// File: /workspace/github_cpp_makefile_star2_O1/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 0x9f9e
leaq 0x6f42(%rip), %rsi      # 0xd089
movq %r14, %rdi
callq 0x30b0
movl %eax, %r13d
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x6166
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
testl %r13d, %r13d
je 0x61b3
movq %r15, (%r14)
movq 0x48(%rbx), %rsi
movq 0x50(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f9e
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 0x61a9
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
cmpl $-0x1, %r13d
je 0x6321
leaq -0x38(%rbp), %r13
movq %r13, (%r14)
movq 0x68(%rbx), %rsi
movq 0x70(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f9e
leaq 0x6ede(%rip), %rsi      # 0xd0b2
movq %r14, %rdi
callq 0x30b0
movl %eax, %r12d
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x61f3
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
testl %r12d, %r12d
je 0x640c
movq %r13, (%r14)
movq 0x88(%rbx), %rsi
movq 0x90(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f9e
leaq 0x6e45(%rip), %rsi      # 0xd064
movq %r14, %rdi
callq 0x30b0
movl %eax, %r12d
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x623e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
testl %r12d, %r12d
je 0x63b9
movq %r13, (%r14)
movq 0x68(%rbx), %rsi
movq 0x70(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f9e
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 0x6290
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
cmpl $-0x1, %r12d
jne 0x640c
movq 0xbd2f(%rip), %r14      # 0x11fd0
leaq 0x6e18(%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 0x9f9e
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r14, %rdi
callq 0x3300
movq %rax, %rbx
leaq 0x6de2(%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 0x66f7
movq 0xbca8(%rip), %r14      # 0x11fd0
leaq 0x6d37(%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 0x9f9e
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r14, %rdi
callq 0x3300
movq %rax, %rbx
leaq 0x6d23(%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 0x6700
jmp 0x670c
movq %r13, (%r14)
movq 0x68(%rbx), %rsi
movq 0x70(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f9e
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 0x6402
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
cmpl $-0x1, %r12d
je 0x65e8
movq %r13, (%r14)
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f9e
leaq 0x6cae(%rip), %rsi      # 0xd0dd
movq %r14, %rdi
callq 0x30b0
movl %eax, %r15d
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x644e
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
testl %r15d, %r15d
je 0x65e1
movq %r13, (%r14)
movq 0xc8(%rbx), %rsi
movq 0xd0(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f9e
leaq 0x6be5(%rip), %rsi      # 0xd05f
movq %r14, %rdi
callq 0x30b0
movl %eax, %r15d
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x6499
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
testl %r15d, %r15d
je 0x6588
movq %r13, (%r14)
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f9e
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 0x64f1
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
cmpl $-0x1, %r15d
jne 0x65e1
movq 0xbace(%rip), %r14      # 0x11fd0
leaq 0x6bb7(%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 0x9f9e
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r14, %rdi
callq 0x3300
movq %rax, %rbx
leaq 0x6b7b(%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 0x66f7
movq %r13, (%r14)
movq 0xa8(%rbx), %rsi
movq 0xb0(%rbx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x9f9e
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 0x65d7
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
cmpl $-0x1, %r15d
je 0x666f
xorl %eax, %eax
jmp 0x6711
movq 0xb9e1(%rip), %r14      # 0x11fd0
leaq 0x6aca(%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 0x9f9e
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r14, %rdi
callq 0x3300
movq %rax, %rbx
leaq 0x6a94(%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 0x66f7
movq 0xb95a(%rip), %r14      # 0x11fd0
leaq 0x6a43(%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 0x9f9e
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %r14, %rdi
callq 0x3300
movq %rax, %rbx
leaq 0x6a07(%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 0x670c
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 0x672e
jmp 0x672e
jmp 0x672e
jmp 0x672e
jmp 0x672e
jmp 0x672e
jmp 0x672e
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x6746
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x32c0
movq %rbx, %rdi
callq 0x3530
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
jne 0x673a
jmp 0x6746
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
jne 0x673a
jmp 0x6746