// File: /workspace/github_c_makefile_star2_O0/goghcrow[P]dubbo_ab/dubbo_hessian.c
// Function: hs_decode_binary
bool hs_decode_binary(struct buffer *buf, char **out, size_t *out_sz)
{
    uint16_t tag = buf_peekInt8(buf);
    uint16_t sz = 0;
    if (tag >= 0x20 && tag <= 0x2f)
    {
        sz = tag - 0x20;
        buf_retrieveInt8(buf);
        
        small:
        *out_sz = sz;
        *out = malloc(sz + 1);
        if (*out == NULL)
        {
            return false;
        }
        memcpy(*out, buf_peek(buf), sz);
        buf_retrieve(buf, sz);
        return true;
    }
    else if (tag >= 0x34 && tag <= 0x37)
    {
        sz = buf_readInt16(buf);
        sz = sz & 1023; // 10 bit number !!!
        goto small;
    }
    else
    {
        buf_retrieveInt8(buf);

        size_t left = BIN_CHUNK_MAX;
        *out_sz = 0;
        *out = malloc(BIN_CHUNK_MAX + 1);
        if (*out == NULL)
        {
            return false;
        }

        while (tag == 0x41)
        {
            if (!hs_decode_binary_chunk(buf, out, out_sz, &left))
            {
                free(*out);
                *out = NULL;
                return false;
            }
            tag = buf_readInt8(buf);
        }

        assert(tag == 'B');
        if (!hs_decode_binary_chunk(buf, out, out_sz, &left))
        {
            free(*out);
            *out = NULL;
            return false;
        }
    }
    (*out)[*out_sz] = '\0';
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x9320
movsbl %al, %eax
movw %ax, -0x22(%rbp)
movw $0x0, -0x24(%rbp)
movzwl -0x22(%rbp), %eax
cmpl $0x20, %eax
jl 0xb88f
movzwl -0x22(%rbp), %eax
cmpl $0x2f, %eax
jg 0xb88f
movzwl -0x22(%rbp), %eax
subl $0x20, %eax
movw %ax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
callq 0x88c0
movzwl -0x24(%rbp), %eax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movzwl -0x24(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x23f8
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xb851
movb $0x0, -0x1(%rbp)
jmp 0xb9d3
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x83b0
movq -0x38(%rbp), %rdi
movq %rax, %rsi
movzwl -0x24(%rbp), %eax
movl %eax, %edx
callq 0x2240
movq -0x10(%rbp), %rdi
movzwl -0x24(%rbp), %eax
movl %eax, %esi
callq 0x86f0
movb $0x1, -0x1(%rbp)
jmp 0xb9d3
movzwl -0x22(%rbp), %eax
cmpl $0x34, %eax
jl 0xb8c0
movzwl -0x22(%rbp), %eax
cmpl $0x37, %eax
jg 0xb8c0
movq -0x10(%rbp), %rdi
callq 0x9580
movw %ax, -0x24(%rbp)
movzwl -0x24(%rbp), %eax
andl $0x3ff, %eax            # imm = 0x3FF
movw %ax, -0x24(%rbp)
jmp 0xb818
movq -0x10(%rbp), %rdi
callq 0x88c0
movq $0x10000, -0x30(%rbp)   # imm = 0x10000
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x10001, %edi          # imm = 0x10001
callq 0x23f8
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xb903
movb $0x0, -0x1(%rbp)
jmp 0xb9d3
jmp 0xb905
movzwl -0x22(%rbp), %eax
cmpl $0x41, %eax
jne 0xb959
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0xb9e0
testb $0x1, %al
jne 0xb947
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x23f0
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0xb9d3
movq -0x10(%rbp), %rdi
callq 0x95b0
movsbl %al, %eax
movw %ax, -0x22(%rbp)
jmp 0xb905
movzwl -0x22(%rbp), %eax
cmpl $0x42, %eax
jne 0xb964
jmp 0xb983
leaq 0x4466(%rip), %rdi      # 0xfdd1
leaq 0x4436(%rip), %rsi      # 0xfda8
movl $0x245, %edx            # imm = 0x245
leaq 0x445e(%rip), %rcx      # 0xfddc
callq 0x2170
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0xb9e0
testb $0x1, %al
jne 0xb9b9
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x23f0
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0xb9d3
jmp 0xb9bb
jmp 0xb9bd
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nop