// File: /workspace/github_c_makefile_star2_O0/adsr[P]phpspy/vendor/termbox2/termbox2.h
// Function: parse_terminfo_caps
static int parse_terminfo_caps(void) {
    // See term(5) "LEGACY STORAGE FORMAT" and "EXTENDED STORAGE FORMAT" for a
    // description of this behavior.

    // Ensure there's at least a header's worth of data
    if (global.nterminfo < 6) {
        return TB_ERR;
    }

    int16_t *header = (int16_t *)global.terminfo;
    // header[0] the magic number (octal 0432 or 01036)
    // header[1] the size, in bytes, of the names section
    // header[2] the number of bytes in the boolean section
    // header[3] the number of short integers in the numbers section
    // header[4] the number of offsets (short integers) in the strings section
    // header[5] the size, in bytes, of the string table

    // Legacy ints are 16-bit, extended ints are 32-bit
    const int bytes_per_int = header[0] == 01036 ? 4  // 32-bit
                                                 : 2; // 16-bit

    // > Between the boolean section and the number section, a null byte will be
    // > inserted, if necessary, to ensure that the number section begins on an
    // > even byte
    const int align_offset = (header[1] + header[2]) % 2 != 0 ? 1 : 0;

    const int pos_str_offsets =
        (6 * sizeof(int16_t)) // header (12 bytes)
        + header[1]           // length of names section
        + header[2]           // length of boolean section
        + align_offset +
        (header[3] * bytes_per_int); // length of numbers section

    const int pos_str_table =
        pos_str_offsets +
        (header[4] * sizeof(int16_t)); // length of string offsets table

    // Load caps
    int i;
    for (i = 0; i < TB_CAP__COUNT; i++) {
        const char *cap = get_terminfo_string(pos_str_offsets, pos_str_table,
            header[5], terminfo_cap_indexes[i]);
        if (!cap) {
            // Something is not right
            return TB_ERR;
        }
        global.caps[i] = cap;
    }

    return TB_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
cmpq $0x6, 0x2f760(%rip)     # 0x3bee0
jae 0xc78e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xc8a3
movq 0x2f743(%rip), %rax     # 0x3bed8
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movswl (%rax), %edx
movl $0x2, %eax
movl $0x4, %ecx
cmpl $0x21e, %edx            # imm = 0x21E
cmovel %ecx, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movswl 0x2(%rax), %eax
movq -0x10(%rbp), %rcx
movswl 0x4(%rcx), %ecx
addl %ecx, %eax
movl $0x2, %ecx
cltd
idivl %ecx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movswq 0x2(%rax), %rax
addq $0xc, %rax
movq -0x10(%rbp), %rcx
movswq 0x4(%rcx), %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movswl 0x6(%rcx), %ecx
imull -0x14(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movl %eax, -0x1c(%rbp)
movslq -0x1c(%rbp), %rax
movq -0x10(%rbp), %rcx
movswq 0x8(%rcx), %rcx
shlq %rcx
addq %rcx, %rax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x24, -0x24(%rbp)
jge 0xc89c
movl -0x1c(%rbp), %eax
movw %ax, %di
movl -0x20(%rbp), %eax
movw %ax, %si
movq -0x10(%rbp), %rax
movw 0xa(%rax), %dx
movslq -0x24(%rbp), %rcx
leaq 0x26119(%rip), %rax     # 0x32970
movswl %di, %edi
movswl %si, %esi
movswl %dx, %edx
movswl (%rax,%rcx,2), %ecx
callq 0xcc30
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xc87d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xc8a3
movq -0x30(%rbp), %rdx
movslq -0x24(%rbp), %rcx
leaq 0x2f60c(%rip), %rax     # 0x3be98
movq %rdx, 0x50(%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xc832
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)