// File: /workspace/github_c_makefile_star2_O3/mruby-zest[P]osc-bridge/test/common.h
// Function: hexdump
void hexdump(const char *data, const char *mask, size_t len)
{
    const char *bold_gray = "\x1b[30;1m";
    const char *reset      = "\x1b[0m";
    int offset = 0;
    while(1)
    {
        //print line
        printf("#%07x: ", offset);

        int char_covered = 0;

        //print hex groups (8)
        for(int i=0; i<8; ++i) {

            //print doublet
            for(int j=0; j<2; ++j) {
                int loffset = offset + 2*i + j;
                if(loffset >= (int)len)
                    goto escape;

                //print hex
                {
                    //start highlight
                    if(mask && mask[loffset]){printf("%s", bold_gray);}

                    //print chars
                    printf("%02x", 0xff&data[loffset]);

                    //end highlight
                    if(mask && mask[loffset]){printf("%s", reset);}
                    char_covered += 2;
                }
            }
            printf(" ");
            char_covered += 1;
        }
escape:

        //print filler if needed
        for(int i=char_covered; i<41; ++i)
            printf(" ");

        //print ascii (16)
        for(int i=0; i<16; ++i) {
            if(isprint(data[offset+i]))
                printf("%c", data[offset+i]);
            else
                printf(".");
        }
        printf("\n");
        offset += 16;
        if(offset >= (int)len)
            return;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdx, -0x40(%rbp)
movslq %edx, %rax
movq %rax, -0x58(%rbp)
movq %rdi, -0x38(%rbp)
movq %rdi, %r12
xorl %r13d, %r13d
movq %r12, -0x48(%rbp)
leaq 0x1f03(%rip), %rdi      # 0x9db2
movl %r13d, %esi
xorl %eax, %eax
callq 0x20f0
xorl %ecx, %ecx
xorl %eax, %eax
movq %r13, -0x30(%rbp)
movq %rcx, -0x50(%rbp)
leaq (%r13,%rcx,2), %r13
movb $0x1, %r12b
xorl %r15d, %r15d
movl %eax, %ebx
orq %r13, %r15
cmpq -0x58(%rbp), %r15
jge 0x7f8b
testq %r14, %r14
je 0x7f35
cmpb $0x0, (%r14,%r15)
je 0x7f00
leaq 0x1267(%rip), %rdi      # 0x9159
leaq 0x1eac(%rip), %rsi      # 0x9da5
xorl %eax, %eax
callq 0x20f0
movq -0x38(%rbp), %rax
movzbl (%rax,%r15), %esi
leaq 0x1eaa(%rip), %rdi      # 0x9dba
xorl %eax, %eax
callq 0x20f0
cmpb $0x0, (%r14,%r15)
je 0x7f4c
leaq 0x1234(%rip), %rdi      # 0x9159
leaq 0x1e81(%rip), %rsi      # 0x9dad
xorl %eax, %eax
callq 0x20f0
jmp 0x7f4c
movq -0x38(%rbp), %rax
movzbl (%rax,%r15), %esi
leaq 0x1e75(%rip), %rdi      # 0x9dba
xorl %eax, %eax
callq 0x20f0
addl $0x2, %ebx
movl $0x1, %r15d
testb $0x1, %r12b
movl $0x0, %r12d
jne 0x7ed2
movl $0x20, %edi
callq 0x2040
leal 0x1(%rbx), %eax
movq -0x50(%rbp), %rcx
incq %rcx
cmpq $0x8, %rcx
movq -0x30(%rbp), %r13
jne 0x7ec1
incl %ebx
jmp 0x7f8f
movq -0x30(%rbp), %r13
cmpl $0x28, %ebx
movq -0x48(%rbp), %r12
jg 0x7fa9
addl $-0x29, %ebx
movl $0x20, %edi
callq 0x2040
incl %ebx
jne 0x7f9b
callq 0x22f0
movq %rax, %rbx
xorl %r15d, %r15d
movq (%rbx), %rcx
movsbl (%r12,%r15), %eax
movslq %eax, %rdx
movzwl (%rcx,%rdx,2), %ecx
btl $0xe, %ecx
movl $0x2e, %edi
jae 0x7fd0
movl %eax, %edi
callq 0x2040
incq %r15
cmpq $0x10, %r15
jne 0x7fb4
movl $0xa, %edi
callq 0x2040
addq $0x10, %r13
addq $0x10, %r12
cmpl -0x40(%rbp), %r13d
jl 0x7ea4
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq