// File: /workspace/github_cpp_makefile_star2_O3/brandoncanaday[P]1730sh/1730sh.cpp
// Function: set_redirects(Input*, int&, int&, int&)
int set_redirects(Input * job, int& fdSTDIN, int& fdSTDOUT, int& fdSTDERR) {
  fdSTDIN = STDIN_FILENO;
  fdSTDOUT = STDOUT_FILENO;
  fdSTDERR = STDERR_FILENO;
  // if user input specified any i/o redirection, open/create the given fd's
  if(job->getSTDIN_fd() != "STDIN_FILENO") {
    if((fdSTDIN = open(job->getSTDIN_fd().c_str(), O_RDONLY)) == -1) {
      cout << "1730sh: " << job->getSTDIN_fd() << ": No such file or directory" << endl;
      return -1;
    } // if
  } // if
  if(job->getSTDOUT_fd() != "STDOUT_FILENO") {
    if(job->getSTDOUT_type() == ">") {
      if((fdSTDOUT = open(job->getSTDOUT_fd().c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644)) == -1) {
	cout << "1730sh: `" << job->getSTDOUT_fd() << "' cannot be opened" << endl;
	return -1;
      } // if
    } else {
      if((fdSTDOUT = open(job->getSTDOUT_fd().c_str(), O_CREAT | O_WRONLY | O_APPEND, 0666)) == -1) {
	cout << "1730sh: `" << job->getSTDOUT_fd() << "' cannot be opened" << endl;
	return -1;
      } // if
    } // if/else
  } // if
  if(job->getSTDERR_fd() != "STDERR_FILENO") {
    if(job->getSTDERR_type() == "e>") {
      if((fdSTDERR = open(job->getSTDERR_fd().c_str(), O_CREAT | O_WRONLY | O_TRUNC, 0644)) == -1) {
	cout << "1730sh: `" << job->getSTDERR_fd() << "' cannot be opened" << endl;
	return -1;
      } // if
    } else {
      if((fdSTDERR = open(job->getSTDERR_fd().c_str(), O_CREAT | O_WRONLY | O_APPEND, 0666)) == -1) {
	cout << "1730sh: `" << job->getSTDERR_fd() << "' cannot be opened" << endl;
	return -1;
      } // if
    } // if/else
  } // if
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movl $0x0, (%rsi)
movq %rdx, -0x58(%rbp)
movl $0x1, (%rdx)
movq %rcx, -0x50(%rbp)
movl $0x2, (%rcx)
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x48(%rdi), %rsi
movq 0x50(%rdi), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %r14
movq %r14, %rdi
callq 0x9f52
leaq 0x6f39(%rip), %rsi      # 0xd089
movq %r14, %rdi
callq 0x30b0
movl %eax, %r13d
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x616f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
testl %r13d, %r13d
je 0x61bc
movq %r15, (%r14)
movq 0x48(%rbx), %rsi
movq 0x50(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f52
movq (%r14), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x31e0
movl %eax, %r13d
movl %eax, (%r12)
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x61b2
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
cmpl $-0x1, %r13d
je 0x632a
leaq -0x38(%rbp), %r13
movq %r13, (%r14)
movq 0x68(%rbx), %rsi
movq 0x70(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f52
leaq 0x6ed5(%rip), %rsi      # 0xd0b2
movq %r14, %rdi
callq 0x30b0
movl %eax, %r12d
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x61fc
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
testl %r12d, %r12d
je 0x6415
movq %r13, (%r14)
movq 0x88(%rbx), %rsi
movq 0x90(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f52
leaq 0x6e3c(%rip), %rsi      # 0xd064
movq %r14, %rdi
callq 0x30b0
movl %eax, %r12d
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x6247
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
testl %r12d, %r12d
je 0x63c2
movq %r13, (%r14)
movq 0x68(%rbx), %rsi
movq 0x70(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f52
movq (%r14), %rdi
movl $0x441, %esi            # imm = 0x441
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x31e0
movl %eax, %r12d
movq -0x58(%rbp), %rax
movl %r12d, (%rax)
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x6299
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
cmpl $-0x1, %r12d
jne 0x6415
movq 0xbd26(%rip), %r14      # 0x11fd0
leaq 0x6e0f(%rip), %rsi      # 0xd0c0
movl $0x9, %edx
movq %r14, %rdi
callq 0x3300
leaq -0x48(%rbp), %r15
movq %r13, (%r15)
movq 0x68(%rbx), %rsi
movq 0x70(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x9f52
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r14, %rdi
callq 0x3300
movq %rax, %rbx
leaq 0x6dd9(%rip), %rsi      # 0xd0ca
movl $0x12, %edx
movq %rax, %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
jmp 0x6700
movq 0xbc9f(%rip), %r14      # 0x11fd0
leaq 0x6d2e(%rip), %rsi      # 0xd066
movl $0x8, %edx
movq %r14, %rdi
callq 0x3300
leaq -0x48(%rbp), %r15
leaq -0x38(%rbp), %r12
movq %r12, (%r15)
movq 0x48(%rbx), %rsi
movq 0x50(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x9f52
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r14, %rdi
callq 0x3300
movq %rax, %rbx
leaq 0x6d1a(%rip), %rsi      # 0xd096
movl $0x1b, %edx
movq %rax, %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
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
jne 0x6709
jmp 0x6715
movq %r13, (%r14)
movq 0x68(%rbx), %rsi
movq 0x70(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f52
movq (%r14), %rdi
movl $0x241, %esi            # imm = 0x241
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x31e0
movl %eax, %r12d
movq -0x58(%rbp), %rax
movl %r12d, (%rax)
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x640b
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
cmpl $-0x1, %r12d
je 0x65f1
movq %r13, (%r14)
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f52
leaq 0x6ca5(%rip), %rsi      # 0xd0dd
movq %r14, %rdi
callq 0x30b0
movl %eax, %r15d
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x6457
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
testl %r15d, %r15d
je 0x65ea
movq %r13, (%r14)
movq 0xc8(%rbx), %rsi
movq 0xd0(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f52
leaq 0x6bdc(%rip), %rsi      # 0xd05f
movq %r14, %rdi
callq 0x30b0
movl %eax, %r15d
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x64a2
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
testl %r15d, %r15d
je 0x6591
movq %r13, (%r14)
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f52
movq (%r14), %rdi
movl $0x441, %esi            # imm = 0x441
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x31e0
movl %eax, %r15d
movq -0x50(%rbp), %rax
movl %r15d, (%rax)
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x64fa
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
cmpl $-0x1, %r15d
jne 0x65ea
movq 0xbac5(%rip), %r14      # 0x11fd0
leaq 0x6bae(%rip), %rsi      # 0xd0c0
movl $0x9, %edx
movq %r14, %rdi
callq 0x3300
leaq -0x48(%rbp), %r15
movq %r13, (%r15)
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x9f52
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r14, %rdi
callq 0x3300
movq %rax, %rbx
leaq 0x6b72(%rip), %rsi      # 0xd0ca
movl $0x12, %edx
movq %rax, %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
jmp 0x6700
movq %r13, (%r14)
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f52
movq (%r14), %rdi
movl $0x241, %esi            # imm = 0x241
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x31e0
movl %eax, %r15d
movq -0x50(%rbp), %rax
movl %r15d, (%rax)
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x65e0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
cmpl $-0x1, %r15d
je 0x6678
xorl %eax, %eax
jmp 0x671a
movq 0xb9d8(%rip), %r14      # 0x11fd0
leaq 0x6ac1(%rip), %rsi      # 0xd0c0
movl $0x9, %edx
movq %r14, %rdi
callq 0x3300
leaq -0x48(%rbp), %r15
movq %r13, (%r15)
movq 0x68(%rbx), %rsi
movq 0x70(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x9f52
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r14, %rdi
callq 0x3300
movq %rax, %rbx
leaq 0x6a8b(%rip), %rsi      # 0xd0ca
movl $0x12, %edx
movq %rax, %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
jmp 0x6700
movq 0xb951(%rip), %r14      # 0x11fd0
leaq 0x6a3a(%rip), %rsi      # 0xd0c0
movl $0x9, %edx
movq %r14, %rdi
callq 0x3300
leaq -0x48(%rbp), %r15
movq %r13, (%r15)
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x9f52
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r14, %rdi
callq 0x3300
movq %rax, %rbx
leaq 0x69fe(%rip), %rsi      # 0xd0ca
movl $0x12, %edx
movq %rax, %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
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x6715
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6737
jmp 0x6737
jmp 0x6737
jmp 0x6737
jmp 0x6737
jmp 0x6737
jmp 0x6737
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x674f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x3530
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
jne 0x6743
jmp 0x674f
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
jne 0x6743
jmp 0x674f