// File: akojo[P]quickfind/term.cpp
// Function: Term::Term(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
Term::Term(const string& ttyName)
{
    tty = fopen(ttyName.c_str(), "r+");
    if (!tty)
        throw invalid_argument("bad tty");
    setbuf(tty, nullptr);

    int fd = fileno(tty);
    if (tcgetattr(fd, &old_termios) < 0)
        throw runtime_error("failed to read terminal parameters");

    struct termios new_termios = old_termios;
    new_termios.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
    if (tcsetattr(fd, TCSAFLUSH, &new_termios) < 0) {
        throw runtime_error(string("failed to set terminal parameters: ") + strerror(errno));
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x30d0
movq %rax, %rdi
leaq 0x1463(%rip), %rsi      # 0x8054
callq 0x32b0
movq %rax, %rcx
movq -0xb0(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, (%rax)
jne 0x6c65
movl $0x10, %edi
callq 0x3110
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
leaq 0x1430(%rip), %rsi      # 0x8057
callq 0x3410
jmp 0x6c2e
movq -0xb8(%rbp), %rdi
movq 0x4394(%rip), %rsi      # 0xafd0
movq 0x437d(%rip), %rdx      # 0xafc0
callq 0x33c0
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3170
jmp 0x6e44
movq -0xb0(%rbp), %rax
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3340
movq -0xb0(%rbp), %rax
movq (%rax), %rdi
callq 0x3240
movq -0xb0(%rbp), %rsi
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %edi
addq $0x8, %rsi
callq 0x3290
cmpl $0x0, %eax
jge 0x6cfe
movl $0x10, %edi
callq 0x3110
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
leaq 0x139f(%rip), %rsi      # 0x805f
callq 0x30b0
jmp 0x6cc7
movq -0xc0(%rbp), %rdi
movq 0x431b(%rip), %rsi      # 0xaff0
movq 0x42d4(%rip), %rdx      # 0xafb0
callq 0x33c0
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x3170
jmp 0x6e44
movq -0xb0(%rbp), %rsi
addq $0x8, %rsi
leaq -0x5c(%rbp), %rdi
movl $0x3c, %edx
callq 0x31a0
movl -0x50(%rbp), %eax
andl $0xffff7ff4, %eax       # imm = 0xFFFF7FF4
movl %eax, -0x50(%rbp)
movl -0x20(%rbp), %edi
movl $0x2, %esi
leaq -0x5c(%rbp), %rdx
callq 0x3300
cmpl $0x0, %eax
jge 0x6e3b
movb $0x1, -0xa2(%rbp)
movl $0x10, %edi
callq 0x3110
movq %rax, -0xd0(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x33f0
movq -0xc8(%rbp), %rdx
leaq 0x130d(%rip), %rsi      # 0x8082
leaq -0xa0(%rbp), %rdi
callq 0x3da0
jmp 0x6d83
callq 0x3030
movl (%rax), %edi
callq 0x3090
movq %rax, %rdx
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x7180
jmp 0x6da4
movq -0xd0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x33a0
jmp 0x6db6
movq -0xd0(%rbp), %rdi
movb $0x0, -0xa2(%rbp)
movq 0x4225(%rip), %rsi      # 0xaff0
movq 0x41de(%rip), %rdx      # 0xafb0
callq 0x33c0
jmp 0x6e4d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x6e16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x6e0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x3140
leaq -0xa0(%rbp), %rdi
callq 0x3140
leaq -0xa1(%rbp), %rdi
callq 0x3250
testb $0x1, -0xa2(%rbp)
jne 0x6e2d
jmp 0x6e39
movq -0xd0(%rbp), %rdi
callq 0x3170
jmp 0x6e44
addq $0xd0, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x33d0
nopl (%rax)