// File: /workspace/github_c_makefile_star2_O0/jtuu[P]quesler/src/qst.c
// Function: read_bin
int read_bin(FILE* fd, QstBin* bin) {
    size_t read_size = 0;

#define CHECKED_READ(dst, size, num) \
    do { \
        size_t ret = fread(dst, size, num, fd); \
        int err = ferror(fd); \
        if (err) { \
            return err; \
        } \
        read_size += ret * (size); \
    } while (false)

    CHECKED_READ(&bin->object_code_offset, 4, 1);
    CHECKED_READ(&bin->function_offset_table_offset, 4, 1);
    CHECKED_READ(&bin->bin_size, 4, 1);
    CHECKED_READ(&bin->xffffffff, 4, 1);
    CHECKED_READ(&bin->quest_number, 4, 1);
    CHECKED_READ(&bin->language, 4, 1);
    CHECKED_READ(&bin->quest_name, 64, 1);
    CHECKED_READ(&bin->short_description, 256, 1);
    CHECKED_READ(&bin->long_description, 576, 1);
    CHECKED_READ(&bin->padding, 4, 1);
    CHECKED_READ(&bin->items_list, 3728, 1);

    bin->object_code_len = bin->function_offset_table_offset - bin->object_code_offset;
    bin->object_code = malloc(bin->object_code_len);
    CHECKED_READ(bin->object_code, bin->object_code_len, 1);

    size_t labels_size = bin->bin_size - bin->function_offset_table_offset;
    bin->function_offset_table_len = labels_size / 4;
    bin->function_offset_table = malloc(labels_size);
    CHECKED_READ(bin->function_offset_table, labels_size, 1);

    return (int) read_size;

#undef CHECKED_READ
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4070
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x82d3
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
movq -0x28(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x82e5
movq -0x18(%rbp), %rdi
addq $0x4, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4070
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x8321
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
movq -0x38(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x8333
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4070
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x836f
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
movq -0x48(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x8381
movq -0x18(%rbp), %rdi
addq $0xc, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4070
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x83bd
movl -0x5c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
movq -0x58(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x83cf
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4070
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
je 0x840b
movl -0x6c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
movq -0x68(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x841d
movq -0x18(%rbp), %rdi
addq $0x14, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4070
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0x7c(%rbp)
je 0x8459
movl -0x7c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
movq -0x78(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x846b
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rcx
movl $0x40, %esi
movl $0x1, %edx
callq 0x4070
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x8c(%rbp)
cmpl $0x0, -0x8c(%rbp)
je 0x84b3
movl -0x8c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
movq -0x88(%rbp), %rax
shlq $0x6, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x84c8
movq -0x18(%rbp), %rdi
addq $0x58, %rdi
movq -0x10(%rbp), %rcx
movl $0x100, %esi            # imm = 0x100
movl $0x1, %edx
callq 0x4070
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x9c(%rbp)
je 0x8510
movl -0x9c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
movq -0x98(%rbp), %rax
shlq $0x8, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x8525
movq -0x18(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
movq -0x10(%rbp), %rcx
movl $0x240, %esi            # imm = 0x240
movl $0x1, %edx
callq 0x4070
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0xac(%rbp)
cmpl $0x0, -0xac(%rbp)
je 0x8570
movl -0xac(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
imulq $0x240, -0xa8(%rbp), %rax # imm = 0x240
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x8585
movq -0x18(%rbp), %rdi
addq $0x398, %rdi            # imm = 0x398
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4070
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0xbc(%rbp)
cmpl $0x0, -0xbc(%rbp)
je 0x85d0
movl -0xbc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
movq -0xb8(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x85e5
movq -0x18(%rbp), %rdi
addq $0x39c, %rdi            # imm = 0x39C
movq -0x10(%rbp), %rcx
movl $0xe90, %esi            # imm = 0xE90
movl $0x1, %edx
callq 0x4070
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
je 0x8630
movl -0xcc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
imulq $0xe90, -0xc8(%rbp), %rax # imm = 0xE90
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
subl (%rcx), %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, 0x1230(%rax)
movq -0x18(%rbp), %rax
movq 0x1230(%rax), %rdi
callq 0x4120
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x1238(%rax)
movq -0x18(%rbp), %rax
movq 0x1238(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x1230(%rax), %rsi
movq -0x10(%rbp), %rcx
movl $0x1, %edx
callq 0x4070
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0xdc(%rbp)
cmpl $0x0, -0xdc(%rbp)
je 0x86ce
movl -0xdc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
movq -0xd8(%rbp), %rax
movq -0x18(%rbp), %rcx
imulq 0x1230(%rcx), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, %eax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rcx
shrq $0x2, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x1240(%rax)
movq -0xe8(%rbp), %rdi
callq 0x4120
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x1248(%rax)
movq -0x18(%rbp), %rax
movq 0x1248(%rax), %rdi
movq -0xe8(%rbp), %rsi
movq -0x10(%rbp), %rcx
movl $0x1, %edx
callq 0x4070
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0xf4(%rbp)
cmpl $0x0, -0xf4(%rbp)
je 0x877a
movl -0xf4(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x8798
movq -0xf0(%rbp), %rax
imulq -0xe8(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw %cs:(%rax,%rax)