// File: brandoncanaday[P]1730sh/1730sh.cpp
// Function: export_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 export_builtin(const vector<string> & args) {
  if(args.size() != 2) {
    cout << "1730sh: Usage: export NAME[=WORD]" << endl;
    return -1;
  } else {
    string str = args[1];
    size_t pos;
    if((pos = str.find("=")) != string::npos) {
      if(pos == 0) { // user entered '=NAME' or '='
	cout << "1730sh: Usage: export NAME[=WORD]" << endl;
	return -1;
      } else { // user entered 'NA=ME' or 'NAME='
	string name = str.substr(0,pos);
	string value = (pos == str.length()-1) ? "" : str.substr(pos+1,str.length()-1-pos); 
	if(setenv(name.c_str(),value.c_str(),1) == -1) {
	  int err = errno; 
	  cout << "1730sh: export: " << str << ": " << strerror(err) << endl;
	  return -1;
	} // if
      } // if/else
    } else { // user entered something like 'NAME'
      string name = str;
      string value = "";
      if(setenv(name.c_str(),value.c_str(),1) == -1) { 
	int err = errno; 
	cout << "1730sh: export: " << str << ": " << strerror(err) << endl;
	return -1;
      } // if
    } // if/else
  } // if/else
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0xb7a0
cmpq $0x2, %rax
je 0x9c5c
movq 0x12393(%rip), %rdi     # 0x1bfc8
leaq 0xbcba(%rip), %rsi      # 0x158f6
callq 0x32e0
movq %rax, %rdi
movq 0x1235d(%rip), %rsi     # 0x1bfa8
callq 0x3330
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xa0f4
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0xbb00
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
callq 0x3140
leaq -0x30(%rbp), %rdi
leaq 0xb1e8(%rip), %rsi      # 0x14e69
xorl %eax, %eax
movl %eax, %edx
callq 0x3600
movq %rax, -0x38(%rbp)
cmpq $-0x1, %rax
je 0x9f2a
cmpq $0x0, -0x38(%rbp)
jne 0x9cf4
movq 0x12322(%rip), %rdi     # 0x1bfc8
leaq 0xbc49(%rip), %rsi      # 0x158f6
callq 0x32e0
movq %rax, -0xe0(%rbp)
jmp 0x9cbb
movq -0xe0(%rbp), %rdi
movq 0x122df(%rip), %rsi     # 0x1bfa8
callq 0x3330
jmp 0x9cd0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x48(%rbp)
jmp 0xa0cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xa0e2
movq -0x38(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x68(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3310
jmp 0x9d0b
movq -0x38(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x34d0
movq %rax, %rcx
movq -0xe8(%rbp), %rax
subq $0x1, %rcx
movb $0x0, -0x8a(%rbp)
cmpq %rcx, %rax
jne 0x9d71
leaq -0x89(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x3590
movq -0xf0(%rbp), %rdx
movb $0x1, -0x8a(%rbp)
leaq 0xbd6d(%rip), %rsi      # 0x15ace
leaq -0x88(%rbp), %rdi
callq 0x3440
jmp 0x9d6f
jmp 0x9db7
movq -0x38(%rbp), %rax
incq %rax
movq %rax, -0xf8(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x34d0
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
movq -0x38(%rbp), %rcx
notq %rcx
addq %rax, %rcx
leaq -0x88(%rbp), %rdi
callq 0x3310
jmp 0x9db5
jmp 0x9db7
testb $0x1, -0x8a(%rbp)
jne 0x9dc2
jmp 0x9dce
leaq -0x89(%rbp), %rdi
callq 0x3340
leaq -0x68(%rbp), %rdi
callq 0x3130
movq %rax, -0x108(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x3130
movq -0x108(%rbp), %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x34e0
cmpl $-0x1, %eax
jne 0x9eec
callq 0x3060
movl (%rax), %eax
movl %eax, -0x90(%rbp)
movq 0x121ad(%rip), %rdi     # 0x1bfc8
leaq 0xbaf6(%rip), %rsi      # 0x15918
callq 0x32e0
movq %rax, -0x110(%rbp)
jmp 0x9e30
movq -0x110(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x32a0
movq %rax, -0x118(%rbp)
jmp 0x9e49
movq -0x118(%rbp), %rdi
leaq 0xba9a(%rip), %rsi      # 0x158f1
callq 0x32e0
movq %rax, -0x120(%rbp)
jmp 0x9e65
movl -0x90(%rbp), %edi
callq 0x30e0
movq -0x120(%rbp), %rdi
movq %rax, %rsi
callq 0x32e0
movq %rax, -0x128(%rbp)
jmp 0x9e88
movq -0x128(%rbp), %rdi
movq 0x12112(%rip), %rsi     # 0x1bfa8
callq 0x3330
jmp 0x9e9d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x48(%rbp)
jmp 0x9ef3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
testb $0x1, -0x8a(%rbp)
jne 0x9ec4
jmp 0x9ed0
leaq -0x89(%rbp), %rdi
callq 0x3340
jmp 0x9f17
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x31e0
jmp 0x9f17
movl $0x0, -0x48(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x31e0
leaq -0x68(%rbp), %rdi
callq 0x31e0
movl -0x48(%rbp), %eax
testl %eax, %eax
jne 0xa0cc
jmp 0x9f15
jmp 0x9f25
leaq -0x68(%rbp), %rdi
callq 0x31e0
jmp 0xa0e2
jmp 0xa0c5
leaq -0xb0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3140
jmp 0x9f3c
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x3590
movq -0x130(%rbp), %rdx
leaq 0xbb71(%rip), %rsi      # 0x15ace
leaq -0xd0(%rbp), %rdi
callq 0x3440
jmp 0x9f6b
leaq -0xd1(%rbp), %rdi
callq 0x3340
leaq -0xb0(%rbp), %rdi
callq 0x3130
movq %rax, -0x138(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3130
movq -0x138(%rbp), %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x34e0
cmpl $-0x1, %eax
jne 0xa08d
callq 0x3060
movl (%rax), %eax
movl %eax, -0xd8(%rbp)
movq 0x12001(%rip), %rdi     # 0x1bfc8
leaq 0xb94a(%rip), %rsi      # 0x15918
callq 0x32e0
movq %rax, -0x140(%rbp)
jmp 0x9fdc
movq -0x140(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x32a0
movq %rax, -0x148(%rbp)
jmp 0x9ff5
movq -0x148(%rbp), %rdi
leaq 0xb8ee(%rip), %rsi      # 0x158f1
callq 0x32e0
movq %rax, -0x150(%rbp)
jmp 0xa011
movl -0xd8(%rbp), %edi
callq 0x30e0
movq -0x150(%rbp), %rdi
movq %rax, %rsi
callq 0x32e0
movq %rax, -0x158(%rbp)
jmp 0xa034
movq -0x158(%rbp), %rdi
movq 0x11f66(%rip), %rsi     # 0x1bfa8
callq 0x3330
jmp 0xa049
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x48(%rbp)
jmp 0xa094
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xd1(%rbp), %rdi
callq 0x3340
jmp 0xa0b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x31e0
jmp 0xa0b7
movl $0x0, -0x48(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x31e0
leaq -0xb0(%rbp), %rdi
callq 0x31e0
movl -0x48(%rbp), %eax
testl %eax, %eax
jne 0xa0cc
jmp 0xa0b5
jmp 0xa0c5
leaq -0xb0(%rbp), %rdi
callq 0x31e0
jmp 0xa0e2
movl $0x0, -0x48(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x31e0
movl -0x48(%rbp), %eax
testl %eax, %eax
je 0xa0e0
jmp 0xa0de
jmp 0xa0f4
jmp 0xa0ed
leaq -0x30(%rbp), %rdi
callq 0x31e0
jmp 0xa100
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x3580
nopl (%rax)