// File: /workspace/github_cpp_makefile_star2_O1/sangwoojun[P]rv32emulator/./linenoise.hpp
// Function: linenoise::getColumns(int, int)
inline int getColumns(int ifd, int ofd) {
#ifdef _WIN32
    CONSOLE_SCREEN_BUFFER_INFO b;

    if (!GetConsoleScreenBufferInfo(hOut, &b)) return 80;
    return b.srWindow.Right - b.srWindow.Left;
#else
    struct winsize ws;

    if (ioctl(1, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) {
        /* ioctl() failed. Try to query the terminal itself. */
        int start, cols;

        /* Get the initial position so we can restore it later. */
        start = getCursorPosition(ifd,ofd);
        if (start == -1) goto failed;

        /* Go to right margin and get position. */
        if (write(ofd,"\x1b[999C",6) != 6) goto failed;
        cols = getCursorPosition(ifd,ofd);
        if (cols == -1) goto failed;

        /* Restore position. */
        if (cols > start) {
            char seq[32];
            snprintf(seq,32,"\x1b[%dD",cols-start);
            if (write(ofd,seq,strlen(seq)) == -1) {
                /* Can't recover... */
            }
        }
        return cols;
    } else {
        return ws.ws_col;
    }

failed:
    return 80;
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebx
movl %edi, %r14d
leaq -0x58(%rbp), %r15
movl $0x5413, %esi           # imm = 0x5413
movl $0x1, %edi
movq %r15, %rdx
xorl %eax, %eax
callq 0x22a0
cmpl $-0x1, %eax
sete %cl
movzwl 0x2(%r15), %eax
testw %ax, %ax
sete %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x614c
leaq 0x5a0a(%rip), %rsi      # 0xba09
movl $0x4, %edx
movl %ebx, %edi
callq 0x20a0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0x4, %rax
jne 0x6087
xorl %r15d, %r15d
leaq (%r15,%rbp), %rsi
addq $-0x50, %rsi
movl $0x1, %edx
movl %r14d, %edi
callq 0x22b0
cmpq $0x1, %rax
jne 0x604c
cmpb $0x52, -0x50(%rbp,%r15)
je 0x604c
incq %r15
cmpq $0x1f, %r15
jne 0x601a
movl $0x1f, %r15d
movb $0x0, -0x50(%rbp,%r15)
cmpb $0x1b, -0x50(%rbp)
jne 0x6087
cmpb $0x5b, -0x4f(%rbp)
jne 0x6087
leaq -0x4e(%rbp), %rdi
leaq 0x59a5(%rip), %rsi      # 0xba0e
leaq -0x30(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
xorl %eax, %eax
callq 0x21a0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x2, %eax
jne 0x6087
movl -0x2c(%rbp), %r12d
movl $0x50, %r15d
cmpl $-0x1, %r12d
je 0x6150
leaq 0x595e(%rip), %rsi      # 0xb9fc
movl $0x6, %edx
movl %ebx, %edi
callq 0x20a0
cmpq $0x6, %rax
jne 0x6150
leaq 0x594e(%rip), %rsi      # 0xba09
movl $0x4, %edx
movl %ebx, %edi
callq 0x20a0
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpq $0x4, %rax
jne 0x6168
xorl %r13d, %r13d
leaq -0x50(,%r13), %rsi
addq %rbp, %rsi
movl $0x1, %edx
movl %r14d, %edi
callq 0x22b0
cmpq $0x1, %rax
jne 0x610f
cmpb $0x52, -0x50(%rbp,%r13)
je 0x610f
incq %r13
cmpq $0x1f, %r13
jne 0x60da
movl $0x1f, %r13d
movb $0x0, -0x50(%rbp,%r13)
cmpb $0x1b, -0x50(%rbp)
jne 0x6162
cmpb $0x5b, -0x4f(%rbp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jne 0x6168
leaq -0x4e(%rbp), %rdi
leaq 0x58dc(%rip), %rsi      # 0xba0e
leaq -0x30(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
xorl %eax, %eax
callq 0x21a0
cmpl $0x2, %eax
jne 0x6168
movl -0x2c(%rbp), %r13d
jmp 0x6168
movzwl %ax, %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $-0x1, %r13d
je 0x6150
movl %r13d, %ecx
subl %r12d, %ecx
jle 0x61a5
leaq 0x5886(%rip), %rdx      # 0xba03
leaq -0x50(%rbp), %r14
movl $0x20, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x2340
movq %r14, %rdi
callq 0x20f0
movl %ebx, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x20a0
movl %r13d, %r15d
jmp 0x6150