// File: yuroitaki[P]enigma_machine/main.cpp
// Function: main
int main(int argc, char** argv){

  try{
    
  /*Construct the components of enigma and store the configuration info in each component after file checks */
    Enigma enigma_machine(argc,argv);

  /*Pass in the message from input for encryption/decryption and print the result on the output stream */
    enigma_machine.run();
  }

  catch(int err_code){
    switch(err_code){
    case INSUFFICIENT_NUMBER_OF_PARAMETERS:
      cerr <<  "usage: enigma plugboard-file reflector-file (<rotor-file>* rotor-positions)?" << endl;
      return 1;
    case INVALID_INPUT_CHARACTER:
      cerr << " is not a valid input character (input characters must be upper case letters A-Z)!" << endl;
      return 2;
    case INVALID_INDEX:
      return 3;
    case NON_NUMERIC_CHARACTER:
      return 4;
    case IMPOSSIBLE_PLUGBOARD_CONFIGURATION:
      return 5;
    case INCORRECT_NUMBER_OF_PLUGBOARD_PARAMETERS:
      cerr << " number of parameters in plugboard file: plugboard.pb"<<endl;
      return 6;
    case INVALID_ROTOR_MAPPING:
      return 7;
    case NO_ROTOR_STARTING_POSITION:
      cerr << " in rotor position file: rotor.pos" << endl;
      return 8;
    case INVALID_REFLECTOR_MAPPING:
      return 9;
    case INCORRECT_NUMBER_OF_REFLECTOR_PARAMETERS:
      cerr << " number of parameters in reflector file: reflector.rf" <<endl;
      return 10;
    case ERROR_OPENING_CONFIGURATION_FILE:
      cerr << " cannot be opened correctly or it's empty (null or contains only white space character)" << endl;
      return 11;
    default: cerr << "Unknown error" << endl;     
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x2750
jmp 0x247b
leaq -0x38(%rbp), %rdi
callq 0x2c20
jmp 0x2486
leaq -0x38(%rbp), %rdi
callq 0x2970
jmp 0x2732
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x24b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2970
movl -0x44(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2745
movq -0x40(%rbp), %rdi
callq 0x20a0
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x58(%rbp)
subl $0xa, %eax
ja 0x26e6
movq -0x58(%rbp), %rax
leaq 0x5b10(%rip), %rcx      # 0x8004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x9aec(%rip), %rdi      # 0xbff0
leaq 0x5b25(%rip), %rsi      # 0x8030
callq 0x2110
movq %rax, -0x60(%rbp)
jmp 0x2516
movq -0x60(%rbp), %rdi
movq 0x9a8f(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x2528
movl $0x1, -0x4(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2720
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
callq 0x21c0
jmp 0x2745
movq 0x9a98(%rip), %rdi      # 0xbff0
leaq 0x5b1e(%rip), %rsi      # 0x807d
callq 0x2110
movq %rax, -0x68(%rbp)
jmp 0x256a
movq -0x68(%rbp), %rdi
movq 0x9a3b(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x257c
movl $0x2, -0x4(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2720
movl $0x3, -0x4(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2720
movl $0x4, -0x4(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2720
movl $0x5, -0x4(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2720
movq 0x9a21(%rip), %rdi      # 0xbff0
leaq 0x5afa(%rip), %rsi      # 0x80d0
callq 0x2110
movq %rax, -0x70(%rbp)
jmp 0x25e1
movq -0x70(%rbp), %rdi
movq 0x99c4(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x25f3
movl $0x6, -0x4(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2720
movl $0x7, -0x4(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2720
movq 0x99d0(%rip), %rdi      # 0xbff0
leaq 0x5e8d(%rip), %rsi      # 0x84b4
callq 0x2110
movq %rax, -0x78(%rbp)
jmp 0x2632
movq -0x78(%rbp), %rdi
movq 0x9973(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x2644
movl $0x8, -0x4(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2720
movl $0x9, -0x4(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2720
movq 0x997f(%rip), %rdi      # 0xbff0
leaq 0x5a8e(%rip), %rsi      # 0x8106
callq 0x2110
movq %rax, -0x80(%rbp)
jmp 0x2683
movq -0x80(%rbp), %rdi
movq 0x9922(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x2695
movl $0xa, -0x4(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2720
movq 0x9944(%rip), %rdi      # 0xbff0
leaq 0x5a89(%rip), %rsi      # 0x813c
callq 0x2110
movq %rax, -0x88(%rbp)
jmp 0x26c1
movq -0x88(%rbp), %rdi
movq 0x98e1(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x26d6
movl $0xb, -0x4(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2720
movq 0x9903(%rip), %rdi      # 0xbff0
leaq 0x5aa0(%rip), %rsi      # 0x8194
callq 0x2110
movq %rax, -0x90(%rbp)
jmp 0x2702
movq -0x90(%rbp), %rdi
movq 0x98a0(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x2717
jmp 0x2719
movl $0x0, -0x4c(%rbp)
callq 0x21c0
movl -0x4c(%rbp), %eax
testl %eax, %eax
je 0x2730
jmp 0x272e
jmp 0x2739
jmp 0x2732
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x21f0
nop