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

#define CHECKED_WRITE(value, size, num) \
    do { \
        size_t ret = fwrite(value, size, num, fd); \
        int err = ferror(fd); \
        if (err) { \
            return err; \
        } \
        write_size += ret * (size); \
    } while (false)
#define WRITE4(value) CHECKED_WRITE(&(value), 4, 1)

    bin->object_code_offset = BIN_MINIMUM_SIZE;
    bin->function_offset_table_offset = (uint32_t) (bin->object_code_offset +
                                                    bin->object_code_len);
    bin->xffffffff = 0xffffffff;
    bin->padding = 0;

    WRITE4(bin->object_code_offset);
    WRITE4(bin->function_offset_table_offset);
    WRITE4(bin->bin_size);
    WRITE4(bin->xffffffff);
    WRITE4(bin->quest_number);
    WRITE4(bin->language);
    
    CHECKED_WRITE(bin->quest_name, 2, 32);
    CHECKED_WRITE(bin->short_description, 2, 128);
    CHECKED_WRITE(bin->long_description, 2, 288);
    
    WRITE4(bin->padding);

    CHECKED_WRITE(bin->items_list, 4, 932);
    CHECKED_WRITE(bin->object_code, 1, bin->object_code_len);
    CHECKED_WRITE(bin->function_offset_table, 4, bin->function_offset_table_len);

    return (int) write_size;

#undef CHECKED_WRITE
#undef WRITE4
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl $0x122c, (%rax)         # imm = 0x122C
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
addq 0x1230(%rcx), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rbp), %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movl $0x0, 0x398(%rax)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4170
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x7e30
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0x28(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x7e42
movq -0x18(%rbp), %rdi
addq $0x4, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4170
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x7e7e
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0x38(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x7e90
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4170
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x7ecc
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0x48(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x7ede
movq -0x18(%rbp), %rdi
addq $0xc, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4170
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x7f1a
movl -0x5c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0x58(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x7f2c
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4170
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
je 0x7f68
movl -0x6c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0x68(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x7f7a
movq -0x18(%rbp), %rdi
addq $0x14, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4170
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0x7c(%rbp)
je 0x7fb6
movl -0x7c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0x78(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x7fc8
movq -0x18(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rcx
movl $0x2, %esi
movl $0x20, %edx
callq 0x4170
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x8c(%rbp)
cmpl $0x0, -0x8c(%rbp)
je 0x8010
movl -0x8c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0x88(%rbp), %rax
shlq %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x8024
movq -0x18(%rbp), %rdi
addq $0x58, %rdi
movq -0x10(%rbp), %rcx
movl $0x2, %esi
movl $0x80, %edx
callq 0x4170
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x9c(%rbp)
je 0x806c
movl -0x9c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0x98(%rbp), %rax
shlq %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x8080
movq -0x18(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
movq -0x10(%rbp), %rcx
movl $0x2, %esi
movl $0x120, %edx            # imm = 0x120
callq 0x4170
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0xac(%rbp)
cmpl $0x0, -0xac(%rbp)
je 0x80cb
movl -0xac(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0xa8(%rbp), %rax
shlq %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x80df
movq -0x18(%rbp), %rdi
addq $0x398, %rdi            # imm = 0x398
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x4170
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0xbc(%rbp)
cmpl $0x0, -0xbc(%rbp)
je 0x812a
movl -0xbc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0xb8(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x813f
movq -0x18(%rbp), %rdi
addq $0x39c, %rdi            # imm = 0x39C
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x3a4, %edx            # imm = 0x3A4
callq 0x4170
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
je 0x818a
movl -0xcc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0xc8(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x819f
movq -0x18(%rbp), %rax
movq 0x1238(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x1230(%rax), %rdx
movq -0x10(%rbp), %rcx
movl $0x1, %esi
callq 0x4170
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0xdc(%rbp)
cmpl $0x0, -0xdc(%rbp)
je 0x81ed
movl -0xdc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0xd8(%rbp), %rax
shlq $0x0, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x8202
movq -0x18(%rbp), %rax
movq 0x1248(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x1240(%rax), %rdx
movq -0x10(%rbp), %rcx
movl $0x4, %esi
callq 0x4170
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4060
movl %eax, -0xec(%rbp)
cmpl $0x0, -0xec(%rbp)
je 0x8250
movl -0xec(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x826a
movq -0xe8(%rbp), %rax
shlq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)