// File: /workspace/github_cpp_makefile_star2_O1/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, -0x40(%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 0x2983
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x20(%r13), %rax
movq %rax, -0x90(%rbp)
leaq 0x8(%r13), %rax
movq %rax, -0x88(%rbp)
movl $0x0, -0x34(%rbp)
movq %r12, -0x98(%rbp)
leaq -0x2a0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movl $0x20, %edx
callq 0x22c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x283b
movq -0x68(%rbp), %rbx
movq -0x60(%rbp), %r13
leaq (%rbx,%r13), %r14
movq %r13, %r12
sarq $0x2, %r12
testq %r12, %r12
jle 0x269e
andq $-0x4, %r13
addq %rbx, %r13
incq %r12
addq $0x3, %rbx
movq %rbx, %r15
movsbl -0x3(%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x26ee
movsbl -0x2(%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x26f4
movsbl -0x1(%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x26fa
movsbl (%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x26fd
decq %r12
addq $0x4, %r15
cmpq $0x1, %r12
jg 0x264f
movq %r13, %rbx
movq %r14, %rax
subq %rbx, %rax
cmpq $0x1, %rax
movq -0x30(%rbp), %r13
je 0x26db
cmpq $0x2, %rax
je 0x26cc
movq %r14, %r15
cmpq $0x3, %rax
jne 0x2701
movsbl (%rbx), %edi
callq 0x2040
testl %eax, %eax
jne 0x26e9
incq %rbx
movsbl (%rbx), %edi
callq 0x2040
testl %eax, %eax
jne 0x26e9
incq %rbx
movsbl (%rbx), %edi
callq 0x2040
testl %eax, %eax
cmoveq %r14, %rbx
movq %rbx, %r15
jmp 0x2701
addq $-0x3, %r15
jmp 0x26fd
addq $-0x2, %r15
jmp 0x26fd
decq %r15
movq -0x30(%rbp), %r13
cmpq %r14, %r15
sete %al
leaq 0x1(%r15), %rbx
cmpq %r14, %rbx
sete %cl
orb %al, %cl
jne 0x2733
movb (%rbx), %r12b
movsbl %r12b, %edi
callq 0x2040
testl %eax, %eax
jne 0x272b
movb %r12b, (%r15)
incq %r15
incq %rbx
cmpq %r14, %rbx
jne 0x2715
movq %r15, %rax
subq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
movb $0x0, (%r15)
movq -0x60(%rbp), %rax
testq %rax, %rax
movq -0x98(%rbp), %r12
je 0x25ff
movq -0x68(%rbp), %rcx
movsbl (%rcx), %edx
addl $-0x30, %edx
cmpl $0x9, %edx
ja 0x293e
movl $0x1, %esi
cmpq %rsi, %rax
je 0x278e
movq %rsi, %rdx
movsbl (%rcx,%rsi), %edi
addl $-0x30, %edi
incq %rsi
cmpl $0xa, %edi
jb 0x276e
cmpq %rdx, %rax
jne 0x293e
leaq -0x68(%rbp), %rdi
callq 0x2b7e
testb %al, %al
je 0x29f6
movq -0x68(%rbp), %r15
callq 0x2030
movq %rax, %r14
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r15, %rdi
leaq -0x80(%rbp), %rsi
movl $0xa, %edx
callq 0x2210
cmpq %r15, -0x80(%rbp)
je 0x2a4f
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x2a5b
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x2a5b
testl %ecx, %ecx
jne 0x27ed
movl %ebx, (%r14)
movl %eax, -0x44(%rbp)
testb $0x1, -0x34(%rbp)
jne 0x2815
movq 0x8(%r13), %rsi
movq %r13, %rdi
movq -0x88(%rbp), %rcx
cmpq 0x10(%r13), %rsi
je 0x282a
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, (%rcx)
jmp 0x2833
movq 0x20(%r13), %rsi
movq -0x40(%rbp), %rdi
movq -0x90(%rbp), %rcx
cmpq 0x28(%r13), %rsi
jne 0x280a
leaq -0x44(%rbp), %rdx
callq 0x4978
incl -0x34(%rbp)
jmp 0x25ff
movq 0x8(%r13), %rax
cmpq (%r13), %rax
je 0x2867
movq 0x20(%r13), %rax
cmpq 0x18(%r13), %rax
je 0x28f9
movq %r13, %rdi
movq -0x40(%rbp), %rsi
callq 0x2c0c
testb %al, %al
je 0x2a67
movq 0x8(%r13), %rax
subq (%r13), %rax
cmpq $0x34, %rax
ja 0x28f9
movq 0x20(%r13), %rcx
subq 0x18(%r13), %rcx
cmpq %rcx, %rax
jne 0x28f9
leaq -0x80(%rbp), %rdi
movq %r13, %rsi
callq 0x47d4
movq 0x8(%r13), %rsi
movq 0x18(%r13), %rdx
movq 0x20(%r13), %rcx
movq %r13, %rdi
callq 0x4ab0
movq 0x20(%r13), %rsi
movq -0x80(%rbp), %rdx
movq -0x78(%rbp), %rcx
movq -0x40(%rbp), %rdi
callq 0x4ab0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x28c9
callq 0x2180
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x28db
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 0x66f0(%rip), %rdi      # 0x8ff0
leaq 0x3788(%rip), %rsi      # 0x608f
movl $0x31, %edx
callq 0x21d0
movq 0x66d8(%rip), %rdi      # 0x8ff0
movq %r12, %rsi
callq 0x21a0
movl $0x6, %ebx
leaq 0x3738(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
jmp 0x2aa7
movq 0x66ab(%rip), %rdi      # 0x8ff0
leaq 0x371a(%rip), %rsi      # 0x6066
movl $0x28, %edx
callq 0x21d0
movq 0x6693(%rip), %rdi      # 0x8ff0
movq %r12, %rsi
callq 0x21a0
movl $0x4, %ebx
leaq 0x36f3(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
jmp 0x2aa7
movq 0x6666(%rip), %rdi      # 0x8ff0
leaq 0x3770(%rip), %rsi      # 0x6101
movl $0xf, %edx
callq 0x21d0
movq 0x664e(%rip), %rdi      # 0x8ff0
movq %r12, %rsi
callq 0x21a0
movq %rax, %r14
leaq 0x375d(%rip), %rsi      # 0x6111
movl $0x1a, %edx
movq %rax, %rdi
callq 0x21d0
leaq 0x369c(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %r14, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl $0xb, (%rax)
movq 0x65c4(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
movq 0x65f3(%rip), %rdi      # 0x8ff0
leaq 0x361c(%rip), %rsi      # 0x6020
movl $0x18, %edx
callq 0x21d0
movq 0x65db(%rip), %rdi      # 0x8ff0
movq %r12, %rsi
callq 0x21a0
movq %rax, %r14
leaq 0x3612(%rip), %rsi      # 0x6039
movl $0x2a, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x3, %ebx
leaq 0x3624(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %r14, %rdi
callq 0x21d0
jmp 0x2aa7
leaq 0x39ed(%rip), %rdi      # 0x6443
callq 0x20f0
leaq 0x39e1(%rip), %rdi      # 0x6443
callq 0x2220
movq 0x6582(%rip), %rdi      # 0x8ff0
leaq 0x364c(%rip), %rsi      # 0x60c1
movl $0x3f, %edx
callq 0x21d0
movq 0x656a(%rip), %rdi      # 0x8ff0
movq %r12, %rsi
callq 0x21a0
movl $0x5, %ebx
leaq 0x35ca(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl %ebx, (%rax)
movq 0x64f6(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
jmp 0x2ac6
movq %rax, %r15
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x2afa
callq 0x2180
jmp 0x2afa
jmp 0x2af7
movq %rax, %r15
jmp 0x2b18
jmp 0x2af7
movq %rax, %r15
cmpl $0x0, (%r14)
jne 0x2afa
movl %ebx, (%r14)
jmp 0x2afa
movq %rax, %r15
jmp 0x2b0c
jmp 0x2af7
movq %rax, %r15
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x2b0c
callq 0x2180
leaq -0x2a0(%rbp), %rdi
callq 0x2060
movq -0x40(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2b29
callq 0x2180
movq -0x30(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2b3a
callq 0x2180
movq %r15, %rdi
callq 0x22b0