// File: /workspace/github_c_makefile_star2_O3/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 0x36d7
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1040, %rsp           # imm = 0x1040
leaq 0x2ab0(%rip), %rdi      # 0x615d
callq 0x3030
testq %rax, %rax
je 0x38c9
movq %rax, %r14
leaq 0x2a9d(%rip), %rdi      # 0x6162
callq 0x3030
testq %rax, %rax
je 0x36dd
movq %rax, %rdi
jmp 0x37b0
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
retq
leaq 0x2a87(%rip), %rdi      # 0x616b
callq 0x3030
testq %rax, %rax
je 0x372b
leaq 0x2a7b(%rip), %rdx      # 0x6170
leaq 0x40(%rsp), %rbx
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x30d0
movb $0x0, 0xfff(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4bc8
testq %rax, %rax
je 0x372b
movq %rax, %rbx
jmp 0x37c4
leaq 0x2a4b(%rip), %rdi      # 0x617d
callq 0x3030
testq %rax, %rax
je 0x37a9
leaq 0x2a64(%rip), %rdx      # 0x61a7
leaq 0x40(%rsp), %rbx
movl $0x1000, %esi           # imm = 0x1000
movq %rbx, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x30d0
movb $0x0, 0xfff(%rbx)
leaq 0x2a23(%rip), %rsi      # 0x618b
movq %rbx, %rdi
callq 0x3220
testq %rax, %rax
je 0x37a9
leaq 0x2a11(%rip), %r12      # 0x618d
leaq 0x2a08(%rip), %r15      # 0x618b
cmpb $0x0, (%rax)
cmoveq %r12, %rax
movq %rax, %rdi
movq %r14, %rsi
callq 0x4bc8
testq %rax, %rax
jne 0x3723
xorl %edi, %edi
movq %r15, %rsi
callq 0x3220
testq %rax, %rax
jne 0x3783
leaq 0x29dd(%rip), %rdi      # 0x618d
movq %r14, %rsi
callq 0x4bc8
movq %rax, %rbx
testq %rax, %rax
je 0x38c9
movzwl (%rbx), %ecx
movswl 0x2(%rbx), %eax
movzwl 0x4(%rbx), %edx
movl %edx, %esi
addl %eax, %esi
testb $0x1, %sil
je 0x37df
incl %edx
movw %dx, 0x4(%rbx)
movzwl %cx, %ecx
cmpl $0x21e, %ecx            # imm = 0x21E
sete %cl
movswl %dx, %edx
addl %edx, %eax
movswl 0x6(%rbx), %edx
incb %cl
shll %cl, %edx
movl %eax, %ecx
addl %edx, %ecx
leal (%rdx,%rax), %r14d
addl $0xc, %r14d
movswl 0x8(%rbx), %eax
leal (%rcx,%rax,2), %ebp
addl $0xc, %ebp
movl $0xb8, %edi
callq 0x31b0
movq %rax, 0x6111(%rip)      # 0x9930
xorl %r15d, %r15d
leaq 0x2877(%rip), %r12      # 0x60a0
movswl (%r15,%r12), %eax
leal (%r14,%rax,2), %esi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x4b98
movq 0x60ed(%rip), %rcx      # 0x9930
movq %rax, (%rcx,%r15,4)
addq $0x2, %r15
cmpq $0x2c, %r15
jne 0x3829
movq $0x0, 0xb0(%rcx)
movl $0x70, %edi
callq 0x31b0
movq %rax, 0x608b(%rip)      # 0x98f8
xorl %r15d, %r15d
leaq 0x2859(%rip), %r12      # 0x60d0
movswl (%r15,%r12), %eax
leal (%r14,%rax,2), %esi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x4b98
movq 0x6067(%rip), %rcx      # 0x98f8
movq %rax, (%rcx,%r15,4)
addq $0x2, %r15
cmpq $0x18, %r15
jne 0x3877
leaq 0x2875(%rip), %rax      # 0x611b
movq %rax, 0x60(%rcx)
leaq 0x288b(%rip), %rax      # 0x613c
movq %rax, 0x68(%rcx)
movb $0x1, 0x606c(%rip)      # 0x9928
movq %rbx, %rdi
callq 0x3040
jmp 0x3a3f
movb $0x0, 0x6058(%rip)      # 0x9928
leaq 0x2886(%rip), %rdi      # 0x615d
callq 0x3030
testq %rax, %rax
je 0x3c83
movq %rax, %rbx
leaq 0x28f1(%rip), %rdi      # 0x61e0
movq %rax, %rsi
callq 0x3150
testl %eax, %eax
je 0x392a
xorl %ecx, %ecx
leaq 0x543c(%rip), %r14      # 0x8d40
leaq 0x18(%rcx), %r15
cmpq $0x90, %r15
je 0x3945
movq 0x18(%rcx,%r14), %rdi
movq %rbx, %rsi
callq 0x3150
movq %r15, %rcx
testl %eax, %eax
jne 0x3904
addq %r15, %r14
jmp 0x3931
leaq 0x540f(%rip), %r14      # 0x8d40
movq 0x8(%r14), %rcx
movq 0x10(%r14), %rax
movq %rcx, 0x5ff0(%rip)      # 0x9930
jmp 0x3a38
leaq 0x286a(%rip), %rsi      # 0x61b6
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
je 0x3973
leaq 0x5800(%rip), %rax      # 0x9160
movq %rax, 0x5fc9(%rip)      # 0x9930
leaq 0x58b2(%rip), %rax      # 0x9220
jmp 0x3a38
leaq 0x2842(%rip), %rsi      # 0x61bc
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
je 0x39a1
leaq 0x5902(%rip), %rax      # 0x9290
movq %rax, 0x5f9b(%rip)      # 0x9930
leaq 0x59b4(%rip), %rax      # 0x9350
jmp 0x3a38
leaq 0x2819(%rip), %rsi      # 0x61c1
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
je 0x39cc
leaq 0x5a04(%rip), %rax      # 0x93c0
movq %rax, 0x5f6d(%rip)      # 0x9930
leaq 0x5ab6(%rip), %rax      # 0x9480
jmp 0x3a38
leaq 0x27f4(%rip), %rsi      # 0x61c7
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
je 0x39f7
leaq 0x5b09(%rip), %rax      # 0x94f0
movq %rax, 0x5f42(%rip)      # 0x9930
leaq 0x5bbb(%rip), %rax      # 0x95b0
jmp 0x3a38
leaq 0x27cf(%rip), %rsi      # 0x61cd
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
jne 0x3a23
leaq 0x27c2(%rip), %rsi      # 0x61d4
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
je 0x3c6b
leaq 0x5bf6(%rip), %rax      # 0x9620
movq %rax, 0x5eff(%rip)      # 0x9930
leaq 0x5ca8(%rip), %rax      # 0x96e0
movq %rax, 0x5eb9(%rip)      # 0x98f8
leaq 0x5e4e(%rip), %rdi      # 0x9894
callq 0x3130
testl %eax, %eax
js 0x3c59
leaq 0x48(%rsp), %rbx
movl $0x90, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3100
leaq 0x235(%rip), %rax       # 0x3ca3
movq %rax, -0x8(%rbx)
leaq 0x40(%rsp), %rsi
movl $0x1c, %edi
xorl %edx, %edx
callq 0x3080
movl 0x5e07(%rip), %edi      # 0x9890
leaq 0x5e0c(%rip), %rsi      # 0x989c
callq 0x31e0
movups 0x5e00(%rip), %xmm0     # 0x989c
movq %rsp, %rdx
movaps %xmm0, (%rdx)
movups 0x5e03(%rip), %xmm0     # 0x98ac
movaps %xmm0, 0x10(%rdx)
movups 0x5e14(%rip), %xmm0     # 0x98c8
movups %xmm0, 0x2c(%rdx)
movups 0x5dfd(%rip), %xmm0     # 0x98bc
movabsq $-0x1000005ec, %rax     # imm = 0xFFFFFFFEFFFFFA14
andq %rax, (%rdx)
movaps %xmm0, 0x20(%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 0x5d9f(%rip), %edi      # 0x9890
movl $0x2, %esi
callq 0x31f0
movabsq $0x8000000000, %rax     # imm = 0x8000000000
movq %rax, 0x5dd4(%rip)      # 0x98e0
movl $0x80, %edi
callq 0x31b0
movq %rax, 0x5dbb(%rip)      # 0x98d8
movabsq $0x800000000000, %rax   # imm = 0x800000000000
movq %rax, 0x5dc2(%rip)      # 0x98f0
movl $0x8000, %edi           # imm = 0x8000
callq 0x31b0
movq %rax, 0x5da9(%rip)      # 0x98e8
movq 0x5db2(%rip), %rax      # 0x98f8
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x30c0
movq %rbx, %rdi
movl %eax, %esi
callq 0x4ceb
movq 0x5d96(%rip), %rax      # 0x98f8
movq 0x50(%rax), %rbx
movq %rbx, %rdi
callq 0x30c0
movq %rbx, %rdi
movl %eax, %esi
callq 0x4ceb
movq 0x5d79(%rip), %rax      # 0x98f8
movq 0x18(%rax), %rbx
movq %rbx, %rdi
callq 0x30c0
movq %rbx, %rdi
movl %eax, %esi
callq 0x4ceb
callq 0x3cc1
callq 0x3d49
movl 0x559b(%rip), %esi      # 0x9140
movl 0x5599(%rip), %edx      # 0x9144
leaq 0x5d4e(%rip), %rdi      # 0x9900
callq 0x3da6
movl 0x5583(%rip), %esi      # 0x9140
movl 0x5581(%rip), %edx      # 0x9144
leaq 0x5d46(%rip), %rdi      # 0x9910
callq 0x3da6
movl 0x5d2f(%rip), %esi      # 0x9904
imull 0x5d24(%rip), %esi      # 0x9900
testl %esi, %esi
jle 0x3c12
movq 0x5d21(%rip), %rax      # 0x9908
movzwl 0x5d36(%rip), %ecx      # 0x9924
movzwl 0x5d31(%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 0x3bf9
movl 0x5cfc(%rip), %esi      # 0x9914
imull 0x5cf1(%rip), %esi      # 0x9910
testl %esi, %esi
jle 0x3c55
movq 0x5cee(%rip), %rax      # 0x9918
movzwl 0x5cf3(%rip), %ecx      # 0x9924
movzwl 0x5cee(%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 0x3c3c
xorl %eax, %eax
jmp 0x3c93
movl 0x5c31(%rip), %edi      # 0x9890
callq 0x3120
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jmp 0x3c93
leaq 0x2567(%rip), %rsi      # 0x61d9
movq %rbx, %rdi
callq 0x3250
testq %rax, %rax
jne 0x3959
movl 0x5c07(%rip), %edi      # 0x9890
callq 0x3120
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x1040, %rsp           # imm = 0x1040
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq