// File: /workspace/github_cpp_makefile_star2_O2/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, %r13
andl $0x0, (%rsi)
movq %rdi, %r14
movq %rdx, -0x58(%rbp)
movl $0x1, (%rdx)
movq %rcx, -0x50(%rbp)
movl $0x2, (%rcx)
leaq 0x48(%rdi), %r12
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3380
leaq 0x520c(%rip), %rsi      # 0xa089
movq %rbx, %rdi
callq 0x77f5
movl %eax, %r15d
movq %rbx, %rdi
callq 0x3120
testb %r15b, %r15b
je 0x4ec4
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3380
movq (%rbx), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x31d0
movl %eax, %ebx
movl %eax, (%r13)
leaq -0x48(%rbp), %rdi
callq 0x3120
cmpl $-0x1, %ebx
je 0x50d5
leaq 0x68(%r14), %r12
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3380
leaq 0x51d4(%rip), %rsi      # 0xa0b2
movq %rbx, %rdi
callq 0x77f5
movl %eax, %r15d
movq %rbx, %rdi
callq 0x3120
testb %r15b, %r15b
je 0x4fdc
leaq 0x88(%r14), %rsi
movq %rbx, %rdi
callq 0x3380
leaq 0x5154(%rip), %rsi      # 0xa064
movq %rbx, %rdi
callq 0x7653
movl %eax, %r15d
movq %rbx, %rdi
callq 0x3120
movq %rbx, %rdi
movq %r12, %rsi
testb %r15b, %r15b
je 0x4fa9
callq 0x3380
movq (%rbx), %rdi
movl $0x241, %esi            # imm = 0x241
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x31d0
movl %eax, %ebx
movq -0x58(%rbp), %rax
movl %ebx, (%rax)
leaq -0x48(%rbp), %rdi
callq 0x3120
cmpl $-0x1, %ebx
jne 0x4fdc
movq 0xb064(%rip), %rdi      # 0xffc8
leaq 0x5155(%rip), %rsi      # 0xa0c0
callq 0x3280
movq %rax, %rbx
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x3380
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3250
leaq 0x5136(%rip), %rsi      # 0xa0ca
movq %rax, %rdi
callq 0x3280
movq %rax, %rdi
callq 0x3130
jmp 0x51e7
callq 0x3380
movq (%rbx), %rdi
movl $0x441, %esi            # imm = 0x441
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x31d0
movl %eax, %ebx
movq -0x58(%rbp), %rax
movl %ebx, (%rax)
leaq -0x48(%rbp), %rdi
callq 0x3120
cmpl $-0x1, %ebx
je 0x51a0
leaq 0xa8(%r14), %r15
leaq -0x48(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3380
leaq 0x50e4(%rip), %rsi      # 0xa0dd
movq %rbx, %rdi
callq 0x77f5
movl %eax, %r13d
movq %rbx, %rdi
callq 0x3120
xorl %r12d, %r12d
testb %r13b, %r13b
je 0x51f4
addq $0xc8, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3380
leaq 0x502e(%rip), %rsi      # 0xa05f
movq %rbx, %rdi
callq 0x7653
movl %eax, %r14d
movq %rbx, %rdi
callq 0x3120
movq %rbx, %rdi
movq %r15, %rsi
testb %r14b, %r14b
je 0x5121
callq 0x3380
movq (%rbx), %rdi
xorl %r12d, %r12d
movl $0x241, %esi            # imm = 0x241
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x31d0
movl %eax, %ebx
movq -0x50(%rbp), %rax
movl %ebx, (%rax)
leaq -0x48(%rbp), %rdi
callq 0x3120
cmpl $-0x1, %ebx
jne 0x51f4
movq 0xaf38(%rip), %rdi      # 0xffc8
leaq 0x5029(%rip), %rsi      # 0xa0c0
callq 0x3280
movq %rax, %rbx
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x3380
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3250
leaq 0x500a(%rip), %rsi      # 0xa0ca
movq %rax, %rdi
callq 0x3280
movq %rax, %rdi
callq 0x3130
jmp 0x51e7
movq 0xaeec(%rip), %rdi      # 0xffc8
leaq 0x4f83(%rip), %rsi      # 0xa066
callq 0x3280
movq %rax, %rbx
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x3380
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3250
leaq 0x4f8a(%rip), %rsi      # 0xa096
movq %rax, %rdi
callq 0x3280
movq %rax, %rdi
callq 0x3130
jmp 0x51e7
callq 0x3380
movq (%rbx), %rdi
xorl %r12d, %r12d
movl $0x441, %esi            # imm = 0x441
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x31d0
movl %eax, %ebx
movq -0x50(%rbp), %rax
movl %ebx, (%rax)
leaq -0x48(%rbp), %rdi
callq 0x3120
cmpl $-0x1, %ebx
jne 0x51f4
movq 0xae6a(%rip), %rdi      # 0xffc8
leaq 0x4f5b(%rip), %rsi      # 0xa0c0
callq 0x3280
movq %rax, %rbx
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x3380
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3250
leaq 0x4f3c(%rip), %rsi      # 0xa0ca
movq %rax, %rdi
callq 0x3280
movq %rax, %rdi
callq 0x3130
jmp 0x51e7
movq 0xae21(%rip), %rdi      # 0xffc8
leaq 0x4f12(%rip), %rsi      # 0xa0c0
callq 0x3280
movq %rax, %rbx
leaq -0x48(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x3380
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3250
leaq 0x4ef3(%rip), %rsi      # 0xa0ca
movq %rax, %rdi
callq 0x3280
movq %rax, %rdi
callq 0x3130
leaq -0x48(%rbp), %rdi
callq 0x3120
pushq $-0x1
popq %r12
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5218
jmp 0x5218
jmp 0x5218
jmp 0x5218
jmp 0x5218
jmp 0x5218
jmp 0x5218
jmp 0x5218
jmp 0x5218
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x34b0