// File: DoubleString[P]RtConverter/src/Rtklib/binex.cpp
// Function: bamboo::input_bnxf(bamboo::raw_t*, _IO_FILE*)
extern int input_bnxf(raw_t *raw, FILE *fp)
{
    unsigned int len;
    int i,data,len_h,len_c;
    
    trace(4,"input_bnxf\n");
    
    if (raw->nbyte==0) {
        for (i=0;;i++) {
            if ((data=fgetc(fp))==EOF) return -2;
            if (sync_bnx(raw->buff,(unsigned char)data)) break;
            if (i>=4096) return 0;
        }
    }
    if (fread(raw->buff+2,1,4,fp)<4) return -2;
    
    len_h=getbnxi(raw->buff+2,&len);
    
    raw->len=len+len_h+2;
    
    if (raw->len-1>4096) {
        trace(2,"binex length error: len=%d\n",raw->len-1);
        raw->nbyte=0;
        return -1;
    }
    len_c=raw->len-1<128?1:2;
    
    if (fread(raw->buff+6,1,raw->len+len_c-6,fp)<(size_t)(raw->len+len_c-6)) {
        return -2;
    }
    raw->nbyte=0;
    
    /* decode binex message */
    return decode_bnx(raw);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x4, %edi
leaq 0x63156(%rip), %rsi     # 0xbe1f2
movb $0x0, %al
callq 0x8b980
movq -0x10(%rbp), %rax
cmpl $0x0, 0x81a74(%rax)
jne 0x5b115
movl $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9b80
movl %eax, -0x24(%rbp)
cmpl $-0x1, %eax
jne 0x5b0d4
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x5b253
movq -0x10(%rbp), %rdi
addq $0x81a90, %rdi          # imm = 0x81A90
movl -0x24(%rbp), %eax
movzbl %al, %esi
callq 0x5ac30
cmpl $0x0, %eax
je 0x5b0f1
jmp 0x5b113
cmpl $0x1000, -0x20(%rbp)    # imm = 0x1000
jl 0x5b106
movl $0x0, -0x4(%rbp)
jmp 0x5b253
jmp 0x5b108
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x5b0b7
jmp 0x5b115
movq -0x10(%rbp), %rdi
addq $0x81a90, %rdi          # imm = 0x81A90
addq $0x2, %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %esi
movl $0x4, %edx
callq 0x9af0
cmpq $0x4, %rax
jae 0x5b149
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x5b253
movq -0x10(%rbp), %rdi
addq $0x81a90, %rdi          # imm = 0x81A90
addq $0x2, %rdi
leaq -0x1c(%rbp), %rsi
callq 0x5ad00
movl %eax, -0x28(%rbp)
movl -0x1c(%rbp), %ecx
addl -0x28(%rbp), %ecx
addl $0x2, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x81a78(%rax)
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %eax
subl $0x1, %eax
cmpl $0x1000, %eax           # imm = 0x1000
jle 0x5b1c5
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %edx
subl $0x1, %edx
movl $0x2, %edi
leaq 0x63032(%rip), %rsi     # 0xbe1d6
movb $0x0, %al
callq 0x8b980
movq -0x10(%rbp), %rax
movl $0x0, 0x81a74(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x5b253
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %edx
subl $0x1, %edx
movl $0x2, %eax
movl $0x1, %ecx
cmpl $0x80, %edx
cmovll %ecx, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x81a90, %rdi          # imm = 0x81A90
addq $0x6, %rdi
movq -0x10(%rbp), %rax
movl 0x81a78(%rax), %eax
addl -0x2c(%rbp), %eax
subl $0x6, %eax
movslq %eax, %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x9af0
movq -0x10(%rbp), %rcx
movl 0x81a78(%rcx), %ecx
addl -0x2c(%rbp), %ecx
subl $0x6, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jae 0x5b239
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x5b253
movq -0x10(%rbp), %rax
movl $0x0, 0x81a74(%rax)
movq -0x10(%rbp), %rdi
callq 0x5ada0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)