// File: brandoncanaday[P]1730sh/1730sh.cpp
// Function: exit_builtin(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&)
int exit_builtin(const vector<string> & args) {
  int status = -1;
  if(args.size() == 1) { // 'exit'
    status = last_exit_status;
    cout << "1730sh: Exited with status: " << status << endl;
    return status;
  } else if(args.size() == 2) { // 'exit [int]'
    bool isNumber = true;
    for(int i = 0, size = args[1].size(); i < size; i++) {
      if(!isdigit(args[1][i])) { // if (number[i] > '9' || number[i] < '0')
	isNumber = false;
	break;
      } // if
    } // for
    if(isNumber) {
      try {
	status = stoi(args[1],0,10);
	cout << "1730sh: Exited with status: " << status << endl;
      } catch(invalid_argument invalidargument) {
	cout << "1730sh: exit: Invalid exit value" << endl;
	status = -1;
      } catch(out_of_range outofrange) {
	cout << "1730sh: exit: Invalid exit value" << endl;
	status = -1;
      } // try/catch
      return status;
    } else {
      cout << "1730sh: exit: Invalid exit value" << endl;
      status = -1;
    } // if/else
    return status;
  } else { // invalid syntax
    cout << "Usage: exit [N]" << endl;
    status = -1;
    return status;
  } // if/else
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
callq 0xb7a0
cmpq $0x1, %rax
jne 0x8f06
movl 0x13489(%rip), %eax     # 0x1c354
movl %eax, -0x14(%rbp)
movq 0x130f3(%rip), %rdi     # 0x1bfc8
leaq 0xc282(%rip), %rsi      # 0x1515e
callq 0x32e0
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x3570
movq %rax, %rdi
movq 0x130b2(%rip), %rsi     # 0x1bfa8
callq 0x3330
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x919c
movq -0x10(%rbp), %rdi
callq 0xb7a0
cmpq $0x2, %rax
jne 0x916d
movb $0x1, -0x15(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0xbb00
movq %rax, %rdi
callq 0x3210
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x8f7f
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0xbb00
movq %rax, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x3350
movsbl (%rax), %edi
callq 0x32b0
cmpl $0x0, %eax
jne 0x8f72
movb $0x0, -0x15(%rbp)
jmp 0x8f7f
jmp 0x8f74
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x8f3d
testb $0x1, -0x15(%rbp)
je 0x913c
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0xbb00
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0xbb20
movl %eax, -0x54(%rbp)
jmp 0x8fad
movl -0x54(%rbp), %eax
movl %eax, -0x14(%rbp)
movq 0x1300e(%rip), %rdi     # 0x1bfc8
leaq 0xc19d(%rip), %rsi      # 0x1515e
callq 0x32e0
movq %rax, -0x60(%rbp)
jmp 0x8fcc
movq -0x60(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x3570
movq %rax, -0x68(%rbp)
jmp 0x8fde
movq -0x68(%rbp), %rdi
movq 0x12fbf(%rip), %rsi     # 0x1bfa8
callq 0x3330
jmp 0x8ff0
jmp 0x906f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x907a
movq -0x28(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x33c0
movq %rax, %rsi
leaq -0x50(%rbp), %rdi
callq 0xbbb0
movq -0x80(%rbp), %rdi
callq 0x3120
movq 0x12f92(%rip), %rdi     # 0x1bfc8
leaq 0xc13e(%rip), %rsi      # 0x1517b
callq 0x32e0
movq %rax, -0x78(%rbp)
jmp 0x9048
movq -0x78(%rbp), %rdi
movq 0x12f55(%rip), %rsi     # 0x1bfa8
callq 0x3330
jmp 0x905a
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
leaq -0x50(%rbp), %rdi
callq 0x3550
callq 0x3530
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x919c
movl -0x6c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x91a8
movq -0x28(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0x33c0
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0xbb60
movq -0x90(%rbp), %rdi
callq 0x3120
movq 0x12f0f(%rip), %rdi     # 0x1bfc8
leaq 0xc0bb(%rip), %rsi      # 0x1517b
callq 0x32e0
movq %rax, -0x88(%rbp)
jmp 0x90ce
movq -0x88(%rbp), %rdi
movq 0x12ecc(%rip), %rsi     # 0x1bfa8
callq 0x3330
jmp 0x90e3
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
leaq -0x40(%rbp), %rdi
callq 0x3480
callq 0x3530
jmp 0x906f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3480
callq 0x3530
jmp 0x9119
jmp 0x91a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3550
callq 0x3530
jmp 0x913a
jmp 0x91a8
movq 0x12e85(%rip), %rdi     # 0x1bfc8
leaq 0xc031(%rip), %rsi      # 0x1517b
callq 0x32e0
movq %rax, %rdi
movq 0x12e4f(%rip), %rsi     # 0x1bfa8
callq 0x3330
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x919c
movq 0x12e54(%rip), %rdi     # 0x1bfc8
leaq 0xc021(%rip), %rsi      # 0x1519c
callq 0x32e0
movq %rax, %rdi
movq 0x12e1e(%rip), %rsi     # 0x1bfa8
callq 0x3330
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x3580
movq %rax, %rdi
callq 0xbba0
nopl (%rax)