// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
movq %rdi, %rbx
leaq 0x18(%rdi), %rax
movq %rax, -0x48(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
leaq -0x298(%rbp), %rdi
callq 0x21d0
leaq -0x298(%rbp), %rdi
pushq $0x8
popq %rdx
movq %r14, %rsi
callq 0x2100
movq %r14, -0x38(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x2050
testb %al, %al
je 0x3150
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl $0x0, -0x3c(%rbp)
leaq -0x298(%rbp), %r13
leaq -0x70(%rbp), %r15
pushq $0x20
popq %r14
movq 0x4fc1(%rip), %r12      # 0x7fa8
pushq $0xa
popq %rax
movl %eax, -0x2c(%rbp)
movq %r13, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x22b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3088
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
addq %rdi, %rsi
movq %r12, %rdx
callq 0x3dce
movq -0x70(%rbp), %rdx
addq -0x68(%rbp), %rdx
movq %r15, %rdi
movq %rax, %rsi
callq 0x2040
cmpq $0x0, -0x68(%rbp)
je 0x2fed
movq %r15, %rdi
callq 0x2888
testb %al, %al
je 0x3214
movq %r15, %rdi
callq 0x28b6
testb %al, %al
je 0x3246
movq %r15, %rdi
leaq -0x90(%rbp), %rsi
pushq $0xa
popq %rdx
callq 0x3a55
movl %eax, -0x4c(%rbp)
testb $0x1, -0x3c(%rbp)
movq -0x48(%rbp), %rdi
cmoveq %rbx, %rdi
leaq -0x4c(%rbp), %rsi
callq 0x3a76
incl -0x3c(%rbp)
jmp 0x2fed
movq 0x8(%rbx), %rax
leaq 0x219b(%rip), %r14      # 0x522e
cmpq (%rbx), %rax
je 0x31e8
movq 0x20(%rbx), %rax
cmpq 0x18(%rbx), %rax
movq -0x48(%rbp), %r15
je 0x31e8
movq %rbx, %rdi
movq %r15, %rsi
callq 0x28d6
testb %al, %al
je 0x31ac
movq 0x8(%rbx), %rax
subq (%rbx), %rax
movq 0x20(%rbx), %rcx
subq 0x18(%rbx), %rcx
cmpq %rcx, %rax
jne 0x31e1
cmpq $0x34, %rax
jb 0x31e8
leaq -0x88(%rbp), %rdi
movq %rbx, %rsi
callq 0x3a9c
movq 0x8(%rbx), %rsi
movq 0x18(%rbx), %rdx
movq 0x20(%rbx), %rcx
movq %rbx, %rdi
callq 0x3af4
movq 0x20(%rbx), %rsi
movq -0x88(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq %r15, %rdi
callq 0x3af4
leaq -0x88(%rbp), %rdi
callq 0x3dba
leaq -0x70(%rbp), %rdi
callq 0x20b0
leaq -0x298(%rbp), %rdi
callq 0x2060
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4e99(%rip), %rdi      # 0x7ff0
leaq 0x217c(%rip), %rsi      # 0x52da
callq 0x21b0
movq -0x38(%rbp), %rsi
movq %rax, %rdi
callq 0x21b0
leaq 0x1f7f(%rip), %rsi      # 0x50f5
movq %rax, %rdi
callq 0x21b0
leaq 0x1ec3(%rip), %rsi      # 0x5048
movq %rax, %rdi
callq 0x21b0
pushq $0x4
popq %rdi
callq 0x20c0
movl $0xb, (%rax)
movq 0x4dfe(%rip), %rsi      # 0x7fa0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2280
movq 0x4e3d(%rip), %rdi      # 0x7ff0
leaq 0x20a8(%rip), %rsi      # 0x5262
callq 0x21b0
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x21b0
leaq 0x1e76(%rip), %rsi      # 0x5048
movq %rax, %rdi
callq 0x21b0
pushq $0x9
jmp 0x3285
leaq 0x20ba(%rip), %r14      # 0x52a2
movq 0x4e01(%rip), %rdi      # 0x7ff0
movq %r14, %rsi
callq 0x21b0
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x21b0
leaq 0x1e3e(%rip), %rsi      # 0x5048
movq %rax, %rdi
callq 0x21b0
jmp 0x3289
movq 0x4dd5(%rip), %rdi      # 0x7ff0
leaq 0x1fe3(%rip), %rsi      # 0x5205
callq 0x21b0
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x21b0
leaq 0x1e0e(%rip), %rsi      # 0x5048
movq %rax, %rdi
callq 0x21b0
pushq $0x4
jmp 0x3285
movq 0x4da3(%rip), %rdi      # 0x7ff0
leaq 0x1f98(%rip), %rsi      # 0x51ec
callq 0x21b0
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x21b0
leaq 0x1db1(%rip), %rsi      # 0x501d
movq %rax, %rdi
callq 0x21b0
leaq 0x1dcd(%rip), %rsi      # 0x5048
movq %rax, %rdi
callq 0x21b0
pushq $0x3
popq %rax
movl %eax, -0x2c(%rbp)
pushq $0x4
popq %rdi
callq 0x20c0
movl -0x2c(%rbp), %ecx
movl %ecx, (%rax)
movq 0x4d03(%rip), %rsi      # 0x7fa0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2280
jmp 0x32a9
movq %rax, %r14
leaq -0x88(%rbp), %rdi
callq 0x3dba
jmp 0x32d1
jmp 0x32ce
movq %rax, %r14
jmp 0x32e6
movq %rax, %r14
jmp 0x32da
jmp 0x32ce
jmp 0x32ce
jmp 0x32ce
jmp 0x32ce
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0x20b0
leaq -0x298(%rbp), %rdi
callq 0x2060
movq -0x48(%rbp), %rdi
callq 0x3dba
movq %rbx, %rdi
callq 0x3dba
movq %r14, %rdi
callq 0x22a0
nop