// File: DoubleString[P]RtConverter/src/Rtklib/binex.cpp
// Function: bamboo::decode_bnx(bamboo::raw_t*)
static int decode_bnx(raw_t *raw)
{
    unsigned int len,cs1,cs2;
    int rec,len_h;
    
    rec=raw->buff[1]; /* record id */
    
    /* record and header length */
    len_h=getbnxi(raw->buff+2,&len);
    
    trace(5,"decode_bnx: rec=%02x len=%d\n",rec,len);
    
    /* check parity */
    if (raw->len-1<128) {
        cs1=U1(raw->buff+raw->len);
        cs2=csum8(raw->buff+1,raw->len-1);
    }
    else {
        cs1=U2(raw->buff+raw->len);
        cs2=rtk_crc16(raw->buff+1,raw->len-1);
    }
    if (cs1!=cs2) {
        trace(2,"binex 0x%02X parity error CS=%X %X\n",rec,cs1,cs2);
        return -1;
    }
    if (raw->outtype) {
        sprintf(raw->msgtype,"BINEX 0x%02X (%4d)",rec,raw->len);
    }
    /* decode binex message record */
    switch (rec) {
        case 0x00: return decode_bnx_00(raw,raw->buff+2+len_h,len);
        case 0x01: return decode_bnx_01(raw,raw->buff+2+len_h,len);
        case 0x02: return decode_bnx_02(raw,raw->buff+2+len_h,len);
        case 0x03: return decode_bnx_03(raw,raw->buff+2+len_h,len);
        case 0x7d: return decode_bnx_7d(raw,raw->buff+2+len_h,len);
        case 0x7e: return decode_bnx_7e(raw,raw->buff+2+len_h,len);
        case 0x7f: return decode_bnx_7f(raw,raw->buff+2+len_h,len);
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x81a91(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
addq $0x81a90, %rdi          # imm = 0x81A90
addq $0x2, %rdi
leaq -0x14(%rbp), %rsi
callq 0x5ad00
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %edx
movl -0x14(%rbp), %ecx
movl $0x5, %edi
leaq 0x63417(%rip), %rsi     # 0xbe1fe
movb $0x0, %al
callq 0x8b980
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %eax
subl $0x1, %eax
cmpl $0x80, %eax
jge 0x5ae45
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x81a78(%rcx), %rcx
movzbl 0x81a90(%rax,%rcx), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
addq $0x81a90, %rdi          # imm = 0x81A90
addq $0x1, %rdi
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %esi
subl $0x1, %esi
callq 0x5b260
movzbl %al, %eax
movl %eax, -0x1c(%rbp)
jmp 0x5ae90
movq -0x10(%rbp), %rdi
addq $0x81a90, %rdi          # imm = 0x81A90
movq -0x10(%rbp), %rax
movslq 0x81a78(%rax), %rax
addq %rax, %rdi
callq 0x5b2b0
movzwl %ax, %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
addq $0x81a90, %rdi          # imm = 0x81A90
addq $0x1, %rdi
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %esi
subl $0x1, %esi
callq 0x8c350
movzwl %ax, %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
je 0x5aec1
movl -0x20(%rbp), %edx
movl -0x18(%rbp), %ecx
movl -0x1c(%rbp), %r8d
movl $0x2, %edi
leaq 0x6336d(%rip), %rsi     # 0xbe21b
movb $0x0, %al
callq 0x8b980
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5b074
movq -0x10(%rbp), %rax
cmpl $0x0, 0x81a8c(%rax)
je 0x5aef4
movq -0x10(%rbp), %rdi
addq $0x70e70, %rdi          # imm = 0x70E70
movl -0x20(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %ecx
leaq 0x63352(%rip), %rsi     # 0xbe23f
movb $0x0, %al
callq 0x9150
movl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
testl %eax, %eax
je 0x5af53
jmp 0x5af00
movl -0x28(%rbp), %eax
subl $0x1, %eax
je 0x5af7d
jmp 0x5af0a
movl -0x28(%rbp), %eax
subl $0x2, %eax
je 0x5afa7
jmp 0x5af18
movl -0x28(%rbp), %eax
subl $0x3, %eax
je 0x5afd1
jmp 0x5af26
movl -0x28(%rbp), %eax
subl $0x7d, %eax
je 0x5aff8
jmp 0x5af34
movl -0x28(%rbp), %eax
subl $0x7e, %eax
je 0x5b01f
jmp 0x5af42
movl -0x28(%rbp), %eax
subl $0x7f, %eax
je 0x5b046
jmp 0x5b06d
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x81a90, %rsi          # imm = 0x81A90
addq $0x2, %rsi
movslq -0x24(%rbp), %rax
addq %rax, %rsi
movl -0x14(%rbp), %edx
callq 0x5b310
movl %eax, -0x4(%rbp)
jmp 0x5b074
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x81a90, %rsi          # imm = 0x81A90
addq $0x2, %rsi
movslq -0x24(%rbp), %rax
addq %rax, %rsi
movl -0x14(%rbp), %edx
callq 0x5b990
movl %eax, -0x4(%rbp)
jmp 0x5b074
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x81a90, %rsi          # imm = 0x81A90
addq $0x2, %rsi
movslq -0x24(%rbp), %rax
addq %rax, %rsi
movl -0x14(%rbp), %edx
callq 0x5bb70
movl %eax, -0x4(%rbp)
jmp 0x5b074
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x81a90, %rsi          # imm = 0x81A90
addq $0x2, %rsi
movslq -0x24(%rbp), %rax
addq %rax, %rsi
movl -0x14(%rbp), %edx
callq 0x5bba0
movl %eax, -0x4(%rbp)
jmp 0x5b074
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x81a90, %rsi          # imm = 0x81A90
addq $0x2, %rsi
movslq -0x24(%rbp), %rax
addq %rax, %rsi
movl -0x14(%rbp), %edx
callq 0x5bbd0
movl %eax, -0x4(%rbp)
jmp 0x5b074
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x81a90, %rsi          # imm = 0x81A90
addq $0x2, %rsi
movslq -0x24(%rbp), %rax
addq %rax, %rsi
movl -0x14(%rbp), %edx
callq 0x5bc00
movl %eax, -0x4(%rbp)
jmp 0x5b074
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x81a90, %rsi          # imm = 0x81A90
addq $0x2, %rsi
movslq -0x24(%rbp), %rax
addq %rax, %rsi
movl -0x14(%rbp), %edx
callq 0x5bc30
movl %eax, -0x4(%rbp)
jmp 0x5b074
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)