// File: yuroitaki[P]enigma_machine/config.cpp
// Function: Config::check_rot_file(char const*, int)
void Config::check_rot_file(const char* rot_file,int rotor_id){
  ifstream input;
  vector<int>buffer1_vec;
  vector<int>buffer2_vec;
  int len1 = 0;
  int len2 = 0;
  int buffer;
  char charac;
  int count = 0;
  
  input.open(rot_file);

  while((count<52)&&(input>>buffer)){

    input.get(charac);
    if(!isspace(charac)){
      cerr << "Non-numeric character in "<< rotor_id+1 << "th rotor file" << endl; 
      throw NON_NUMERIC_CHARACTER;
    }
    if((buffer<0)||(buffer>25)){
      cerr << "Invalid index in "<< rotor_id+1 << "th rotor file" << endl;
      throw INVALID_INDEX;
    }
    if(count < 26){                    //to check if the rotor mapping is valid
      buffer1_vec.push_back(buffer);
      len1 = buffer1_vec.size();
      
      for (int i=0;i<len1-1;i++){
	if(buffer1_vec[i]==buffer1_vec[len1-1]){
	  cerr <<"Invalid mapping of input "<< len1-1 <<" to output "<<buffer1_vec[len1-1]<<  " (output " <<buffer1_vec[len1-1] << " is already mapped to from input " << i <<") in "<< rotor_id+1 << "th rotor file" << endl;
	  throw INVALID_ROTOR_MAPPING;
	}
      }
    }else{                             //to check if the notch position is valid
      buffer2_vec.push_back(buffer);
      len2 = buffer2_vec.size();
      
      for (int i=0;i<len2-1;i++){
	if(buffer2_vec[i]==buffer2_vec[len2-1]){
	  cerr <<"Repeated placing of notch "<< buffer2_vec[len2-1] << " in " << rotor_id+1 << "th rotor file" << endl;
	  throw INVALID_ROTOR_MAPPING;
	}
      }
    }
    count++;
  }
  if((count==52)&&(input>>charac)){
    cerr << "Exceeded maximum number of notches allowed in "<< rotor_id+1 << "th rotor file" << endl;
    throw INVALID_ROTOR_MAPPING;
  }
  if((input.fail())&&(!input.eof())){
    cerr << "Non-numeric character in "<< rotor_id+1 << "th rotor file" << endl;
    throw NON_NUMERIC_CHARACTER;
  }
  if(count<27){
    if(count<26)
      cerr << "Not all inputs mapped in "<< rotor_id+1 << "th rotor file" << endl;
    else
      cerr << "Missing notch position in "<< rotor_id+1 << "th rotor file" << endl;
    throw INVALID_ROTOR_MAPPING;
  }
  input.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3e0, %rsp            # imm = 0x3E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
leaq -0x220(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x2150
leaq -0x238(%rbp), %rdi
callq 0x58b0
leaq -0x250(%rbp), %rdi
callq 0x58b0
movq -0x288(%rbp), %rdi
movl $0x0, -0x254(%rbp)
movl $0x0, -0x258(%rbp)
movl $0x0, -0x264(%rbp)
movq -0x10(%rbp), %rsi
movl $0x8, %edx
callq 0x20e0
jmp 0x4af6
jmp 0x4af8
xorl %eax, %eax
cmpl $0x34, -0x264(%rbp)
movb %al, -0x289(%rbp)
jge 0x4b51
leaq -0x220(%rbp), %rdi
leaq -0x25c(%rbp), %rsi
callq 0x20d0
movq %rax, -0x298(%rbp)
jmp 0x4b25
movq -0x298(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2170
movb %al, -0x299(%rbp)
jmp 0x4b43
movb -0x299(%rbp), %al
movb %al, -0x289(%rbp)
jmp 0x4b51
movb -0x289(%rbp), %al
testb $0x1, %al
jne 0x4b60
jmp 0x50d1
leaq -0x220(%rbp), %rdi
leaq -0x25d(%rbp), %rsi
callq 0x2190
jmp 0x4b75
movsbl -0x25d(%rbp), %edi
callq 0x2040
cmpl $0x0, %eax
jne 0x4c54
movq 0x745f(%rip), %rdi      # 0xbff0
leaq 0x37f6(%rip), %rsi      # 0x838e
callq 0x2110
movq %rax, -0x2a8(%rbp)
jmp 0x4ba6
movq -0x2a8(%rbp), %rdi
movl -0x14(%rbp), %esi
incl %esi
callq 0x21e0
movq %rax, -0x2b0(%rbp)
jmp 0x4bc0
movq -0x2b0(%rbp), %rdi
leaq 0x37da(%rip), %rsi      # 0x83a8
callq 0x2110
movq %rax, -0x2b8(%rbp)
jmp 0x4bdc
movq -0x2b8(%rbp), %rdi
movq 0x73c6(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x4bf1
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x4, (%rdi)
movq 0x7395(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x53f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x270(%rbp)
movl %eax, -0x274(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x30b0
leaq -0x238(%rbp), %rdi
callq 0x30b0
leaq -0x220(%rbp), %rdi
callq 0x2060
jmp 0x53ec
cmpl $0x0, -0x25c(%rbp)
jl 0x4c6a
cmpl $0x19, -0x25c(%rbp)
jle 0x4cf9
movq 0x737f(%rip), %rdi      # 0xbff0
leaq 0x373e(%rip), %rsi      # 0x83b6
callq 0x2110
movq %rax, -0x2c0(%rbp)
jmp 0x4c86
movq -0x2c0(%rbp), %rdi
movl -0x14(%rbp), %esi
incl %esi
callq 0x21e0
movq %rax, -0x2c8(%rbp)
jmp 0x4ca0
movq -0x2c8(%rbp), %rdi
leaq 0x36fa(%rip), %rsi      # 0x83a8
callq 0x2110
movq %rax, -0x2d0(%rbp)
jmp 0x4cbc
movq -0x2d0(%rbp), %rdi
movq 0x72e6(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x4cd1
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x3, (%rdi)
movq 0x72b5(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x53f8
cmpl $0x1a, -0x264(%rbp)
jge 0x4f40
leaq -0x238(%rbp), %rdi
leaq -0x25c(%rbp), %rsi
callq 0x58d0
jmp 0x4d1b
leaq -0x238(%rbp), %rdi
callq 0x5940
movl %eax, -0x254(%rbp)
movl $0x0, -0x278(%rbp)
movl -0x278(%rbp), %eax
movl -0x254(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x4f3b
movslq -0x278(%rbp), %rsi
leaq -0x238(%rbp), %rdi
callq 0x5960
movl (%rax), %eax
movl %eax, -0x2d4(%rbp)
movl -0x254(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq -0x238(%rbp), %rdi
callq 0x5960
movq %rax, %rcx
movl -0x2d4(%rbp), %eax
cmpl (%rcx), %eax
jne 0x4f25
movq 0x7257(%rip), %rdi      # 0xbff0
leaq 0x3628(%rip), %rsi      # 0x83c8
callq 0x2110
movq %rax, -0x2e0(%rbp)
jmp 0x4dae
movq -0x2e0(%rbp), %rdi
movl -0x254(%rbp), %esi
decl %esi
callq 0x21e0
movq %rax, -0x2e8(%rbp)
jmp 0x4dcb
movq -0x2e8(%rbp), %rdi
leaq 0x3609(%rip), %rsi      # 0x83e2
callq 0x2110
movq %rax, -0x2f0(%rbp)
jmp 0x4de7
movl -0x254(%rbp), %eax
decl %eax
movslq %eax, %rsi
leaq -0x238(%rbp), %rdi
callq 0x5960
movq -0x2f0(%rbp), %rdi
movl (%rax), %esi
callq 0x21e0
movq %rax, -0x2f8(%rbp)
jmp 0x4e15
movq -0x2f8(%rbp), %rdi
leaq 0x35cb(%rip), %rsi      # 0x83ee
callq 0x2110
movq %rax, -0x300(%rbp)
jmp 0x4e31
movl -0x254(%rbp), %eax
decl %eax
movslq %eax, %rsi
leaq -0x238(%rbp), %rdi
callq 0x5960
movq -0x300(%rbp), %rdi
movl (%rax), %esi
callq 0x21e0
movq %rax, -0x308(%rbp)
jmp 0x4e5f
movq -0x308(%rbp), %rdi
leaq 0x358b(%rip), %rsi      # 0x83f8
callq 0x2110
movq %rax, -0x310(%rbp)
jmp 0x4e7b
movq -0x310(%rbp), %rdi
movl -0x278(%rbp), %esi
callq 0x21e0
movq %rax, -0x318(%rbp)
jmp 0x4e96
movq -0x318(%rbp), %rdi
leaq 0x3576(%rip), %rsi      # 0x841a
callq 0x2110
movq %rax, -0x320(%rbp)
jmp 0x4eb2
movq -0x320(%rbp), %rdi
movl -0x14(%rbp), %esi
incl %esi
callq 0x21e0
movq %rax, -0x328(%rbp)
jmp 0x4ecc
movq -0x328(%rbp), %rdi
leaq 0x34ce(%rip), %rsi      # 0x83a8
callq 0x2110
movq %rax, -0x330(%rbp)
jmp 0x4ee8
movq -0x330(%rbp), %rdi
movq 0x70ba(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x4efd
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x7, (%rdi)
movq 0x7089(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x53f8
jmp 0x4f27
movl -0x278(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x278(%rbp)
jmp 0x4d37
jmp 0x50bd
leaq -0x250(%rbp), %rdi
leaq -0x25c(%rbp), %rsi
callq 0x58d0
jmp 0x4f55
leaq -0x250(%rbp), %rdi
callq 0x5940
movl %eax, -0x258(%rbp)
movl $0x0, -0x27c(%rbp)
movl -0x27c(%rbp), %eax
movl -0x258(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x50bb
movslq -0x27c(%rbp), %rsi
leaq -0x250(%rbp), %rdi
callq 0x5960
movl (%rax), %eax
movl %eax, -0x334(%rbp)
movl -0x258(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq -0x250(%rbp), %rdi
callq 0x5960
movq %rax, %rcx
movl -0x334(%rbp), %eax
cmpl (%rcx), %eax
jne 0x50a5
movq 0x701d(%rip), %rdi      # 0xbff0
leaq 0x3446(%rip), %rsi      # 0x8420
callq 0x2110
movq %rax, -0x340(%rbp)
jmp 0x4fe8
movl -0x258(%rbp), %eax
decl %eax
movslq %eax, %rsi
leaq -0x250(%rbp), %rdi
callq 0x5960
movq -0x340(%rbp), %rdi
movl (%rax), %esi
callq 0x21e0
movq %rax, -0x348(%rbp)
jmp 0x5016
movq -0x348(%rbp), %rdi
leaq 0x33f7(%rip), %rsi      # 0x841b
callq 0x2110
movq %rax, -0x350(%rbp)
jmp 0x5032
movq -0x350(%rbp), %rdi
movl -0x14(%rbp), %esi
incl %esi
callq 0x21e0
movq %rax, -0x358(%rbp)
jmp 0x504c
movq -0x358(%rbp), %rdi
leaq 0x334e(%rip), %rsi      # 0x83a8
callq 0x2110
movq %rax, -0x360(%rbp)
jmp 0x5068
movq -0x360(%rbp), %rdi
movq 0x6f3a(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x507d
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x7, (%rdi)
movq 0x6f09(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x53f8
jmp 0x50a7
movl -0x27c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x27c(%rbp)
jmp 0x4f71
jmp 0x50bd
movl -0x264(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x264(%rbp)
jmp 0x4af8
cmpl $0x34, -0x264(%rbp)
jne 0x51b6
leaq -0x220(%rbp), %rdi
leaq -0x25d(%rbp), %rsi
callq 0x2180
movq %rax, -0x368(%rbp)
jmp 0x50fa
movq -0x368(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2170
movb %al, -0x369(%rbp)
jmp 0x5118
movb -0x369(%rbp), %al
testb $0x1, %al
jne 0x5127
jmp 0x51b6
movq 0x6ec2(%rip), %rdi      # 0xbff0
leaq 0x3306(%rip), %rsi      # 0x843b
callq 0x2110
movq %rax, -0x378(%rbp)
jmp 0x5143
movq -0x378(%rbp), %rdi
movl -0x14(%rbp), %esi
incl %esi
callq 0x21e0
movq %rax, -0x380(%rbp)
jmp 0x515d
movq -0x380(%rbp), %rdi
leaq 0x323d(%rip), %rsi      # 0x83a8
callq 0x2110
movq %rax, -0x388(%rbp)
jmp 0x5179
movq -0x388(%rbp), %rdi
movq 0x6e29(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x518e
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x7, (%rdi)
movq 0x6df8(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x53f8
movq -0x220(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x220(%rbp,%rax), %rdi
callq 0x2030
movb %al, -0x389(%rbp)
jmp 0x51d6
movb -0x389(%rbp), %al
testb $0x1, %al
jne 0x51e5
jmp 0x52a4
movq -0x220(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x220(%rbp,%rax), %rdi
callq 0x2200
movb %al, -0x38a(%rbp)
jmp 0x5205
movb -0x38a(%rbp), %al
testb $0x1, %al
jne 0x52a4
jmp 0x5215
movq 0x6dd4(%rip), %rdi      # 0xbff0
leaq 0x316b(%rip), %rsi      # 0x838e
callq 0x2110
movq %rax, -0x398(%rbp)
jmp 0x5231
movq -0x398(%rbp), %rdi
movl -0x14(%rbp), %esi
incl %esi
callq 0x21e0
movq %rax, -0x3a0(%rbp)
jmp 0x524b
movq -0x3a0(%rbp), %rdi
leaq 0x314f(%rip), %rsi      # 0x83a8
callq 0x2110
movq %rax, -0x3a8(%rbp)
jmp 0x5267
movq -0x3a8(%rbp), %rdi
movq 0x6d3b(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x527c
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x4, (%rdi)
movq 0x6d0a(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x53f8
cmpl $0x1b, -0x264(%rbp)
jge 0x53b1
cmpl $0x1a, -0x264(%rbp)
jge 0x5323
movq 0x6d2f(%rip), %rdi      # 0xbff0
leaq 0x31a2(%rip), %rsi      # 0x846a
callq 0x2110
movq %rax, -0x3b0(%rbp)
jmp 0x52d6
movq -0x3b0(%rbp), %rdi
movl -0x14(%rbp), %esi
incl %esi
callq 0x21e0
movq %rax, -0x3b8(%rbp)
jmp 0x52f0
movq -0x3b8(%rbp), %rdi
leaq 0x30aa(%rip), %rsi      # 0x83a8
callq 0x2110
movq %rax, -0x3c0(%rbp)
jmp 0x530c
movq -0x3c0(%rbp), %rdi
movq 0x6c96(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x5321
jmp 0x538c
movq 0x6cc6(%rip), %rdi      # 0xbff0
leaq 0x3153(%rip), %rsi      # 0x8484
callq 0x2110
movq %rax, -0x3c8(%rbp)
jmp 0x533f
movq -0x3c8(%rbp), %rdi
movl -0x14(%rbp), %esi
incl %esi
callq 0x21e0
movq %rax, -0x3d0(%rbp)
jmp 0x5359
movq -0x3d0(%rbp), %rdi
leaq 0x3041(%rip), %rsi      # 0x83a8
callq 0x2110
movq %rax, -0x3d8(%rbp)
jmp 0x5375
movq -0x3d8(%rbp), %rdi
movq 0x6c2d(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x538a
jmp 0x538c
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x7, (%rdi)
movq 0x6bfa(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x53f8
leaq -0x220(%rbp), %rdi
callq 0x2050
jmp 0x53bf
leaq -0x250(%rbp), %rdi
callq 0x30b0
leaq -0x238(%rbp), %rdi
callq 0x30b0
leaq -0x220(%rbp), %rdi
callq 0x2060
addq $0x3e0, %rsp            # imm = 0x3E0
popq %rbp
retq
movq -0x270(%rbp), %rdi
callq 0x21f0
nopl (%rax,%rax)