// File: /workspace/github_c_makefile_star2_O0/termbox[P]termbox/termbox.c
// Function: init_term
static int init_term(void) {
    int i;
    char *data = load_terminfo();
    if (!data) {
        init_from_terminfo = false;
        return init_term_builtin();
    }

    int16_t *header = (int16_t *)data;

    const int number_sec_len = header[0] == TI_ALT_MAGIC ? 4 : 2;

    if ((header[1] + header[2]) % 2) {
        // old quirk to align everything on word boundaries
        header[2] += 1;
    }

    const int str_offset =
        TI_HEADER_LENGTH + header[1] + header[2] + number_sec_len * header[3];
    const int table_offset = str_offset + 2 * header[4];

    keys = malloc(sizeof(const char *) * (TB_KEYS_NUM + 1));
    for (i = 0; i < TB_KEYS_NUM; i++) {
        keys[i] = terminfo_copy_string(data, str_offset + 2 * ti_keys[i],
                                       table_offset);
    }
    keys[TB_KEYS_NUM] = 0;

    funcs = malloc(sizeof(const char *) * T_FUNCS_NUM);
    // the last two entries are reserved for mouse. because the table offset is
    // not there, the two entries have to fill in manually
    for (i = 0; i < T_FUNCS_NUM - 2; i++) {
        funcs[i] = terminfo_copy_string(data, str_offset + 2 * ti_funcs[i],
                                        table_offset);
    }

    funcs[T_FUNCS_NUM - 2] = ENTER_MOUSE_SEQ;
    funcs[T_FUNCS_NUM - 1] = EXIT_MOUSE_SEQ;

    init_from_terminfo = true;
    free(data);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
callq 0x4f20
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x39cc
movb $0x0, 0x7019(%rip)      # 0xa9d8
callq 0x5120
movl %eax, -0x4(%rbp)
jmp 0x3b60
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movswl (%rax), %edx
movl $0x2, %eax
movl $0x4, %ecx
cmpl $0x21e, %edx            # imm = 0x21E
cmovel %ecx, %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movswl 0x2(%rax), %eax
movq -0x18(%rbp), %rcx
movswl 0x4(%rcx), %ecx
addl %ecx, %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x3a1f
movq -0x18(%rbp), %rax
movswl 0x4(%rax), %ecx
addl $0x1, %ecx
movw %cx, 0x4(%rax)
movq -0x18(%rbp), %rax
movswl 0x2(%rax), %eax
addl $0xc, %eax
movq -0x18(%rbp), %rcx
movswl 0x4(%rcx), %ecx
addl %ecx, %eax
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rdx
movswl 0x6(%rdx), %edx
imull %edx, %ecx
addl %ecx, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x18(%rbp), %rcx
movswl 0x8(%rcx), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movl $0xb8, %edi
callq 0x31b0
movq %rax, 0x6f76(%rip)      # 0xa9e0
movl $0x0, -0x8(%rbp)
cmpl $0x16, -0x8(%rbp)
jge 0x3ab6
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
movslq -0x8(%rbp), %rcx
leaq 0x3617(%rip), %rax      # 0x70a0
movswl (%rax,%rcx,2), %eax
shll %eax
addl %eax, %esi
movl -0x24(%rbp), %edx
callq 0x5330
movq %rax, %rdx
movq 0x6f3d(%rip), %rax      # 0xa9e0
movslq -0x8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x3a71
movq 0x6f23(%rip), %rax      # 0xa9e0
movq $0x0, 0xb0(%rax)
movl $0x70, %edi
callq 0x31b0
movq %rax, 0x6ecf(%rip)      # 0xa9a8
movl $0x0, -0x8(%rbp)
cmpl $0xc, -0x8(%rbp)
jge 0x3b25
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
movslq -0x8(%rbp), %rcx
leaq 0x35d8(%rip), %rax      # 0x70d0
movswl (%rax,%rcx,2), %eax
shll %eax
addl %eax, %esi
movl -0x24(%rbp), %edx
callq 0x5330
movq %rax, %rdx
movq 0x6e96(%rip), %rax      # 0xa9a8
movslq -0x8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x3ae0
movq 0x6e7c(%rip), %rax      # 0xa9a8
leaq 0x35e8(%rip), %rcx      # 0x711b
movq %rcx, 0x60(%rax)
movq 0x6e6a(%rip), %rax      # 0xa9a8
leaq 0x35f7(%rip), %rcx      # 0x713c
movq %rcx, 0x68(%rax)
movb $0x1, 0x6e88(%rip)      # 0xa9d8
movq -0x10(%rbp), %rdi
callq 0x3040
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)