// File: brandoncanaday[P]1730sh/1730sh.cpp
// Function: main
int main(int argc, char * argv[]) {

  // prints shell logo
  print_logo();

  // set job control signal dispositions to SIG_IGN
  parent_signals();

  cout.setf(std::ios::unitbuf);
  cin.setf(std::ios::unitbuf);

  // changes to user's home dir upon shell init
  chdir_home();

  string input = "";
  bool hangingPipe = false;
  bool hangingQuote = false;
  
  // begin REPL loop
  while(1) { // exits when ^C

    // polls all of the currently running jobs for status changes
    check_current_jobs();
    
    // prompt
    if(!hangingPipe && !hangingQuote) {
      prompt();
    } else {
      cout << "> ";
    } // if/else

    // only reset input if not waiting on more (due to hanging pipe OR hanging quote). otherwise, append to it.
    if(!hangingPipe && !hangingQuote) {
      input = "";
      getline(cin,input);
      input = trim(input);
    } else {
      string tmp = "";
      getline(cin,tmp);
      tmp = trim(tmp);
      if(hangingQuote) {
	input = input + tmp;
      } else if(hangingPipe) {
	input = input + " " + tmp;
      } // if/else
    } // if/else

    // user just hit [enter]
    if(input == "") continue;

    // if user input actually contains something, check if valid
    if(isValidInput(input)) {
      if(hasQuotes(input) && !hasEvenQuotes(input)) {
	hangingQuote = true;
	continue;
      } // if
      hangingQuote = false;
      if(input[input.length()-1] == '|') {
	hangingPipe = true;
	continue;
      } // if
      hangingPipe = false;

      // if finally have valid input AND no hanging pipes/quotes, make Input obj and do stuff
      Input * job = new Input(input);
      int ** pipes = makePipes(job->getNumPipes());
      int fd_STDIN = STDIN_FILENO;
      int fd_STDOUT = STDOUT_FILENO;
      int fd_STDERR = STDERR_FILENO;
      int pid; 
      
      // sets and/or creates the destinations for any i/o redirection. default is STD[IN/OUT/ERR]_FILENO
      if(set_redirects(job,fd_STDIN,fd_STDOUT,fd_STDERR) == -1) { delete job; continue; } // if

      // command is either built-in || has no pipes
      if(job->getProcesses().size() == 1) {
	string command = job->getProcesses()[0].args[0];
	if(isBuiltIn(command)) { // does not involve fork/exec
	  do_redirects(fd_STDIN,fd_STDOUT,fd_STDERR);
	  close_redirects(fd_STDIN,fd_STDOUT,fd_STDERR);
	  callBuiltIn(command, job->getProcesses()[0].args, job);
	  continue;
	} else { // involves fork/exec
	  if((pid = fork()) == -1) {
	    nope_out("fork");
	  } else if(pid == 0) { // in child
	    child_signals(); // resets signal dispositions back to default
	    job->getProcesses()[0].PID = getpid(); // sets pid for bookkeeping
	    job->setJID(getpid()); // sets JID/PGID of current Input obj/Processes for bookkeeping
	    if(setpgid(getpid(),job->getJID()) == -1) { nope_out("setpgid"); } // sets pgid of process in system
	    if(job->isForeground()) {
	      if(tcsetpgrp(shell_terminal, job->getJID()) == -1) { nope_out("tcsetpgrp"); } // makes JID the foreground pgrp of the terminal
	    } // if
	    do_redirects(fd_STDIN,fd_STDOUT,fd_STDERR);
	    close_redirects(fd_STDIN,fd_STDOUT,fd_STDERR);
	    nice_exec(job->getProcesses()[0].args, pipes, job->getNumPipes());
	  } else { // in parent
	    job->getProcesses()[0].PID = pid; // sets pid for bookkeeping
	    job->setJID(pid); // sets JID/PGID of current Input obj/Processes for bookkeeping
	    if(setpgid(pid,job->getJID()) == -1) { nope_out("setpgid"); } // sets pgid of process in system
	  } // if/else
	  // after job has been launched
	  current_jobs.push_back(job); // add to vector of currently running jobs
	} // if/else
      } else { // command is a pipelined job
	for(unsigned int i = 0, size = job->getProcesses().size(); i < size; i++) {
	  if(i != size-1) { // not last process
	    if(pipe(pipes[i]) == -1) { nope_out("pipe"); } // if
	  } // if
	  if((pid = fork()) == -1) {
	    nope_out("fork");
	  } else if(pid == 0) { // in child
	    job->getProcesses()[i].PID = getpid(); // sets pid for bookkeeping
	    if(i == 0) { job->setJID(getpid()); } // sets JID/PGID of current Input obj/Processes for bookkeeping
	    if(setpgid(getpid(),job->getJID()) == -1) { nope_out("setpgid"); } // sets pgid of process in system
	    if(job->isForeground()) {
	      if(tcsetpgrp(shell_terminal, job->getJID()) == -1) { nope_out("tcsetpgrp"); } // makes JID the foreground pgrp of the terminal
	    } // if
	    child_signals(); // reset signal dispositions back to default
	    if(i == 0) { // first process
	      do_redirects(fd_STDIN,pipes[i][1],-1);
	      close_pipe(pipes[i],true);
	    } else if(i != size-1) { // some middle process
	      do_redirects(pipes[i-1][0],pipes[i][1],-1);
	      close_pipe(pipes[i-1],true);
	      close_pipe(pipes[i],true);
	    } else if(i == size-1) { // last process
	      do_redirects(pipes[i-1][0],fd_STDOUT,fd_STDERR);
	      close_pipe(pipes[i-1],true);
	    } // if/else
	    close_redirects(fd_STDIN,fd_STDOUT,fd_STDERR);
	    nice_exec(job->getProcesses()[i].args, pipes, job->getNumPipes());
	  } else { // in parent
	    job->getProcesses()[i].PID = pid; // sets pid for bookkeeping
	    if(i == 0) { job->setJID(pid); } // sets JID/PGID of current Input obj/Processes
	    if(setpgid(pid,job->getJID()) == -1) { nope_out("setpgid"); } // sets pgid of process in system
	    if(i != 0) {
	      close_pipe(pipes[i-1],true);
	    } // if
	  } // if/else	
	} // for	
	// after job has been launched
	current_jobs.push_back(job); // add to vector of currently running jobs
      } // if/else
      
      close_redirects(fd_STDIN,fd_STDOUT,fd_STDERR); // close i/o redirect fd's
      deletePipes(pipes,job->getNumPipes()); // delete dynamically-allocated pipefd[2] array

      // waits on last child of job if in foreground. if in background, it doesnt.
      if(job->isForeground()) {
	put_job_in_foreground(job,false);
      } else {
	put_job_in_background(job,false);
      } // if/else
    } else { // invalid syntax
      cout << "./1730sh: Invalid command syntax" << endl;
    } // if/else
  } // while
  return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x580, %rsp            # imm = 0x580
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x4d40
callq 0x5450
movq 0x1877e(%rip), %rdi     # 0x1bfc8
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
movl $0x2000, %esi           # imm = 0x2000
movl %esi, -0x3d4(%rbp)
callq 0xb210
movl -0x3d4(%rbp), %esi
movq 0x1876f(%rip), %rdi     # 0x1bfe0
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xb210
callq 0x5840
leaq -0x31(%rbp), %rdi
movq %rdi, -0x3d0(%rbp)
callq 0x3590
movq -0x3d0(%rbp), %rdx
leaq 0x1222b(%rip), %rsi     # 0x15ace
leaq -0x30(%rbp), %rdi
callq 0x3440
jmp 0x38ae
leaq -0x31(%rbp), %rdi
callq 0x3340
movb $0x0, -0x45(%rbp)
movb $0x0, -0x46(%rbp)
jmp 0x38c1
callq 0x5970
jmp 0x38c8
testb $0x1, -0x45(%rbp)
jne 0x3908
testb $0x1, -0x46(%rbp)
jne 0x3908
callq 0x5ca0
jmp 0x38db
jmp 0x391f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x3340
jmp 0x4d2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4d25
movq 0x186b9(%rip), %rdi     # 0x1bfc8
leaq 0x106ee(%rip), %rsi     # 0x14004
callq 0x32e0
jmp 0x391d
jmp 0x391f
testb $0x1, -0x45(%rbp)
jne 0x39bf
testb $0x1, -0x46(%rbp)
jne 0x39bf
leaq 0x12194(%rip), %rsi     # 0x15ace
leaq -0x30(%rbp), %rdi
callq 0x3420
jmp 0x3945
movq 0x18694(%rip), %rdi     # 0x1bfe0
leaq -0x30(%rbp), %rsi
callq 0x3080
jmp 0x3957
leaq -0x88(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3140
jmp 0x3969
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x11ff0
jmp 0x397b
leaq -0x30(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x33b0
leaq -0x68(%rbp), %rdi
callq 0x31e0
leaq -0x88(%rbp), %rdi
callq 0x31e0
jmp 0x3b93
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x31e0
jmp 0x4d25
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x3e0(%rbp)
callq 0x3590
movq -0x3e0(%rbp), %rdx
leaq 0x120ee(%rip), %rsi     # 0x15ace
leaq -0xa8(%rbp), %rdi
callq 0x3440
jmp 0x39ee
leaq -0xa9(%rbp), %rdi
callq 0x3340
movq 0x185df(%rip), %rdi     # 0x1bfe0
leaq -0xa8(%rbp), %rsi
callq 0x3080
jmp 0x3a0f
leaq -0xf0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3140
jmp 0x3a24
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x11ff0
jmp 0x3a39
leaq -0xa8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x33b0
leaq -0xd0(%rbp), %rdi
callq 0x31e0
leaq -0xf0(%rbp), %rdi
callq 0x31e0
testb $0x1, -0x46(%rbp)
je 0x3af3
leaq -0x110(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0xb240
jmp 0x3a87
leaq -0x30(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x33b0
leaq -0x110(%rbp), %rdi
callq 0x31e0
jmp 0x3b74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa9(%rbp), %rdi
callq 0x3340
jmp 0x4d25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3b82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x31e0
jmp 0x3b82
testb $0x1, -0x45(%rbp)
je 0x3b72
leaq 0x10c22(%rip), %rdx     # 0x14722
leaq -0x150(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xb310
jmp 0x3b12
leaq -0x130(%rbp), %rdi
leaq -0x150(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0xb2c0
jmp 0x3b2e
leaq -0x30(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x33b0
leaq -0x130(%rbp), %rdi
callq 0x31e0
leaq -0x150(%rbp), %rdi
callq 0x31e0
jmp 0x3b72
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x31e0
jmp 0x3b82
jmp 0x3b74
leaq -0xa8(%rbp), %rdi
callq 0x31e0
jmp 0x3b93
leaq -0xa8(%rbp), %rdi
callq 0x31e0
jmp 0x4d25
leaq 0x11f34(%rip), %rsi     # 0x15ace
leaq -0x30(%rbp), %rdi
callq 0xb390
movb %al, -0x3e1(%rbp)
jmp 0x3bab
movb -0x3e1(%rbp), %al
testb $0x1, %al
jne 0x3bb7
jmp 0x3bbc
jmp 0x38bf
leaq -0x170(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3140
jmp 0x3bce
leaq -0x170(%rbp), %rdi
callq 0x6120
movb %al, -0x3e2(%rbp)
jmp 0x3be2
leaq -0x170(%rbp), %rdi
callq 0x31e0
movb -0x3e2(%rbp), %al
testb $0x1, %al
jne 0x3bfd
jmp 0x4ced
movb $0x0, -0x1b1(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3140
jmp 0x3c16
leaq -0x190(%rbp), %rdi
callq 0x12240
movb %al, -0x3e3(%rbp)
jmp 0x3c2a
movb -0x3e3(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x3e4(%rbp)
jne 0x3c3f
jmp 0x3c7a
leaq -0x1b0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3140
jmp 0x3c51
movb $0x1, -0x1b1(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x6490
movb %al, -0x3e5(%rbp)
jmp 0x3c6c
movb -0x3e5(%rbp), %al
xorb $-0x1, %al
movb %al, -0x3e4(%rbp)
movb -0x3e4(%rbp), %al
movb %al, -0x3e6(%rbp)
testb $0x1, -0x1b1(%rbp)
jne 0x3c91
jmp 0x3c9d
leaq -0x1b0(%rbp), %rdi
callq 0x31e0
leaq -0x190(%rbp), %rdi
callq 0x31e0
movb -0x3e6(%rbp), %al
testb $0x1, %al
jne 0x3cb5
jmp 0x3d1f
movb $0x1, -0x46(%rbp)
jmp 0x38bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x31e0
jmp 0x4d25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3d0e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
testb $0x1, -0x1b1(%rbp)
jne 0x3d00
jmp 0x3d0c
leaq -0x1b0(%rbp), %rdi
callq 0x31e0
jmp 0x3d0e
leaq -0x190(%rbp), %rdi
callq 0x31e0
jmp 0x4d25
movb $0x0, -0x46(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x34d0
movq -0x3f8(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x3610
movq %rax, -0x3f0(%rbp)
jmp 0x3d4e
movq -0x3f0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7c, %eax
jne 0x3d66
movb $0x1, -0x45(%rbp)
jmp 0x38bf
movb $0x0, -0x45(%rbp)
movl $0xe8, %edi
callq 0x32f0
movq %rax, -0x400(%rbp)
jmp 0x3d7d
movb $0x1, -0x1e1(%rbp)
leaq -0x1e0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3140
jmp 0x3d96
movq -0x400(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0xfdc0
jmp 0x3dab
movb $0x0, -0x1e1(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x31e0
movq -0x400(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0x11ba0
movl %eax, -0x404(%rbp)
jmp 0x3de0
movl -0x404(%rbp), %edi
callq 0x6570
movq %rax, -0x410(%rbp)
jmp 0x3df4
movq -0x410(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movl $0x0, -0x1f4(%rbp)
movl $0x1, -0x1f8(%rbp)
movl $0x2, -0x1fc(%rbp)
movq -0x1c0(%rbp), %rdi
leaq -0x1f4(%rbp), %rsi
leaq -0x1f8(%rbp), %rdx
leaq -0x1fc(%rbp), %rcx
callq 0x6600
movl %eax, -0x414(%rbp)
jmp 0x3e49
movl -0x414(%rbp), %eax
cmpl $-0x1, %eax
jne 0x3ed1
movq -0x1c0(%rbp), %rax
movq %rax, -0x420(%rbp)
cmpq $0x0, %rax
je 0x3e85
movq -0x420(%rbp), %rdi
callq 0xb3c0
movq -0x420(%rbp), %rdi
movl $0xe8, %esi
callq 0x3300
jmp 0x38bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3eb0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x31e0
testb $0x1, -0x1e1(%rbp)
jne 0x3ebb
jmp 0x3ecc
movq -0x400(%rbp), %rdi
movl $0xe8, %esi
callq 0x3300
jmp 0x4d25
movq -0x1c0(%rbp), %rdi
callq 0xb440
movq %rax, -0x428(%rbp)
jmp 0x3ee6
movq -0x428(%rbp), %rdi
callq 0xb460
cmpq $0x1, %rax
jne 0x450b
movq -0x1c0(%rbp), %rdi
callq 0xb440
movq %rax, -0x430(%rbp)
jmp 0x3f11
movq -0x430(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x438(%rbp)
callq 0xb490
movq -0x438(%rbp), %rsi
movq %rax, %rdi
addq $0x10, %rdi
callq 0xb4b0
movq %rax, %rsi
leaq -0x220(%rbp), %rdi
callq 0x3140
jmp 0x3f4c
leaq -0x220(%rbp), %rdi
callq 0x6e70
movb %al, -0x439(%rbp)
jmp 0x3f60
movb -0x439(%rbp), %al
testb $0x1, %al
jne 0x3f6f
jmp 0x4002
movl -0x1f4(%rbp), %edi
movl -0x1f8(%rbp), %esi
movl -0x1fc(%rbp), %edx
callq 0x6f80
jmp 0x3f88
movl -0x1f4(%rbp), %edi
movl -0x1f8(%rbp), %esi
movl -0x1fc(%rbp), %edx
callq 0x7180
jmp 0x3fa1
movq -0x1c0(%rbp), %rdi
callq 0xb440
movq %rax, -0x448(%rbp)
jmp 0x3fb6
movq -0x448(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb490
movq %rax, %rsi
addq $0x10, %rsi
movq -0x1c0(%rbp), %rdx
leaq -0x220(%rbp), %rdi
callq 0x7380
jmp 0x3fe2
movl $0x2, -0x224(%rbp)
jmp 0x44d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x44fa
callq 0x30a0
movl %eax, -0x200(%rbp)
cmpl $-0x1, %eax
jne 0x40a7
leaq -0x249(%rbp), %rdi
movq %rdi, -0x450(%rbp)
callq 0x3590
movq -0x450(%rbp), %rdx
leaq 0xffd0(%rip), %rsi      # 0x14007
leaq -0x248(%rbp), %rdi
callq 0x3440
jmp 0x4045
leaq -0x248(%rbp), %rdi
callq 0xb4d0
jmp 0x4053
leaq -0x248(%rbp), %rdi
callq 0x31e0
leaq -0x249(%rbp), %rdi
callq 0x3340
jmp 0x44b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4096
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x31e0
leaq -0x249(%rbp), %rdi
callq 0x3340
jmp 0x44fa
cmpl $0x0, -0x200(%rbp)
jne 0x43a1
callq 0x7670
jmp 0x40bb
callq 0x34b0
movl %eax, -0x45c(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0xb440
movq %rax, -0x458(%rbp)
jmp 0x40db
movq -0x458(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb490
movl -0x45c(%rbp), %ecx
movl %ecx, (%rax)
movq -0x1c0(%rbp), %rax
movq %rax, -0x468(%rbp)
callq 0x34b0
movq -0x468(%rbp), %rdi
movl %eax, %esi
callq 0x11b30
jmp 0x4116
callq 0x34b0
movl %eax, -0x470(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0xb500
movl %eax, -0x46c(%rbp)
jmp 0x4135
movl -0x46c(%rbp), %esi
movl -0x470(%rbp), %edi
callq 0x3540
cmpl $-0x1, %eax
jne 0x41dd
leaq -0x271(%rbp), %rdi
movq %rdi, -0x478(%rbp)
callq 0x3590
movq -0x478(%rbp), %rdx
leaq 0xfe9c(%rip), %rsi      # 0x1400c
leaq -0x270(%rbp), %rdi
callq 0x3440
jmp 0x417e
leaq -0x270(%rbp), %rdi
callq 0xb4d0
jmp 0x418c
leaq -0x270(%rbp), %rdi
callq 0x31e0
leaq -0x271(%rbp), %rdi
callq 0x3340
jmp 0x41dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x41cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x31e0
leaq -0x271(%rbp), %rdi
callq 0x3340
jmp 0x44fa
movq -0x1c0(%rbp), %rdi
callq 0xb510
movb %al, -0x479(%rbp)
jmp 0x41f1
movb -0x479(%rbp), %al
testb $0x1, %al
jne 0x4200
jmp 0x42ca
movl 0x18152(%rip), %eax     # 0x1c358
movl %eax, -0x484(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0xb500
movl %eax, -0x480(%rbp)
jmp 0x4220
movl -0x480(%rbp), %esi
movl -0x484(%rbp), %edi
callq 0x3460
cmpl $-0x1, %eax
jne 0x42c8
leaq -0x299(%rbp), %rdi
movq %rdi, -0x490(%rbp)
callq 0x3590
movq -0x490(%rbp), %rdx
leaq 0xfdb9(%rip), %rsi      # 0x14014
leaq -0x298(%rbp), %rdi
callq 0x3440
jmp 0x4269
leaq -0x298(%rbp), %rdi
callq 0xb4d0
jmp 0x4277
leaq -0x298(%rbp), %rdi
callq 0x31e0
leaq -0x299(%rbp), %rdi
callq 0x3340
jmp 0x42c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x42b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x31e0
leaq -0x299(%rbp), %rdi
callq 0x3340
jmp 0x44fa
jmp 0x42ca
movl -0x1f4(%rbp), %edi
movl -0x1f8(%rbp), %esi
movl -0x1fc(%rbp), %edx
callq 0x6f80
jmp 0x42e3
movl -0x1f4(%rbp), %edi
movl -0x1f8(%rbp), %esi
movl -0x1fc(%rbp), %edx
callq 0x7180
jmp 0x42fc
movq -0x1c0(%rbp), %rdi
callq 0xb440
movq %rax, -0x498(%rbp)
jmp 0x4311
movq -0x498(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb490
movq %rax, %rsi
addq $0x10, %rsi
leaq -0x2b8(%rbp), %rdi
callq 0xb530
jmp 0x4336
movq -0x1f0(%rbp), %rax
movq %rax, -0x4a8(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0x11ba0
movl %eax, -0x49c(%rbp)
jmp 0x4358
movl -0x49c(%rbp), %edx
movq -0x4a8(%rbp), %rsi
leaq -0x2b8(%rbp), %rdi
callq 0x7b00
jmp 0x4373
leaq -0x2b8(%rbp), %rdi
callq 0xb620
jmp 0x44b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0xb620
jmp 0x44fa
movl -0x200(%rbp), %eax
movl %eax, -0x4b4(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0xb440
movq %rax, -0x4b0(%rbp)
jmp 0x43c2
movq -0x4b0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb490
movl -0x4b4(%rbp), %ecx
movl %ecx, (%rax)
movq -0x1c0(%rbp), %rdi
movl -0x200(%rbp), %esi
callq 0x11b30
jmp 0x43ee
movl -0x200(%rbp), %eax
movl %eax, -0x4bc(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0xb500
movl %eax, -0x4b8(%rbp)
jmp 0x440e
movl -0x4b8(%rbp), %esi
movl -0x4bc(%rbp), %edi
callq 0x3540
cmpl $-0x1, %eax
jne 0x44b3
leaq -0x2d9(%rbp), %rdi
movq %rdi, -0x4c8(%rbp)
callq 0x3590
movq -0x4c8(%rbp), %rdx
leaq 0xfbc3(%rip), %rsi      # 0x1400c
leaq -0x2d8(%rbp), %rdi
callq 0x3440
jmp 0x4457
leaq -0x2d8(%rbp), %rdi
callq 0xb4d0
jmp 0x4465
leaq -0x2d8(%rbp), %rdi
callq 0x31e0
leaq -0x2d9(%rbp), %rdi
callq 0x3340
jmp 0x44b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x44a5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x31e0
leaq -0x2d9(%rbp), %rdi
callq 0x3340
jmp 0x44fa
jmp 0x44b5
jmp 0x44b7
leaq 0x17ea2(%rip), %rdi     # 0x1c360
leaq -0x1c0(%rbp), %rsi
callq 0xb680
jmp 0x44cc
jmp 0x44ce
movl $0x0, -0x224(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x31e0
movl -0x224(%rbp), %eax
testl %eax, %eax
je 0x44f5
jmp 0x44f0
jmp 0x38bf
jmp 0x4c58
leaq -0x220(%rbp), %rdi
callq 0x31e0
jmp 0x4d25
movl $0x0, -0x2e0(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0xb440
movq %rax, -0x4d0(%rbp)
jmp 0x452a
movq -0x4d0(%rbp), %rdi
callq 0xb460
movl %eax, -0x2e4(%rbp)
movl -0x2e0(%rbp), %eax
cmpl -0x2e4(%rbp), %eax
jae 0x4c41
movl -0x2e0(%rbp), %eax
movl -0x2e4(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x4614
movq -0x1f0(%rbp), %rax
movl -0x2e0(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x3430
cmpl $-0x1, %eax
jne 0x4612
leaq -0x309(%rbp), %rdi
movq %rdi, -0x4d8(%rbp)
callq 0x3590
movq -0x4d8(%rbp), %rdx
leaq 0xfa79(%rip), %rsi      # 0x1401e
leaq -0x308(%rbp), %rdi
callq 0x3440
jmp 0x45b3
leaq -0x308(%rbp), %rdi
callq 0xb4d0
jmp 0x45c1
leaq -0x308(%rbp), %rdi
callq 0x31e0
leaq -0x309(%rbp), %rdi
callq 0x3340
jmp 0x4612
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4601
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x308(%rbp), %rdi
callq 0x31e0
leaq -0x309(%rbp), %rdi
callq 0x3340
jmp 0x4d25
jmp 0x4614
callq 0x30a0
movl %eax, -0x200(%rbp)
cmpl $-0x1, %eax
jne 0x46b9
leaq -0x331(%rbp), %rdi
movq %rdi, -0x4e0(%rbp)
callq 0x3590
movq -0x4e0(%rbp), %rdx
leaq 0xf9be(%rip), %rsi      # 0x14007
leaq -0x330(%rbp), %rdi
callq 0x3440
jmp 0x4657
leaq -0x330(%rbp), %rdi
callq 0xb4d0
jmp 0x4665
leaq -0x330(%rbp), %rdi
callq 0x31e0
leaq -0x331(%rbp), %rdi
callq 0x3340
jmp 0x4c2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x46a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x330(%rbp), %rdi
callq 0x31e0
leaq -0x331(%rbp), %rdi
callq 0x3340
jmp 0x4d25
cmpl $0x0, -0x200(%rbp)
jne 0x4ad9
callq 0x34b0
movl %eax, -0x4ec(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0xb440
movq %rax, -0x4e8(%rbp)
jmp 0x46e6
movq -0x4e8(%rbp), %rdi
movl -0x2e0(%rbp), %eax
movl %eax, %esi
callq 0xb490
movl -0x4ec(%rbp), %ecx
movl %ecx, (%rax)
cmpl $0x0, -0x2e0(%rbp)
jne 0x4730
movq -0x1c0(%rbp), %rax
movq %rax, -0x4f8(%rbp)
callq 0x34b0
movq -0x4f8(%rbp), %rdi
movl %eax, %esi
callq 0x11b30
jmp 0x472e
jmp 0x4730
callq 0x34b0
movl %eax, -0x500(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0xb500
movl %eax, -0x4fc(%rbp)
jmp 0x474f
movl -0x4fc(%rbp), %esi
movl -0x500(%rbp), %edi
callq 0x3540
cmpl $-0x1, %eax
jne 0x47f7
leaq -0x359(%rbp), %rdi
movq %rdi, -0x508(%rbp)
callq 0x3590
movq -0x508(%rbp), %rdx
leaq 0xf882(%rip), %rsi      # 0x1400c
leaq -0x358(%rbp), %rdi
callq 0x3440
jmp 0x4798
leaq -0x358(%rbp), %rdi
callq 0xb4d0
jmp 0x47a6
leaq -0x358(%rbp), %rdi
callq 0x31e0
leaq -0x359(%rbp), %rdi
callq 0x3340
jmp 0x47f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x47e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x358(%rbp), %rdi
callq 0x31e0
leaq -0x359(%rbp), %rdi
callq 0x3340
jmp 0x4d25
movq -0x1c0(%rbp), %rdi
callq 0xb510
movb %al, -0x509(%rbp)
jmp 0x480b
movb -0x509(%rbp), %al
testb $0x1, %al
jne 0x481a
jmp 0x48e4
movl 0x17b38(%rip), %eax     # 0x1c358
movl %eax, -0x514(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0xb500
movl %eax, -0x510(%rbp)
jmp 0x483a
movl -0x510(%rbp), %esi
movl -0x514(%rbp), %edi
callq 0x3460
cmpl $-0x1, %eax
jne 0x48e2
leaq -0x381(%rbp), %rdi
movq %rdi, -0x520(%rbp)
callq 0x3590
movq -0x520(%rbp), %rdx
leaq 0xf79f(%rip), %rsi      # 0x14014
leaq -0x380(%rbp), %rdi
callq 0x3440
jmp 0x4883
leaq -0x380(%rbp), %rdi
callq 0xb4d0
jmp 0x4891
leaq -0x380(%rbp), %rdi
callq 0x31e0
leaq -0x381(%rbp), %rdi
callq 0x3340
jmp 0x48e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x48d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x380(%rbp), %rdi
callq 0x31e0
leaq -0x381(%rbp), %rdi
callq 0x3340
jmp 0x4d25
jmp 0x48e4
callq 0x7670
jmp 0x48eb
cmpl $0x0, -0x2e0(%rbp)
jne 0x493c
movl -0x1f4(%rbp), %edi
movq -0x1f0(%rbp), %rax
movl -0x2e0(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6f80
jmp 0x491a
movq -0x1f0(%rbp), %rax
movl -0x2e0(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movl $0x1, %esi
callq 0x7cf0
jmp 0x4937
jmp 0x4a17
movl -0x2e0(%rbp), %eax
movl -0x2e4(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x49b7
movq -0x1f0(%rbp), %rax
movl -0x2e0(%rbp), %ecx
movl %ecx, %edx
decl %edx
movq (%rax,%rdx,8), %rdx
movl (%rdx), %edi
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x6f80
jmp 0x4979
movq -0x1f0(%rbp), %rax
movl -0x2e0(%rbp), %ecx
decl %ecx
movq (%rax,%rcx,8), %rdi
movl $0x1, %esi
callq 0x7cf0
jmp 0x4998
movq -0x1f0(%rbp), %rax
movl -0x2e0(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movl $0x1, %esi
callq 0x7cf0
jmp 0x49b5
jmp 0x4a15
movl -0x2e0(%rbp), %eax
movl -0x2e4(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x4a13
movq -0x1f0(%rbp), %rax
movl -0x2e0(%rbp), %ecx
decl %ecx
movq (%rax,%rcx,8), %rax
movl (%rax), %edi
movl -0x1f8(%rbp), %esi
movl -0x1fc(%rbp), %edx
callq 0x6f80
jmp 0x49f2
movq -0x1f0(%rbp), %rax
movl -0x2e0(%rbp), %ecx
decl %ecx
movq (%rax,%rcx,8), %rdi
movl $0x1, %esi
callq 0x7cf0
jmp 0x4a11
jmp 0x4a13
jmp 0x4a15
jmp 0x4a17
movl -0x1f4(%rbp), %edi
movl -0x1f8(%rbp), %esi
movl -0x1fc(%rbp), %edx
callq 0x7180
jmp 0x4a30
movq -0x1c0(%rbp), %rdi
callq 0xb440
movq %rax, -0x528(%rbp)
jmp 0x4a45
movq -0x528(%rbp), %rdi
movl -0x2e0(%rbp), %eax
movl %eax, %esi
callq 0xb490
movq %rax, %rsi
addq $0x10, %rsi
leaq -0x3a0(%rbp), %rdi
callq 0xb530
jmp 0x4a6e
movq -0x1f0(%rbp), %rax
movq %rax, -0x538(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0x11ba0
movl %eax, -0x52c(%rbp)
jmp 0x4a90
movl -0x52c(%rbp), %edx
movq -0x538(%rbp), %rsi
leaq -0x3a0(%rbp), %rdi
callq 0x7b00
jmp 0x4aab
leaq -0x3a0(%rbp), %rdi
callq 0xb620
jmp 0x4c29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x3a0(%rbp), %rdi
callq 0xb620
jmp 0x4d25
movl -0x200(%rbp), %eax
movl %eax, -0x544(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0xb440
movq %rax, -0x540(%rbp)
jmp 0x4afa
movq -0x540(%rbp), %rdi
movl -0x2e0(%rbp), %eax
movl %eax, %esi
callq 0xb490
movl -0x544(%rbp), %ecx
movl %ecx, (%rax)
cmpl $0x0, -0x2e0(%rbp)
jne 0x4b35
movq -0x1c0(%rbp), %rdi
movl -0x200(%rbp), %esi
callq 0x11b30
jmp 0x4b33
jmp 0x4b35
movl -0x200(%rbp), %eax
movl %eax, -0x54c(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0xb500
movl %eax, -0x548(%rbp)
jmp 0x4b55
movl -0x548(%rbp), %esi
movl -0x54c(%rbp), %edi
callq 0x3540
cmpl $-0x1, %eax
jne 0x4bfd
leaq -0x3c1(%rbp), %rdi
movq %rdi, -0x558(%rbp)
callq 0x3590
movq -0x558(%rbp), %rdx
leaq 0xf47c(%rip), %rsi      # 0x1400c
leaq -0x3c0(%rbp), %rdi
callq 0x3440
jmp 0x4b9e
leaq -0x3c0(%rbp), %rdi
callq 0xb4d0
jmp 0x4bac
leaq -0x3c0(%rbp), %rdi
callq 0x31e0
leaq -0x3c1(%rbp), %rdi
callq 0x3340
jmp 0x4bfd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4bec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x3c0(%rbp), %rdi
callq 0x31e0
leaq -0x3c1(%rbp), %rdi
callq 0x3340
jmp 0x4d25
cmpl $0x0, -0x2e0(%rbp)
je 0x4c27
movq -0x1f0(%rbp), %rax
movl -0x2e0(%rbp), %ecx
decl %ecx
movq (%rax,%rcx,8), %rdi
movl $0x1, %esi
callq 0x7cf0
jmp 0x4c25
jmp 0x4c27
jmp 0x4c29
jmp 0x4c2b
jmp 0x4c2d
movl -0x2e0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2e0(%rbp)
jmp 0x453c
leaq 0x17718(%rip), %rdi     # 0x1c360
leaq -0x1c0(%rbp), %rsi
callq 0xb680
jmp 0x4c56
jmp 0x4c58
movl -0x1f4(%rbp), %edi
movl -0x1f8(%rbp), %esi
movl -0x1fc(%rbp), %edx
callq 0x7180
jmp 0x4c71
movq -0x1f0(%rbp), %rax
movq %rax, -0x568(%rbp)
movq -0x1c0(%rbp), %rdi
callq 0x11ba0
movl %eax, -0x55c(%rbp)
jmp 0x4c93
movl -0x55c(%rbp), %esi
movq -0x568(%rbp), %rdi
callq 0x7e30
jmp 0x4ca7
movq -0x1c0(%rbp), %rdi
callq 0xb510
movb %al, -0x569(%rbp)
jmp 0x4cbb
movb -0x569(%rbp), %al
testb $0x1, %al
jne 0x4cc7
jmp 0x4cd9
movq -0x1c0(%rbp), %rdi
xorl %esi, %esi
callq 0x7ea0
jmp 0x4cd7
jmp 0x4ceb
movq -0x1c0(%rbp), %rdi
xorl %esi, %esi
callq 0x80d0
jmp 0x4ce9
jmp 0x4ceb
jmp 0x4d20
movq 0x172d4(%rip), %rdi     # 0x1bfc8
leaq 0xf328(%rip), %rsi      # 0x14023
callq 0x32e0
movq %rax, -0x578(%rbp)
jmp 0x4d09
movq -0x578(%rbp), %rdi
movq 0x17291(%rip), %rsi     # 0x1bfa8
callq 0x3330
jmp 0x4d1e
jmp 0x4d20
jmp 0x38bf
leaq -0x30(%rbp), %rdi
callq 0x31e0
movq -0x40(%rbp), %rdi
callq 0x3580
nopw (%rax,%rax)