// File: yuroitaki[P]enigma_machine/config.cpp
// Function: Config::check_pb_file()
void Config::check_pb_file(){
  ifstream input;
  vector<int>buffer_vec;
  int len = 0;
  int buffer;
  char charac;
  int count = 0;
  input.open(plugboard_file);

  while((count<26)&&(input>>buffer)){           
   
    input.get(charac);
    if(!isspace(charac)){                 //check if the next character is a white space char or not
      cerr << "Non-numeric character in plugboard file: plugboard.pb" <<endl;
      throw NON_NUMERIC_CHARACTER;
    } 
    if((buffer<0)||(buffer>25)){
      cerr << "Invalid index in plugboard file: plugboard.pb" <<endl;
      throw INVALID_INDEX;
    }
    buffer_vec.push_back(buffer);      //store the config value in a vector for mapping check
    len = buffer_vec.size();
    
    for (int i=0;i<len-1;i++){
      if(buffer_vec[i]==buffer_vec[len-1]){
	if((i%2==0)&&(len-1-i==1))
	  cerr <<"Invalid connection of plugboard contact "<< buffer_vec[i] << " as it is being connected to itself" << endl;
	else
	  cerr << "Invalid connection of plugboard contact "<< buffer_vec[i] << " as it is being connected to more than one other contact" <<endl;
	throw IMPOSSIBLE_PLUGBOARD_CONFIGURATION;
      }
    }count++;
  }
  if((count==26)&&(input>>charac)){            
    cerr << "Exceeded the maximum";
    throw INCORRECT_NUMBER_OF_PLUGBOARD_PARAMETERS;
  }
  if((input.fail())&&(!input.eof())){            
    cerr << "Non-numeric character in plugboard file: plugboard.pb" <<endl;
    throw NON_NUMERIC_CHARACTER;
  }
  if(count%2!=0){
    cerr << "Incorrect";
    throw INCORRECT_NUMBER_OF_PLUGBOARD_PARAMETERS;
  }
  input.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x258(%rbp)
leaq -0x210(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x2150
leaq -0x228(%rbp), %rdi
callq 0x58b0
movq -0x258(%rbp), %rax
movq -0x250(%rbp), %rdi
movl $0x0, -0x22c(%rbp)
movl $0x0, -0x238(%rbp)
movq 0x18(%rax), %rsi
movl $0x8, %edx
callq 0x20e0
jmp 0x3f4b
jmp 0x3f4d
xorl %eax, %eax
cmpl $0x1a, -0x238(%rbp)
movb %al, -0x259(%rbp)
jge 0x3fa6
leaq -0x210(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x20d0
movq %rax, -0x268(%rbp)
jmp 0x3f7a
movq -0x268(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2170
movb %al, -0x269(%rbp)
jmp 0x3f98
movb -0x269(%rbp), %al
movb %al, -0x259(%rbp)
jmp 0x3fa6
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x3fb5
jmp 0x42cd
leaq -0x210(%rbp), %rdi
leaq -0x231(%rbp), %rsi
callq 0x2190
jmp 0x3fca
movsbl -0x231(%rbp), %edi
callq 0x2040
cmpl $0x0, %eax
jne 0x4067
movq 0x800a(%rip), %rdi      # 0xbff0
leaq 0x41ee(%rip), %rsi      # 0x81db
callq 0x2110
movq %rax, -0x278(%rbp)
jmp 0x3ffb
movq -0x278(%rbp), %rdi
movq 0x7fa7(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x4010
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x4, (%rdi)
movq 0x7f76(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x4499
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x240(%rbp)
movl %eax, -0x244(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x30b0
leaq -0x210(%rbp), %rdi
callq 0x2060
jmp 0x448d
cmpl $0x0, -0x230(%rbp)
jl 0x4079
cmpl $0x19, -0x230(%rbp)
jle 0x40d2
movq 0x7f70(%rip), %rdi      # 0xbff0
leaq 0x418a(%rip), %rsi      # 0x8211
callq 0x2110
movq %rax, -0x280(%rbp)
jmp 0x4095
movq -0x280(%rbp), %rdi
movq 0x7f0d(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x40aa
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x3, (%rdi)
movq 0x7edc(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x4499
leaq -0x228(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x58d0
jmp 0x40e7
leaq -0x228(%rbp), %rdi
callq 0x5940
movl %eax, -0x22c(%rbp)
movl $0x0, -0x248(%rbp)
movl -0x248(%rbp), %eax
movl -0x22c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x42b9
movslq -0x248(%rbp), %rsi
leaq -0x228(%rbp), %rdi
callq 0x5960
movl (%rax), %eax
movl %eax, -0x284(%rbp)
movl -0x22c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq -0x228(%rbp), %rdi
callq 0x5960
movq %rax, %rcx
movl -0x284(%rbp), %eax
cmpl (%rcx), %eax
jne 0x42a3
movl -0x248(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x4202
movl -0x22c(%rbp), %eax
subl $0x1, %eax
subl -0x248(%rbp), %eax
cmpl $0x1, %eax
jne 0x4202
movq 0x7e60(%rip), %rdi      # 0xbff0
leaq 0x40a8(%rip), %rsi      # 0x823f
callq 0x2110
movq %rax, -0x290(%rbp)
jmp 0x41a5
movslq -0x248(%rbp), %rsi
leaq -0x228(%rbp), %rdi
callq 0x5960
movq -0x290(%rbp), %rdi
movl (%rax), %esi
callq 0x21e0
movq %rax, -0x298(%rbp)
jmp 0x41cf
movq -0x298(%rbp), %rdi
leaq 0x408b(%rip), %rsi      # 0x8268
callq 0x2110
movq %rax, -0x2a0(%rbp)
jmp 0x41eb
movq -0x2a0(%rbp), %rdi
movq 0x7db7(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x4200
jmp 0x427b
movq 0x7de7(%rip), %rdi      # 0xbff0
leaq 0x402f(%rip), %rsi      # 0x823f
callq 0x2110
movq %rax, -0x2a8(%rbp)
jmp 0x421e
movslq -0x248(%rbp), %rsi
leaq -0x228(%rbp), %rdi
callq 0x5960
movq -0x2a8(%rbp), %rdi
movl (%rax), %esi
callq 0x21e0
movq %rax, -0x2b0(%rbp)
jmp 0x4248
movq -0x2b0(%rbp), %rdi
leaq 0x4036(%rip), %rsi      # 0x828c
callq 0x2110
movq %rax, -0x2b8(%rbp)
jmp 0x4264
movq -0x2b8(%rbp), %rdi
movq 0x7d3e(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x4279
jmp 0x427b
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x5, (%rdi)
movq 0x7d0b(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x4499
jmp 0x42a5
movl -0x248(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x248(%rbp)
jmp 0x4103
movl -0x238(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x238(%rbp)
jmp 0x3f4d
cmpl $0x1a, -0x238(%rbp)
jne 0x435d
leaq -0x210(%rbp), %rdi
leaq -0x231(%rbp), %rsi
callq 0x2180
movq %rax, -0x2c0(%rbp)
jmp 0x42f6
movq -0x2c0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2170
movb %al, -0x2c1(%rbp)
jmp 0x4314
movb -0x2c1(%rbp), %al
testb $0x1, %al
jne 0x4320
jmp 0x435d
movq 0x7cc9(%rip), %rdi      # 0xbff0
leaq 0x3f97(%rip), %rsi      # 0x82c5
callq 0x2110
jmp 0x4335
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x6, (%rdi)
movq 0x7c51(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x4499
movq -0x210(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x210(%rbp,%rax), %rdi
callq 0x2030
movb %al, -0x2c2(%rbp)
jmp 0x437d
movb -0x2c2(%rbp), %al
testb $0x1, %al
jne 0x438c
jmp 0x4411
movq -0x210(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x210(%rbp,%rax), %rdi
callq 0x2200
movb %al, -0x2c3(%rbp)
jmp 0x43ac
movb -0x2c3(%rbp), %al
testb $0x1, %al
jne 0x4411
jmp 0x43b8
movq 0x7c31(%rip), %rdi      # 0xbff0
leaq 0x3e15(%rip), %rsi      # 0x81db
callq 0x2110
movq %rax, -0x2d0(%rbp)
jmp 0x43d4
movq -0x2d0(%rbp), %rdi
movq 0x7bce(%rip), %rsi      # 0xbfb0
callq 0x2140
jmp 0x43e9
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x4, (%rdi)
movq 0x7b9d(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x4499
movl -0x238(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x445e
movq 0x7bc5(%rip), %rdi      # 0xbff0
leaq 0x3ea8(%rip), %rsi      # 0x82da
callq 0x2110
jmp 0x4439
movl $0x4, %edi
callq 0x20b0
movq %rax, %rdi
movl $0x6, (%rdi)
movq 0x7b4d(%rip), %rsi      # 0xbfa0
xorl %eax, %eax
movl %eax, %edx
callq 0x21d0
jmp 0x4499
leaq -0x210(%rbp), %rdi
callq 0x2050
jmp 0x446c
leaq -0x228(%rbp), %rdi
callq 0x30b0
leaq -0x210(%rbp), %rdi
callq 0x2060
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
movq -0x240(%rbp), %rdi
callq 0x21f0
nopl (%rax)