// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
cmpq $0x2, %rcx
je 0x7b13
cmpq $0x1, %rcx
jne 0x7be6
movl 0xa845(%rip), %ebx      # 0x12304
movq 0xa50a(%rip), %r14      # 0x11fd0
leaq 0x6691(%rip), %rsi      # 0xe15e
movl $0x1c, %edx
movq %r14, %rdi
callq 0x3300
movq %r14, %rdi
movl %ebx, %esi
callq 0x3510
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31b0
jmp 0x7c42
movq 0x28(%rax), %rcx
testl %ecx, %ecx
jle 0x7b3f
movq 0x20(%rax), %rdx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %esi, %esi
movsbl (%rdx,%rsi), %edi
addl $-0x30, %edi
cmpl $0xa, %edi
jae 0x7bfb
incq %rsi
cmpq %rsi, %rcx
jne 0x7b27
movq 0x20(%rax), %r15
callq 0x3060
movq %rax, %r14
movl (%rax), %r13d
movl $0x0, (%rax)
leaq -0x38(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x33b0
cmpq %r15, (%r12)
je 0x7c53
movq %rax, %rbx
movslq %ebx, %rax
cmpq %rbx, %rax
jne 0x7c5f
movl (%r14), %eax
cmpl $0x22, %eax
je 0x7c5f
testl %eax, %eax
jne 0x7b94
movl %r13d, (%r14)
movq 0xa435(%rip), %rdi      # 0x11fd0
leaq 0x65bc(%rip), %rsi      # 0xe15e
movl $0x1c, %edx
callq 0x3300
movq 0xa41d(%rip), %rdi      # 0x11fd0
movl %ebx, %esi
callq 0x3510
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31b0
jmp 0x7c42
movq 0xa3e3(%rip), %rbx      # 0x11fd0
leaq 0x65a8(%rip), %rsi      # 0xe19c
movl $0xf, %edx
jmp 0x7c0e
movq 0xa3ce(%rip), %rbx      # 0x11fd0
leaq 0x6572(%rip), %rsi      # 0xe17b
movl $0x20, %edx
movq %rbx, %rdi
callq 0x3300
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31b0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6e01(%rip), %rdi      # 0xea5b
callq 0x3190
leaq 0x6df5(%rip), %rdi      # 0xea5b
callq 0x33f0
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x7c7c
movl %r13d, (%r14)
jmp 0x7c7c
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x7cdd
movq %rbx, %rdi
callq 0x3360
leaq -0x38(%rbp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x34e0
movq 0xa321(%rip), %rax      # 0x11fc0
addq $0x10, %rax
movq %rax, (%r14)
movq %rbx, %rdi
callq 0x3120
movq 0xa31b(%rip), %rdi      # 0x11fd0
leaq 0x64bf(%rip), %rsi      # 0xe17b
movl $0x20, %edx
callq 0x3300
movq 0xa303(%rip), %rdi      # 0x11fd0
callq 0x3140
leaq -0x38(%rbp), %rdi
callq 0x34d0
jmp 0x7d40
cmpl $0x1, %edx
jne 0x7d6e
movq %rbx, %rdi
callq 0x3360
leaq -0x38(%rbp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x34e0
movq 0xa2c4(%rip), %rax      # 0x11fc8
addq $0x10, %rax
movq %rax, (%r14)
movq %rbx, %rdi
callq 0x3120
movq 0xa2b6(%rip), %rdi      # 0x11fd0
leaq 0x645a(%rip), %rsi      # 0xe17b
movl $0x20, %edx
callq 0x3300
movq 0xa29e(%rip), %rdi      # 0x11fd0
callq 0x3140
leaq -0x38(%rbp), %rdi
callq 0x33e0
callq 0x34a0
jmp 0x7c3d
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x33e0
callq 0x34a0
jmp 0x7d6e
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x34d0
callq 0x34a0
movq %rbx, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x9dcc