    .intel_syntax noprefix
    .global main
    main:
        sub esp, 12
        mov [esp + 8], ebx
        xor ebx, ebx
    
    test_loop:
        mov eax, [in + 4 * ebx]
        mov dword ptr [esp], eax
        call bitstuffing
        mov [esp + 8], eax
        cmp eax, [verify + 4 * ebx]
        mov dword ptr [esp], offset ok
        je got_fmt
        mov dword ptr [esp], offset error
    got_fmt:
        mov eax, [in + 4 * ebx]
        mov [esp + 4], eax
        call printf
        inc ebx
        cmp ebx, 7
        jb test_loop
    
        mov ebx, [esp + 8]
        add esp, 12
        xor eax, eax
        ret
    
    bitstuffing:
        push ebp
        mov ebp, esp
        push ebx
    
        mov cl, 32         # 32 bits to go
        xor eax, eax       # the output
        mov edx, [ebp + 8] # the input
        xor bl, bl         # the run count
    next_bit:
        dec cl             # more bits?
        js done            # no
        shl edx, 1         # consume from the input into CF
        rcl eax, 1         # copy to output from CF
        test bl, bl        # first bit always matches
        jz match
        test al, 3         # do we have 00 or 11 in the low 2 bits?
        jnp reset          # no, start counting again
    match:
        inc bl
        cmp bl, 5          # did 5 bits match?
        jb next_bit        # no, keep going
        dec cl             # space for stuffed bit?
        js done            # no
        mov ebx, eax       # make a copy
        and ebx, 1         # isolate LSB
        xor ebx, 1         # flip it
        shl eax, 1         # make space for it
        or eax, ebx        # stuff it
    reset:
        mov bl, 1          # already have length 1
        jmp next_bit
    
    done:
        pop ebx
        mov esp, ebp
        pop ebp
        ret
    
    .data
    ok: .string "OK: 0x%08x => 0x%08x\n"
    error: .string "ERROR: 0x%08x => 0x%08x\n"
    in: .int 0xFFFFFFFF, 0x00000000, 0x0F0F0F0F, 0x0F0F0F00, 0x0F0F0000, 0xAAAA0000, 0x07878000
    verify: .int 0xFBEFBEFB, 0x04104104, 0x0F0F0F0F, 0x0F0F0F04, 0x0F0F0410, 0xAAAA0820, 0x07C1F041