// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl %edi, -0x8(%rbp)
movl -0x8(%rbp), %eax
movl %eax, 0x71a9(%rip)      # 0xa940
cmpl $-0x1, 0x71a2(%rip)     # 0xa940
jne 0x37ac
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3991
callq 0x39a0
cmpl $0x0, %eax
jge 0x37cd
movl 0x7184(%rip), %edi      # 0xa940
callq 0x3120
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3991
leaq 0x7170(%rip), %rdi      # 0xa944
callq 0x3130
cmpl $0x0, %eax
jge 0x37f5
movl 0x715c(%rip), %edi      # 0xa940
callq 0x3120
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x3991
leaq -0xa0(%rbp), %rdi
xorl %esi, %esi
movl $0x98, %edx
callq 0x3100
leaq 0x361(%rip), %rax       # 0x3b70
movq %rax, -0xa0(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x1c, %edi
leaq -0xa0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x3080
movl 0x7108(%rip), %edi      # 0xa940
leaq 0x710d(%rip), %rsi      # 0xa94c
callq 0x31e0
leaq -0xdc(%rbp), %rdi
leaq 0x70fa(%rip), %rsi      # 0xa94c
movl $0x3c, %edx
callq 0x3170
movl -0xdc(%rbp), %eax
andl $0xfffffa14, %eax       # imm = 0xFFFFFA14
movl %eax, -0xdc(%rbp)
movl -0xd8(%rbp), %eax
andl $-0x2, %eax
movl %eax, -0xd8(%rbp)
movl -0xd0(%rbp), %eax
andl $0xffff7fb4, %eax       # imm = 0xFFFF7FB4
movl %eax, -0xd0(%rbp)
movl -0xd4(%rbp), %eax
andl $0xfffffecf, %eax       # imm = 0xFFFFFECF
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
orl $0x30, %eax
movl %eax, -0xd4(%rbp)
movb $0x0, -0xc5(%rbp)
movb $0x0, -0xc6(%rbp)
movl 0x707f(%rip), %edi      # 0xa940
movl $0x2, %esi
leaq -0xdc(%rbp), %rdx
callq 0x31f0
leaq 0x70af(%rip), %rdi      # 0xa988
movl $0x80, %esi
callq 0x3ba0
leaq 0x70ae(%rip), %rdi      # 0xa998
movl $0x8000, %esi           # imm = 0x8000
callq 0x3ba0
movq 0x70ad(%rip), %rax      # 0xa9a8
movq (%rax), %rsi
leaq 0x7093(%rip), %rdi      # 0xa998
callq 0x3c00
movq 0x7097(%rip), %rax      # 0xa9a8
movq 0x50(%rax), %rsi
leaq 0x707c(%rip), %rdi      # 0xa998
callq 0x3c00
movq 0x7080(%rip), %rax      # 0xa9a8
movq 0x18(%rax), %rsi
leaq 0x7065(%rip), %rdi      # 0xa998
callq 0x3c00
callq 0x3c40
callq 0x3cc0
movl 0x67f8(%rip), %esi      # 0xa140
movl 0x67f6(%rip), %edx      # 0xa144
leaq 0x705b(%rip), %rdi      # 0xa9b0
callq 0x3d40
movl 0x67e0(%rip), %esi      # 0xa140
movl 0x67de(%rip), %edx      # 0xa144
leaq 0x7053(%rip), %rdi      # 0xa9c0
callq 0x3d40
leaq 0x7037(%rip), %rdi      # 0xa9b0
callq 0x3dc0
leaq 0x703b(%rip), %rdi      # 0xa9c0
callq 0x3dc0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax)