// File: /workspace/github_cpp_makefile_star2_O3/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 0x7b2d
cmpq $0x1, %rcx
jne 0x7bfc
movl 0xa82b(%rip), %ebx      # 0x12304
movq 0xa4f0(%rip), %r14      # 0x11fd0
leaq 0x6677(%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 0x7c58
movq 0x20(%rax), %r15
movq 0x28(%rax), %rax
testl %eax, %eax
jle 0x7b59
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movsbl (%r15,%rcx), %edx
addl $-0x30, %edx
cmpl $0xa, %edx
jae 0x7c11
incq %rcx
cmpq %rcx, %rax
jne 0x7b40
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 0x7c69
movq %rax, %rbx
movslq %ebx, %rax
cmpq %rbx, %rax
jne 0x7c75
movl (%r14), %eax
cmpl $0x22, %eax
je 0x7c75
testl %eax, %eax
jne 0x7baa
movl %r13d, (%r14)
movq 0xa41f(%rip), %rdi      # 0x11fd0
leaq 0x65a6(%rip), %rsi      # 0xe15e
movl $0x1c, %edx
callq 0x3300
movq 0xa407(%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 0x7c58
movq 0xa3cd(%rip), %rbx      # 0x11fd0
leaq 0x6592(%rip), %rsi      # 0xe19c
movl $0xf, %edx
jmp 0x7c24
movq 0xa3b8(%rip), %rbx      # 0x11fd0
leaq 0x655c(%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 0x6deb(%rip), %rdi      # 0xea5b
callq 0x3190
leaq 0x6ddf(%rip), %rdi      # 0xea5b
callq 0x33f0
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x7c92
movl %r13d, (%r14)
jmp 0x7c92
movq %rax, %rbx
cmpl $0x2, %edx
jne 0x7cf3
movq %rbx, %rdi
callq 0x3360
leaq -0x38(%rbp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x34e0
movq 0xa30b(%rip), %rax      # 0x11fc0
addq $0x10, %rax
movq %rax, (%r14)
movq %rbx, %rdi
callq 0x3120
movq 0xa305(%rip), %rdi      # 0x11fd0
leaq 0x64a9(%rip), %rsi      # 0xe17b
movl $0x20, %edx
callq 0x3300
movq 0xa2ed(%rip), %rdi      # 0x11fd0
callq 0x3140
leaq -0x38(%rbp), %rdi
callq 0x34d0
jmp 0x7d56
cmpl $0x1, %edx
jne 0x7d84
movq %rbx, %rdi
callq 0x3360
leaq -0x38(%rbp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x34e0
movq 0xa2ae(%rip), %rax      # 0x11fc8
addq $0x10, %rax
movq %rax, (%r14)
movq %rbx, %rdi
callq 0x3120
movq 0xa2a0(%rip), %rdi      # 0x11fd0
leaq 0x6444(%rip), %rsi      # 0xe17b
movl $0x20, %edx
callq 0x3300
movq 0xa288(%rip), %rdi      # 0x11fd0
callq 0x3140
leaq -0x38(%rbp), %rdi
callq 0x33e0
callq 0x34a0
jmp 0x7c53
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x33e0
callq 0x34a0
jmp 0x7d84
movq %rax, %rbx
leaq -0x38(%rbp), %rdi
callq 0x34d0
callq 0x34a0
movq %rbx, %rdi
callq 0x3530
movq %rax, %rdi
callq 0x9d7a