// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movl %esi, %ebx
movl %edi, %r14d
leaq -0x68(%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 0x60f1
leaq 0x5a3c(%rip), %rsi      # 0xb99d
movl $0x4, %edx
movl %ebx, %edi
callq 0x20a0
cmpq $0x4, %rax
jne 0x60f7
xorl %r12d, %r12d
leaq (%r12,%rbp), %r15
addq $-0x60, %r15
movl $0x1, %edx
movl %r14d, %edi
movq %r15, %rsi
callq 0x22b0
cmpq $0x1, %rax
jne 0x5fad
cmpb $0x52, (%r15)
je 0x5fad
incq %r12
cmpq $0x1f, %r12
jne 0x5f7a
movl $0x1f, %r12d
movb $0x0, -0x60(%rbp,%r12)
cmpb $0x1b, -0x60(%rbp)
jne 0x60f7
cmpb $0x5b, -0x5f(%rbp)
jne 0x60f7
leaq -0x5e(%rbp), %rdi
leaq 0x59d0(%rip), %rsi      # 0xb9a2
leaq -0x34(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
xorl %eax, %eax
callq 0x21a0
cmpl $0x2, %eax
jne 0x60f7
movl -0x2c(%rbp), %r12d
movl $0x50, %r15d
cmpl $-0x1, %r12d
je 0x60fd
leaq 0x598b(%rip), %rsi      # 0xb990
movl $0x6, %edx
movl %ebx, %edi
callq 0x20a0
cmpq $0x6, %rax
jne 0x60fd
leaq 0x597b(%rip), %rsi      # 0xb99d
movl $0x4, %edx
movl %ebx, %edi
callq 0x20a0
cmpq $0x4, %rax
jne 0x60fd
movl %r12d, -0x30(%rbp)
xorl %r13d, %r13d
leaq -0x60(,%r13), %r12
addq %rbp, %r12
movl $0x1, %edx
movl %r14d, %edi
movq %r12, %rsi
callq 0x22b0
cmpq $0x1, %rax
jne 0x6076
cmpb $0x52, (%r12)
je 0x6076
incq %r13
cmpq $0x1f, %r13
jne 0x603f
movl $0x1f, %r13d
movb $0x0, -0x60(%rbp,%r13)
cmpb $0x1b, -0x60(%rbp)
movl -0x30(%rbp), %r14d
jne 0x60fd
cmpb $0x5b, -0x5f(%rbp)
jne 0x60fd
leaq -0x5e(%rbp), %rdi
leaq 0x590b(%rip), %rsi      # 0xb9a2
leaq -0x34(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
xorl %eax, %eax
callq 0x21a0
cmpl $0x2, %eax
jne 0x60fd
movl -0x2c(%rbp), %r12d
cmpl $-0x1, %r12d
je 0x60fd
movl %r12d, %ecx
subl %r14d, %ecx
jle 0x60ec
leaq 0x58d3(%rip), %rdx      # 0xb997
leaq -0x60(%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 %r12d, %r15d
jmp 0x60fd
movzwl %ax, %r15d
jmp 0x60fd
movl $0x50, %r15d
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq