// File: /workspace/github_c_makefile_star2_O1/termbox[P]termbox/termbox.c
// Function: tb_init_fd
int tb_init_fd(int inout_) {
    inout = inout_;
    if (inout == -1) {
        return TB_EFAILED_TO_OPEN_TTY;
    }

    if (init_term() < 0) {
        close(inout);
        return TB_EUNSUPPORTED_TERMINAL;
    }

    if (pipe(winch_fds) < 0) {
        close(inout);
        return TB_EPIPE_TRAP_ERROR;
    }

    struct sigaction sa;
    memset(&sa, 0, sizeof(sa));
    sa.sa_handler = sigwinch_handler;
    sa.sa_flags = 0;
    sigaction(SIGWINCH, &sa, 0);

    tcgetattr(inout, &orig_tios);

    struct termios tios;
    memcpy(&tios, &orig_tios, sizeof(tios));

    tios.c_iflag &=
        ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
    tios.c_oflag &= ~OPOST;
    tios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
    tios.c_cflag &= ~(CSIZE | PARENB);
    tios.c_cflag |= CS8;
    tios.c_cc[VMIN] = 0;
    tios.c_cc[VTIME] = 0;
    tcsetattr(inout, TCSAFLUSH, &tios);

    bytebuffer_init(&input_buffer, 128);
    bytebuffer_init(&output_buffer, 32 * 1024);

    bytebuffer_puts(&output_buffer, funcs[T_ENTER_CA]);
    bytebuffer_puts(&output_buffer, funcs[T_ENTER_KEYPAD]);
    bytebuffer_puts(&output_buffer, funcs[T_HIDE_CURSOR]);
    send_clear();

    update_term_size();
    cellbuf_init(&back_buffer, termw, termh);
    cellbuf_init(&front_buffer, termw, termh);
    cellbuf_clear(&back_buffer);
    cellbuf_clear(&front_buffer);

    return 0;
}

// Assembly:
movl %edi, 0x61fe(%rip)      # 0x9890
cmpl $-0x1, %edi
je 0x36e4
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1048, %rsp           # imm = 0x1048
leaq 0x2aae(%rip), %rdi      # 0x615d
callq 0x3030
testq %rax, %rax
je 0x36ea
movq %rax, %rbx
leaq 0x2a9f(%rip), %rdi      # 0x6162
callq 0x3030
movq %rax, %r12
testq %rax, %rax
je 0x386b
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4c13
movq %rax, %r14
jmp 0x36ed
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
retq
xorl %r14d, %r14d
testq %r14, %r14
je 0x3802
movzwl (%r14), %eax
movzwl 0x2(%r14), %edx
movzwl 0x4(%r14), %ecx
addl %ecx, %edx
testb $0x1, %dl
je 0x3712
incl %ecx
movw %cx, 0x4(%r14)
movzwl %ax, %eax
cmpl $0x21e, %eax            # imm = 0x21E
sete %cl
movswl 0x2(%r14), %eax
movswl 0x4(%r14), %edx
addl %eax, %edx
movswl 0x6(%r14), %eax
incb %cl
shll %cl, %eax
leal (%rax,%rdx), %r15d
addl $0xc, %r15d
addl %eax, %edx
movswl 0x8(%r14), %eax
leal (%rdx,%rax,2), %ebx
addl $0xc, %ebx
movl $0xb8, %edi
callq 0x31b0
movq %rax, 0x61d8(%rip)      # 0x9930
xorl %r12d, %r12d
leaq 0x293e(%rip), %r13      # 0x60a0
movswl (%r12,%r13), %eax
leal (%r15,%rax,2), %esi
movq %r14, %rdi
movl %ebx, %edx
callq 0x4be3
movq 0x61b4(%rip), %rcx      # 0x9930
movq %rax, (%rcx,%r12,4)
addq $0x2, %r12
cmpq $0x2c, %r12
jne 0x3762
movq $0x0, 0xb0(%rcx)
movl $0x70, %edi
callq 0x31b0
movq %rax, 0x6152(%rip)      # 0x98f8
xorl %r12d, %r12d
leaq 0x2920(%rip), %r13      # 0x60d0
movswl (%r12,%r13), %eax
leal (%r15,%rax,2), %esi
movq %r14, %rdi
movl %ebx, %edx
callq 0x4be3
movq 0x612e(%rip), %rcx      # 0x98f8
movq %rax, (%rcx,%r12,4)
addq $0x2, %r12
cmpq $0x18, %r12
jne 0x37b0
leaq 0x293c(%rip), %rax      # 0x611b
movq %rax, 0x60(%rcx)
leaq 0x2952(%rip), %rax      # 0x613c
movq %rax, 0x68(%rcx)
movb $0x1, 0x6133(%rip)      # 0x9928
movq %r14, %rdi
callq 0x3040
jmp 0x3a8d
movb $0x0, 0x611f(%rip)      # 0x9928
leaq 0x294d(%rip), %rdi      # 0x615d
callq 0x3030
testq %rax, %rax
je 0x3cdb
movq %rax, %rbx
leaq 0x29b8(%rip), %rdi      # 0x61e0
movq %rax, %rsi
callq 0x3150
testl %eax, %eax
je 0x38be
xorl %ecx, %ecx
leaq 0x54ff(%rip), %r14      # 0x8d40
leaq 0x18(%rcx), %r15
cmpq $0x90, %r15
je 0x3976
movq 0x18(%rcx,%r14), %rdi
movq %rbx, %rsi
callq 0x3150
movq %r15, %rcx
testl %eax, %eax
jne 0x3841
addq %r15, %r14
jmp 0x38c5
leaq 0x28f9(%rip), %rdi      # 0x616b
callq 0x3030
testq %rax, %rax
je 0x38e0
leaq 0x28ed(%rip), %rdx      # 0x6170
leaq 0x40(%rsp), %r14
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x30d0
movb $0x0, 0xfff(%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4c13
movq %rax, %r15
movq %rax, %r14
testq %rax, %rax
jne 0x36ed
jmp 0x38e0
leaq 0x547b(%rip), %r14      # 0x8d40
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
movq %rax, 0x605c(%rip)      # 0x9930
movq %rcx, 0x601d(%rip)      # 0x98f8
jmp 0x3a8d
leaq 0x2896(%rip), %rdi      # 0x617d
callq 0x3030
testq %rax, %rax
je 0x39a4
leaq 0x28ab(%rip), %rdx      # 0x61a7
leaq 0x40(%rsp), %r14
movl $0x1000, %esi           # imm = 0x1000
movq %r14, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x30d0
movb $0x0, 0xfff(%r14)
leaq 0x2869(%rip), %rsi      # 0x618b
movq %r14, %rdi
callq 0x3220
leaq 0x285c(%rip), %r12      # 0x618d
movq %rax, %r13
testq %rax, %rax
je 0x39b0
cmpb $0x0, (%r13)
movq %r13, %rdi
cmoveq %r12, %rdi
movq %rbx, %rsi
callq 0x4c13
movq %rax, %rbp
movq %r13, %rax
movq %rbp, %r14
testq %rbp, %rbp
jne 0x396c
xorl %edi, %edi
leaq 0x2827(%rip), %rsi      # 0x618b
callq 0x3220
movq %r15, %r14
movq %r14, %r15
testq %rbp, %rbp
je 0x3931
jmp 0x39b3
leaq 0x2839(%rip), %rsi      # 0x61b6
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
je 0x39c1
leaq 0x57cf(%rip), %rax      # 0x9160
movq %rax, 0x5f98(%rip)      # 0x9930
leaq 0x5881(%rip), %rax      # 0x9220
jmp 0x3a86
leaq 0x27e2(%rip), %r12      # 0x618d
jmp 0x36d4
movq %r15, %r14
testq %r13, %r13
jne 0x36ed
jmp 0x36d4
leaq 0x27f4(%rip), %rsi      # 0x61bc
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
je 0x39ef
leaq 0x58b4(%rip), %rax      # 0x9290
movq %rax, 0x5f4d(%rip)      # 0x9930
leaq 0x5966(%rip), %rax      # 0x9350
jmp 0x3a86
leaq 0x27cb(%rip), %rsi      # 0x61c1
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
je 0x3a1a
leaq 0x59b6(%rip), %rax      # 0x93c0
movq %rax, 0x5f1f(%rip)      # 0x9930
leaq 0x5a68(%rip), %rax      # 0x9480
jmp 0x3a86
leaq 0x27a6(%rip), %rsi      # 0x61c7
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
je 0x3a45
leaq 0x5abb(%rip), %rax      # 0x94f0
movq %rax, 0x5ef4(%rip)      # 0x9930
leaq 0x5b6d(%rip), %rax      # 0x95b0
jmp 0x3a86
leaq 0x2781(%rip), %rsi      # 0x61cd
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
jne 0x3a71
leaq 0x2774(%rip), %rsi      # 0x61d4
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
je 0x3cc3
leaq 0x5ba8(%rip), %rax      # 0x9620
movq %rax, 0x5eb1(%rip)      # 0x9930
leaq 0x5c5a(%rip), %rax      # 0x96e0
movq %rax, 0x5e6b(%rip)      # 0x98f8
leaq 0x5e00(%rip), %rdi      # 0x9894
callq 0x3130
testl %eax, %eax
js 0x3cb1
leaq 0x40(%rsp), %rbx
movl $0x98, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3100
leaq 0x241(%rip), %rax       # 0x3cfd
movq %rax, (%rbx)
movl $0x0, 0x88(%rbx)
movl $0x1c, %edi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x3080
movl 0x5db2(%rip), %edi      # 0x9890
leaq 0x5db7(%rip), %rsi      # 0x989c
callq 0x31e0
movups 0x5dab(%rip), %xmm0     # 0x989c
movq %rsp, %rdx
movaps %xmm0, (%rdx)
movups 0x5dae(%rip), %xmm0     # 0x98ac
movaps %xmm0, 0x10(%rdx)
movups 0x5dbf(%rip), %xmm0     # 0x98c8
movups %xmm0, 0x2c(%rdx)
movups 0x5da8(%rip), %xmm0     # 0x98bc
andl $0xfffffa14, (%rdx)     # imm = 0xFFFFFA14
movaps %xmm0, 0x20(%rdx)
andb $-0x2, 0x4(%rdx)
andl $0xffff7fb4, 0xc(%rdx)  # imm = 0xFFFF7FB4
movl $0xfffffecf, %eax       # imm = 0xFFFFFECF
andl 0x8(%rdx), %eax
orl $0x30, %eax
movl %eax, 0x8(%rdx)
movw $0x0, 0x16(%rdx)
movl 0x5d4d(%rip), %edi      # 0x9890
movl $0x2, %esi
callq 0x31f0
xorps %xmm0, %xmm0
movups %xmm0, 0x5d81(%rip)     # 0x98d8
movl $0x80, 0x5d83(%rip)     # 0x98e4
movl $0x80, %edi
callq 0x31b0
movq %rax, 0x5d66(%rip)      # 0x98d8
xorps %xmm0, %xmm0
movups %xmm0, 0x5d6c(%rip)     # 0x98e8
movl $0x8000, 0x5d6e(%rip)   # imm = 0x8000
movl $0x8000, %edi           # imm = 0x8000
callq 0x31b0
movq %rax, 0x5d51(%rip)      # 0x98e8
movq 0x5d5a(%rip), %rax      # 0x98f8
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x30c0
movq %rbx, %rdi
movl %eax, %esi
callq 0x4d36
movq 0x5d3e(%rip), %rax      # 0x98f8
movq 0x50(%rax), %rbx
movq %rbx, %rdi
callq 0x30c0
movq %rbx, %rdi
movl %eax, %esi
callq 0x4d36
movq 0x5d21(%rip), %rax      # 0x98f8
movq 0x18(%rax), %rbx
movq %rbx, %rdi
callq 0x30c0
movq %rbx, %rdi
movl %eax, %esi
callq 0x4d36
callq 0x3d1b
callq 0x3da3
movl 0x5543(%rip), %esi      # 0x9140
movl 0x5541(%rip), %edx      # 0x9144
leaq 0x5cf6(%rip), %rdi      # 0x9900
callq 0x3e00
movl 0x552b(%rip), %esi      # 0x9140
movl 0x5529(%rip), %edx      # 0x9144
leaq 0x5cee(%rip), %rdi      # 0x9910
callq 0x3e00
movl 0x5cd7(%rip), %esi      # 0x9904
imull 0x5ccc(%rip), %esi      # 0x9900
testl %esi, %esi
jle 0x3c6a
movq 0x5cc9(%rip), %rax      # 0x9908
movzwl 0x5cde(%rip), %ecx      # 0x9924
movzwl 0x5cd9(%rip), %edx      # 0x9926
movl %esi, %esi
xorl %edi, %edi
movl $0x20, (%rax,%rdi,8)
movw %cx, 0x4(%rax,%rdi,8)
movw %dx, 0x6(%rax,%rdi,8)
incq %rdi
cmpq %rdi, %rsi
jne 0x3c51
movl 0x5ca4(%rip), %esi      # 0x9914
imull 0x5c99(%rip), %esi      # 0x9910
testl %esi, %esi
jle 0x3cad
movq 0x5c96(%rip), %rax      # 0x9918
movzwl 0x5c9b(%rip), %ecx      # 0x9924
movzwl 0x5c96(%rip), %edx      # 0x9926
movl %esi, %esi
xorl %edi, %edi
movl $0x20, (%rax,%rdi,8)
movw %cx, 0x4(%rax,%rdi,8)
movw %dx, 0x6(%rax,%rdi,8)
incq %rdi
cmpq %rdi, %rsi
jne 0x3c94
xorl %eax, %eax
jmp 0x3ceb
movl 0x5bd9(%rip), %edi      # 0x9890
callq 0x3120
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jmp 0x3ceb
leaq 0x250f(%rip), %rsi      # 0x61d9
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
jne 0x398a
movl 0x5baf(%rip), %edi      # 0x9890
callq 0x3120
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x1048, %rsp           # imm = 0x1048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq