// File: /workspace/github_cpp_makefile_star2_O1/bowenfan96[P]icl-mcs-enigma/enigma.cpp
// Function: Enigma::Reflector::Reflector(char const*)
Enigma::Reflector::Reflector(const char* rf_filename) 
{
    std::ifstream rf_file;
    rf_file.open(rf_filename);
    
    if(rf_file.is_open()) {
        
        std::string index;
        int rf_num;
        int i = 0;
        size_t sz;
        
        while(std::getline(rf_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)) {
                        rf_num = std::stoi(index, &sz);
                        if(i % 2 == 0) {
                            map_from.push_back(rf_num);
                        }
                        else {
                            map_to.push_back(rf_num);
                        }
                        i++;
                    }
                    else {
                        std::cerr << "Index in reflector file " << rf_filename << " does not correspond to an alphabet letter" << "\n";
                        throw INVALID_INDEX;
                    }
                }
                else {
                    std::cerr << "Non-numeric character in reflector file " << rf_filename << "\n";
                    throw NON_NUMERIC_CHARACTER;
                }
            }
        }
        
        // check reflector is not empty or contain only 1 parameter
        if(map_from.size() == 0 || map_to.size() == 0) {
            std::cerr << "Insufficient number of mappings in reflector file: " << rf_filename << "\n";
            throw INCORRECT_NUMBER_OF_REFLECTOR_PARAMETERS;
        }
        
        // check correct config (1 to 1 mapping, no value to itself)
        if(!is_one_to_one(map_from, map_to)) {
            std::cerr << "Malformed contact points (not linked 1 to 1) in reflector file " << rf_filename << "\n";
            throw INVALID_REFLECTOR_MAPPING;
        }
        
        // check exactly 13 pairings
        if(map_from.size() != map_to.size()) {
            std::cerr << "Incorrect (odd) number of parameters in reflector file " << rf_filename << "\n";
            throw INCORRECT_NUMBER_OF_REFLECTOR_PARAMETERS;
        }
            
        if(map_from.size() < 13 || map_to.size() < 13) {
            std::cerr << "Insufficient number of mappings in reflector file: " << rf_filename << "\n";
            throw INCORRECT_NUMBER_OF_REFLECTOR_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 << "Reflector file " << rf_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, %r13
movq %rdi, %r14
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 %r14, -0x48(%rbp)
callq 0x21c0
leaq -0x2a0(%rbp), %rdi
movq %r13, %rsi
movl $0x8, %edx
callq 0x2100
leaq -0x228(%rbp), %rdi
callq 0x2050
testb %al, %al
je 0x3a11
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x20(%r14), %rax
movq %rax, -0x98(%rbp)
leaq 0x8(%r14), %rax
movq %rax, -0x90(%rbp)
movl $0x0, -0x2c(%rbp)
movq %r13, -0x38(%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 0x38df
movq -0x70(%rbp), %rbx
movq -0x68(%rbp), %r13
leaq (%rbx,%r13), %r14
movq %r13, %r12
sarq $0x2, %r12
testq %r12, %r12
jle 0x3743
andq $-0x4, %r13
addq %rbx, %r13
incq %r12
addq $0x3, %rbx
movq %rbx, %r15
movsbl -0x3(%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x378f
movsbl -0x2(%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x3795
movsbl -0x1(%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x379b
movsbl (%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x379e
decq %r12
addq $0x4, %r15
cmpq $0x1, %r12
jg 0x36f8
movq %r13, %rbx
movq %r14, %rax
subq %rbx, %rax
cmpq $0x1, %rax
je 0x377c
cmpq $0x2, %rax
je 0x376d
movq %r14, %r15
cmpq $0x3, %rax
jne 0x379e
movsbl (%rbx), %edi
callq 0x2040
testl %eax, %eax
jne 0x378a
incq %rbx
movsbl (%rbx), %edi
callq 0x2040
testl %eax, %eax
jne 0x378a
incq %rbx
movsbl (%rbx), %edi
callq 0x2040
testl %eax, %eax
cmoveq %r14, %rbx
movq %rbx, %r15
jmp 0x379e
addq $-0x3, %r15
jmp 0x379e
addq $-0x2, %r15
jmp 0x379e
decq %r15
cmpq %r14, %r15
sete %al
leaq 0x1(%r15), %rbx
cmpq %r14, %rbx
sete %cl
orb %al, %cl
jne 0x37d0
movb (%rbx), %r12b
movsbl %r12b, %edi
callq 0x2040
testl %eax, %eax
jne 0x37c8
movb %r12b, (%r15)
incq %r15
incq %rbx
cmpq %r14, %rbx
jne 0x37b2
movq %r15, %rax
subq -0x70(%rbp), %rax
movq %rax, -0x68(%rbp)
movb $0x0, (%r15)
movq -0x68(%rbp), %rax
testq %rax, %rax
movq -0x48(%rbp), %r14
je 0x36a8
movq -0x70(%rbp), %rcx
movsbl (%rcx), %edx
addl $-0x30, %edx
cmpl $0x9, %edx
ja 0x39cb
movl $0x1, %esi
cmpq %rsi, %rax
je 0x3828
movq %rsi, %rdx
movsbl (%rcx,%rsi), %edi
addl $-0x30, %edi
incq %rsi
cmpl $0xa, %edi
jb 0x3808
cmpq %rdx, %rax
jne 0x39cb
leaq -0x70(%rbp), %rdi
callq 0x2b7e
testb %al, %al
je 0x3b2c
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 0x3b86
movslq %eax, %rcx
cmpq %rax, %rcx
movq -0x48(%rbp), %r14
jne 0x3b92
movl (%r15), %ecx
cmpl $0x22, %ecx
je 0x3b92
testl %ecx, %ecx
jne 0x3891
movl %ebx, (%r15)
movl %eax, -0x4c(%rbp)
testb $0x1, -0x2c(%rbp)
jne 0x38b9
movq 0x8(%r14), %rsi
movq %r14, %rdi
movq -0x90(%rbp), %rcx
cmpq 0x10(%r14), %rsi
je 0x38ce
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, (%rcx)
jmp 0x38d7
movq 0x20(%r14), %rsi
movq -0x40(%rbp), %rdi
movq -0x98(%rbp), %rcx
cmpq 0x28(%r14), %rsi
jne 0x38ae
leaq -0x4c(%rbp), %rdx
callq 0x4978
incl -0x2c(%rbp)
jmp 0x36a8
movq 0x8(%r14), %rax
movl $0x33, %r12d
leaq 0x295a(%rip), %r13      # 0x624a
cmpq (%r14), %rax
je 0x3ad4
movq 0x20(%r14), %rax
cmpq 0x18(%r14), %rax
je 0x3ad4
movq %r14, %rdi
movq -0x40(%rbp), %rsi
callq 0x2c0c
testb %al, %al
je 0x3a84
movq 0x8(%r14), %rcx
movq 0x20(%r14), %rax
subq (%r14), %rcx
sarq $0x2, %rcx
subq 0x18(%r14), %rax
sarq $0x2, %rax
cmpq %rax, %rcx
jne 0x3ac7
cmpq $0xd, %rcx
jb 0x3ad4
cmpq $0xd, %rax
jb 0x3ad4
leaq -0x88(%rbp), %rdi
movq %r14, %rsi
callq 0x47d4
movq 0x8(%r14), %rsi
movq 0x18(%r14), %rdx
movq 0x20(%r14), %rcx
movq %r14, %rdi
callq 0x4ab0
movq 0x20(%r14), %rsi
movq -0x88(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq -0x40(%rbp), %rdi
callq 0x4ab0
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x399b
callq 0x2180
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x39ad
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 0x561e(%rip), %rdi      # 0x8ff0
leaq 0x2848(%rip), %rsi      # 0x6221
movl $0x28, %edx
callq 0x21d0
movq 0x5606(%rip), %rdi      # 0x8ff0
movq -0x38(%rbp), %rsi
callq 0x21a0
movl $0x4, %ebx
leaq 0x2665(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
jmp 0x3b0f
movq 0x55d8(%rip), %rdi      # 0x8ff0
leaq 0x28d7(%rip), %rsi      # 0x62f6
movl $0xf, %edx
callq 0x21d0
movq 0x55c0(%rip), %rdi      # 0x8ff0
movq %r13, %rsi
callq 0x21a0
movq %rax, %r15
leaq 0x26cf(%rip), %rsi      # 0x6111
movl $0x1a, %edx
movq %rax, %rdi
callq 0x21d0
leaq 0x260e(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %r15, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl $0xb, (%rax)
movq 0x5536(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
movq 0x5565(%rip), %rdi      # 0x8ff0
leaq 0x27ec(%rip), %rsi      # 0x627e
movl $0x3f, %edx
callq 0x21d0
movq 0x554d(%rip), %rdi      # 0x8ff0
movq -0x38(%rbp), %rsi
callq 0x21a0
movl $0x9, %ebx
leaq 0x25ac(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
jmp 0x3b0f
movl $0x37, %r12d
leaq 0x27ea(%rip), %r13      # 0x62be
movq 0x5515(%rip), %rdi      # 0x8ff0
movq %r13, %rsi
movq %r12, %rdx
callq 0x21d0
movq 0x5503(%rip), %rdi      # 0x8ff0
movq -0x38(%rbp), %rsi
callq 0x21a0
movl $0xa, %ebx
leaq 0x2562(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl %ebx, (%rax)
movq 0x548e(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
movq 0x54bd(%rip), %rdi      # 0x8ff0
leaq 0x26ce(%rip), %rsi      # 0x6208
movl $0x18, %edx
callq 0x21d0
movq 0x54a5(%rip), %rdi      # 0x8ff0
movq -0x38(%rbp), %rsi
callq 0x21a0
movq %rax, %r15
leaq 0x24db(%rip), %rsi      # 0x6039
movl $0x2a, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x3, %ebx
leaq 0x24ed(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %r15, %rdi
callq 0x21d0
jmp 0x3b0f
leaq 0x28b6(%rip), %rdi      # 0x6443
callq 0x20f0
leaq 0x28aa(%rip), %rdi      # 0x6443
callq 0x2220
jmp 0x3ba0
movq %rax, %r12
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0x3bd7
callq 0x2180
jmp 0x3bd7
jmp 0x3bd4
movq %rax, %r12
jmp 0x3bf5
jmp 0x3bd4
movq %rax, %r12
cmpl $0x0, (%r15)
jne 0x3bd7
movl %ebx, (%r15)
jmp 0x3bd7
movq %rax, %r12
jmp 0x3be9
jmp 0x3bd4
movq %rax, %r12
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x3be9
callq 0x2180
leaq -0x2a0(%rbp), %rdi
callq 0x2060
movq -0x40(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x3c06
callq 0x2180
movq -0x48(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x3c17
callq 0x2180
movq %r12, %rdi
callq 0x22b0
nop