// File: /workspace/github_cpp_makefile_star2_O3/bowenfan96[P]icl-mcs-enigma/enigma.cpp
// Function: Enigma::Plugboard::Plugboard(char const*)
Enigma::Plugboard::Plugboard(const char* pb_filename) 
{
    std::ifstream pb_file;
    pb_file.open(pb_filename);
    
    if(pb_file.is_open()) {
        
        std::string index;
        int pb_num;
        int i = 0;
        size_t sz;
        
        while(std::getline(pb_file, index, ' ')) {
            
            index.erase(std::remove_if(index.begin(), index.end(), ::isspace), index.end());
            
            if(!index.empty()) {
                if(is_numeric(index)) {
                    if(is_valid(index)) {
                        pb_num = std::stoi(index, &sz);
                        if(i % 2 == 0) {
                            map_from.push_back(pb_num);
                        }
                        else {
                            map_to.push_back(pb_num);
                        }
                        i++;
                    }
                    else {
                        std::cerr << "Index in plugboard file " << pb_filename << " does not correspond to an alphabet letter" << "\n";
                        throw INVALID_INDEX;
                    }
                }
                else {
                    std::cerr << "Non-numeric character in plugboard file " << pb_filename << "\n";
                    throw NON_NUMERIC_CHARACTER;
                }
            }
        }
        
        // check correct config (1 to 1 mapping, no value to itself)
        if(map_from.size() != 0) {
            if(map_to.size() == 0) {
                std::cerr << "Incorrect number of parameters in plugboard file " << pb_filename << "\n";
                throw INCORRECT_NUMBER_OF_PLUGBOARD_PARAMETERS;
            }
            if(!is_one_to_one(map_from, map_to)) {
                std::cerr << "Malformed contact points (not linked 1 to 1) in plugboard file " << pb_filename << "\n";
                throw IMPOSSIBLE_PLUGBOARD_CONFIGURATION;
            }
        }
        
        // check odd number of parameters or more than 13 pairings
        if(map_from.size() != map_to.size() || map_from.size() > 13) {
            std::cerr << "Incorrect number of parameters in plugboard file " << pb_filename << "\n";
            throw INCORRECT_NUMBER_OF_PLUGBOARD_PARAMETERS;
        }
        
        // mirror the mapping vectors
        std::vector<int> swap = map_from;
        map_from.insert(map_from.end(), map_to.begin(), map_to.end());
        map_to.insert(map_to.end(), swap.begin(), swap.end());
    }
    
    // check if file open failed
    else {
        std::cerr << "Plugboard file " << pb_filename << " supplied cannot be opened" << "\n";
        throw ERROR_OPENING_CONFIGURATION_FILE;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rsi, %r12
movq %rdi, %r13
leaq 0x18(%rdi), %rax
movq %rax, -0x38(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
leaq -0x2a0(%rbp), %rdi
movq %r13, -0x30(%rbp)
callq 0x21c0
leaq -0x2a0(%rbp), %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x2100
leaq -0x228(%rbp), %rdi
callq 0x2050
testb %al, %al
je 0x29b3
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x20(%r13), %rax
movq %rax, -0x40(%rbp)
leaq 0x8(%r13), %rax
movq %rax, -0x90(%rbp)
movq $0x0, -0x48(%rbp)
movq %r12, -0x98(%rbp)
leaq -0x2a0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x20, %edx
callq 0x22c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2834
movq -0x70(%rbp), %r12
movq -0x68(%rbp), %rax
leaq (%r12,%rax), %rbx
movq %rax, %r13
sarq $0x2, %r13
movq %r12, %r15
testq %r13, %r13
jle 0x2695
andq $-0x4, %rax
movq %rax, %r15
addq %r12, %r15
incq %r13
leaq 0x3(%r12), %r14
movsbl -0x3(%r14), %edi
callq 0x2040
testl %eax, %eax
jne 0x26d7
movsbl -0x2(%r14), %edi
callq 0x2040
testl %eax, %eax
jne 0x26dd
movsbl -0x1(%r14), %edi
callq 0x2040
testl %eax, %eax
jne 0x26e3
movsbl (%r14), %edi
callq 0x2040
testl %eax, %eax
jne 0x26e6
decq %r13
addq $0x4, %r14
cmpq $0x1, %r13
jg 0x2651
movq %rbx, %rax
subq %r15, %rax
cmpq $0x1, %rax
je 0x26ec
cmpq $0x2, %rax
movq -0x30(%rbp), %r13
je 0x26c5
cmpq $0x3, %rax
jne 0x273a
movsbl (%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x26ff
incq %r15
movsbl (%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x26ff
incq %r15
jmp 0x26f0
addq $-0x3, %r14
jmp 0x26e6
addq $-0x2, %r14
jmp 0x26e6
decq %r14
movq -0x30(%rbp), %r13
jmp 0x2702
movq -0x30(%rbp), %r13
movsbl (%r15), %edi
callq 0x2040
testl %eax, %eax
cmoveq %rbx, %r15
movq %r15, %r14
cmpq %rbx, %r14
sete %al
leaq 0x1(%r14), %r15
cmpq %rbx, %r15
sete %cl
orb %al, %cl
jne 0x273d
movb (%r15), %r12b
movsbl %r12b, %edi
callq 0x2040
testl %eax, %eax
jne 0x272c
movb %r12b, (%r14)
incq %r14
incq %r15
cmpq %rbx, %r15
jne 0x2716
movq -0x70(%rbp), %r12
jmp 0x273d
movq %rbx, %r14
movq %r14, %rax
subq %r12, %rax
movq %rax, -0x68(%rbp)
movb $0x0, (%r14)
movq -0x68(%rbp), %rax
testq %rax, %rax
movq -0x98(%rbp), %r12
je 0x25fd
movq -0x70(%rbp), %rcx
xorl %edx, %edx
movsbl (%rcx,%rdx), %esi
addl $-0x30, %esi
cmpl $0xa, %esi
jae 0x2914
incq %rdx
cmpq %rdx, %rax
jne 0x2765
leaq -0x70(%rbp), %rdi
callq 0x2b96
testb %al, %al
je 0x2a26
movq -0x70(%rbp), %r14
callq 0x2030
movq %rax, %r15
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r14, %rdi
leaq -0x88(%rbp), %rsi
movl $0xa, %edx
callq 0x2210
cmpq %r14, -0x88(%rbp)
je 0x2a82
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x2a8e
movl (%r15), %ecx
cmpl $0x22, %ecx
je 0x2a8e
testl %ecx, %ecx
jne 0x27e2
movl %ebx, (%r15)
movl %eax, -0x4c(%rbp)
testb $0x1, -0x48(%rbp)
jne 0x280a
movq 0x8(%r13), %rsi
movq %r13, %rdi
movq -0x90(%rbp), %rcx
cmpq 0x10(%r13), %rsi
je 0x281c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, (%rcx)
jmp 0x2825
movq 0x20(%r13), %rsi
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rcx
cmpq 0x28(%r13), %rsi
jne 0x27ff
leaq -0x4c(%rbp), %rdx
callq 0x499e
movq -0x48(%rbp), %rax
incl %eax
movq %rax, -0x48(%rbp)
jmp 0x25fd
movq 0x8(%r13), %rcx
movq %rcx, %rax
cmpq (%r13), %rcx
je 0x2871
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
je 0x2971
movq %r13, %rdi
movq -0x38(%rbp), %rsi
callq 0x2c24
testb %al, %al
je 0x2a9a
movq (%r13), %rcx
movq 0x8(%r13), %rax
subq %rcx, %rax
cmpq $0x34, %rax
ja 0x2971
movq -0x40(%rbp), %rcx
movq (%rcx), %rcx
movq -0x38(%rbp), %rdx
subq (%rdx), %rcx
cmpq %rcx, %rax
jne 0x2971
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x47e6
movq 0x8(%r13), %rsi
movq 0x18(%r13), %rdx
movq 0x20(%r13), %rcx
movq %r13, %rdi
callq 0x4ad6
movq -0x40(%rbp), %rax
movq (%rax), %rsi
movq -0x88(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq -0x38(%rbp), %rdi
callq 0x4ad6
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x28e4
callq 0x2180
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x28f6
callq 0x2180
leaq -0x2a0(%rbp), %rdi
callq 0x2060
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x66d5(%rip), %rdi      # 0x8ff0
leaq 0x3744(%rip), %rsi      # 0x6066
movl $0x28, %edx
callq 0x21d0
movq 0x66bd(%rip), %rdi      # 0x8ff0
movq %r12, %rsi
callq 0x21a0
movl $0x4, %ebx
leaq 0x371d(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl %ebx, (%rax)
movq 0x6649(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
movq 0x6678(%rip), %rdi      # 0x8ff0
leaq 0x3710(%rip), %rsi      # 0x608f
movl $0x31, %edx
callq 0x21d0
movq 0x6660(%rip), %rdi      # 0x8ff0
movq %r12, %rsi
callq 0x21a0
movl $0x6, %ebx
leaq 0x36c0(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
jmp 0x2954
movq 0x6636(%rip), %rdi      # 0x8ff0
leaq 0x3740(%rip), %rsi      # 0x6101
movl $0xf, %edx
callq 0x21d0
movq 0x661e(%rip), %rdi      # 0x8ff0
movq %r12, %rsi
callq 0x21a0
movq %rax, %r15
leaq 0x372d(%rip), %rsi      # 0x6111
movl $0x1a, %edx
movq %rax, %rdi
callq 0x21d0
leaq 0x366c(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %r15, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl $0xb, (%rax)
movq 0x6594(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
movq 0x65c3(%rip), %rdi      # 0x8ff0
leaq 0x35ec(%rip), %rsi      # 0x6020
movl $0x18, %edx
callq 0x21d0
movq 0x65ab(%rip), %rdi      # 0x8ff0
movq %r12, %rsi
callq 0x21a0
movq %rax, %r15
leaq 0x35e2(%rip), %rsi      # 0x6039
movl $0x2a, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x3, %ebx
leaq 0x35f4(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %r15, %rdi
callq 0x21d0
jmp 0x2954
leaq 0x39ba(%rip), %rdi      # 0x6443
callq 0x20f0
leaq 0x39ae(%rip), %rdi      # 0x6443
callq 0x2220
movq 0x654f(%rip), %rdi      # 0x8ff0
leaq 0x3619(%rip), %rsi      # 0x60c1
movl $0x3f, %edx
callq 0x21d0
movq 0x6537(%rip), %rdi      # 0x8ff0
movq %r12, %rsi
callq 0x21a0
movl $0x5, %ebx
leaq 0x3597(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
jmp 0x2954
jmp 0x2ae1
movq %rax, %r12
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x2b18
callq 0x2180
jmp 0x2b18
jmp 0x2b15
movq %rax, %r12
jmp 0x2b36
jmp 0x2b15
movq %rax, %r12
cmpl $0x0, (%r15)
jne 0x2b18
movl %ebx, (%r15)
jmp 0x2b18
movq %rax, %r12
jmp 0x2b2a
jmp 0x2b15
movq %rax, %r12
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x2b2a
callq 0x2180
leaq -0x2a0(%rbp), %rdi
callq 0x2060
movq -0x38(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2b47
callq 0x2180
movq -0x30(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2b58
callq 0x2180
movq %r12, %rdi
callq 0x22b0