// File: /workspace/github_cpp_makefile_star2_O3/bowenfan96[P]icl-mcs-enigma/enigma.cpp
// Function: Enigma::Rotor::Rotor(char const*)
Enigma::Rotor::Rotor(const char* rot_filename) 
{
    std::ifstream rot_file;
    rot_file.open(rot_filename);
    
    if(rot_file.is_open()) {
        
        std::string index;
        int rot_num;
        int i = 0;
        size_t sz;
        
        while(std::getline(rot_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)) {
                        rot_num = std::stoi(index, &sz);
                        if(i <= 25) {
                            map_rtl[i] = rot_num;
                            map_ltr[rot_num] = i;
                        }
                        else {
                            triggers.push_back(rot_num);
                        }
                        i++;
                    }
                    else {
                        std::cerr << "Index in rotor file " << rot_filename << " does not correspond to an alphabet letter" << "\n";
                        throw INVALID_INDEX;
                    }
                }
                else {
                    std::cerr << "Non-numeric character for mapping in rotor file " << rot_filename << "\n";
                    throw NON_NUMERIC_CHARACTER;
                }
            }
        }
        
        // check mapping is correct, 26 numbers given in rotor file
        if(i < 26) {
            std::cerr << "Not all inputs mapped in rotor file: " << rot_filename << "\n";
            throw INVALID_ROTOR_MAPPING;
        }
        // check all numbers are unique
        std::unordered_set<int> set;
        
        for(int j=0; j<26; j++) {
            if(!set.insert(map_rtl[j]).second) {
                auto repeat_val = std::find(map_rtl.cbegin(), map_rtl.cend(), map_rtl[j]);
                
                std::cerr << "Invalid mapping of input " << j << " to output " << map_rtl[j] << " (output " << map_rtl[j] << " is already mapped to from input " << std::distance(map_rtl.cbegin(), repeat_val) << ") in rotor file: " << rot_filename << "\n";
                
                throw INVALID_ROTOR_MAPPING;
            }
        }
        
        // set position to 0
        // Enigma constructor will turn the rotors after reading pos file
        position = 0;
        
        // rotor is triggered if it rotates to its notch
        triggered = false;
    }
    
    // check if file open failed
    else {
        std::cerr << "Rotor file " << rot_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 $0x298, %rsp            # imm = 0x298
movq %rsi, %rbx
movq %rdi, %r15
leaq 0xd0(%rdi), %rax
movq %rax, -0x68(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0xd0(%rdi)
movq $0x0, 0xe0(%rdi)
leaq -0x2c0(%rbp), %rdi
callq 0x21c0
leaq -0x2c0(%rbp), %rdi
movq %rbx, -0x38(%rbp)
movq %rbx, %rsi
movl $0x8, %edx
callq 0x2100
leaq -0x248(%rbp), %rdi
callq 0x2050
testb %al, %al
je 0x332a
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x68(%r15), %rax
movq %rax, -0x78(%rbp)
xorl %r13d, %r13d
movq %r15, -0x70(%rbp)
movq %r13, -0x30(%rbp)
leaq -0x2c0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x20, %edx
callq 0x22c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3112
movq -0x60(%rbp), %r12
movq -0x58(%rbp), %rax
leaq (%r12,%rax), %rbx
movq %rax, %r13
sarq $0x2, %r13
movq %r12, %r15
testq %r13, %r13
jle 0x2f7c
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 0x2fbe
movsbl -0x2(%r14), %edi
callq 0x2040
testl %eax, %eax
jne 0x2fc4
movsbl -0x1(%r14), %edi
callq 0x2040
testl %eax, %eax
jne 0x2fca
movsbl (%r14), %edi
callq 0x2040
testl %eax, %eax
jne 0x2fcd
decq %r13
addq $0x4, %r14
cmpq $0x1, %r13
jg 0x2f38
movq %rbx, %rax
subq %r15, %rax
cmpq $0x1, %rax
je 0x2fd3
cmpq $0x2, %rax
movq -0x30(%rbp), %r13
je 0x2fac
cmpq $0x3, %rax
jne 0x3021
movsbl (%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x2fe6
incq %r15
movsbl (%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x2fe6
incq %r15
jmp 0x2fd7
addq $-0x3, %r14
jmp 0x2fcd
addq $-0x2, %r14
jmp 0x2fcd
decq %r14
movq -0x30(%rbp), %r13
jmp 0x2fe9
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 0x3024
movb (%r15), %r12b
movsbl %r12b, %edi
callq 0x2040
testl %eax, %eax
jne 0x3013
movb %r12b, (%r14)
incq %r14
incq %r15
cmpq %rbx, %r15
jne 0x2ffd
movq -0x60(%rbp), %r12
jmp 0x3024
movq %rbx, %r14
movq %r14, %rax
subq %r12, %rax
movq %rax, -0x58(%rbp)
movb $0x0, (%r14)
movq -0x58(%rbp), %rax
testq %rax, %rax
je 0x2ee4
movq -0x60(%rbp), %rcx
xorl %edx, %edx
movsbl (%rcx,%rdx), %esi
addl $-0x30, %esi
cmpl $0xa, %esi
jae 0x32ca
incq %rdx
cmpq %rdx, %rax
jne 0x3045
leaq -0x60(%rbp), %rdi
callq 0x2b96
testb %al, %al
je 0x33e5
movq -0x60(%rbp), %r15
callq 0x2030
movq %rax, %r14
movl (%rax), %r12d
movl $0x0, (%rax)
movq %r15, %rdi
leaq -0xb8(%rbp), %rsi
movl $0xa, %edx
callq 0x2210
cmpq %r15, -0xb8(%rbp)
je 0x3443
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x344f
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x344f
testl %ecx, %ecx
movq -0x70(%rbp), %r15
jne 0x30c7
movl %r12d, (%r14)
movl %eax, -0x3c(%rbp)
cmpl $0x19, %r13d
ja 0x30de
movl %r13d, %ecx
movl %eax, (%r15,%rcx,4)
movl %r13d, 0x68(%r15,%rax,4)
jmp 0x310a
movq 0xd8(%r15), %rsi
cmpq 0xe0(%r15), %rsi
je 0x30fd
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0xd8(%r15)
jmp 0x310a
movq -0x68(%rbp), %rdi
leaq -0x3c(%rbp), %rdx
callq 0x499e
incl %r13d
jmp 0x2ee0
cmpl $0x19, %r13d
jbe 0x339e
leaq -0x88(%rbp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
xorl %r12d, %r12d
leaq -0x80(%rbp), %r14
movq -0x70(%rbp), %r15
movq %r15, %rbx
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x80(%rbp)
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4d50
testb $0x1, %dl
je 0x31c6
decq %r12
addq $0x4, %rbx
cmpq $-0x1a, %r12
jne 0x314f
movl $0x0, 0xe8(%r15)
movb $0x0, 0xec(%r15)
leaq -0xb8(%rbp), %rdi
callq 0x491a
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x31a8
callq 0x2180
leaq -0x2c0(%rbp), %rdi
callq 0x2060
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movq -0x78(%rbp), %rsi
movq %rbx, %rdx
callq 0x5008
movq %rax, %r13
movq 0x5e11(%rip), %rdi      # 0x8ff0
leaq 0x2fb2(%rip), %rsi      # 0x6198
movl $0x19, %edx
callq 0x21d0
negq %r12
movq 0x5df6(%rip), %rdi      # 0x8ff0
movl %r12d, %esi
callq 0x22a0
movq %rax, %r14
leaq 0x2fa6(%rip), %rsi      # 0x61b2
movl $0xb, %edx
movq %rax, %rdi
callq 0x21d0
movl (%rbx), %esi
movq %r14, %rdi
callq 0x22a0
movq %rax, %r14
leaq 0x2f91(%rip), %rsi      # 0x61be
movl $0x9, %edx
movq %rax, %rdi
callq 0x21d0
movl (%rbx), %esi
movq %r14, %rdi
callq 0x22a0
movq %rax, %rbx
leaq 0x2f7a(%rip), %rsi      # 0x61c8
movl $0x21, %edx
movq %rax, %rdi
callq 0x21d0
subq %r15, %r13
sarq $0x2, %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2190
movq %rax, %rbx
leaq 0x2f73(%rip), %rsi      # 0x61ea
movl $0x11, %edx
movq %rax, %rdi
callq 0x21d0
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
callq 0x21a0
leaq 0x2dcd(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl $0x7, (%rax)
movq 0x5cf5(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
jmp 0x339e
movq 0x5d1f(%rip), %rdi      # 0x8ff0
leaq 0x2e69(%rip), %rsi      # 0x6141
movl $0x30, %edx
callq 0x21d0
movq 0x5d07(%rip), %rdi      # 0x8ff0
movq -0x38(%rbp), %rsi
callq 0x21a0
movl $0x4, %r14d
leaq 0x2d65(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl %r14d, (%rax)
movq 0x5c90(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
movq 0x5cbf(%rip), %rdi      # 0x8ff0
leaq 0x2ec4(%rip), %rsi      # 0x61fc
movl $0xb, %edx
callq 0x21d0
movq 0x5ca7(%rip), %rdi      # 0x8ff0
movq -0x38(%rbp), %rsi
callq 0x21a0
movq %rax, %rbx
leaq 0x2db5(%rip), %rsi      # 0x6111
movl $0x1a, %edx
movq %rax, %rdi
callq 0x21d0
leaq 0x2cf4(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rbx, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl $0xb, (%rax)
movq 0x5c1c(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
movq 0x5c4b(%rip), %rdi      # 0x8ff0
leaq 0x2dc6(%rip), %rsi      # 0x6172
movl $0x25, %edx
callq 0x21d0
movq 0x5c33(%rip), %rdi      # 0x8ff0
movq -0x38(%rbp), %rsi
callq 0x21a0
movl $0x7, %r14d
leaq 0x2c91(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
jmp 0x330c
movq 0x5c04(%rip), %rdi      # 0x8ff0
leaq 0x2d39(%rip), %rsi      # 0x612c
movl $0x14, %edx
callq 0x21d0
movq 0x5bec(%rip), %rdi      # 0x8ff0
movq -0x38(%rbp), %rsi
callq 0x21a0
movq %rax, %rbx
leaq 0x2c22(%rip), %rsi      # 0x6039
movl $0x2a, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x3, %r14d
leaq 0x2c33(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rbx, %rdi
callq 0x21d0
jmp 0x330c
leaq 0x2ff9(%rip), %rdi      # 0x6443
callq 0x20f0
leaq 0x2fed(%rip), %rdi      # 0x6443
callq 0x2220
movq %rax, %rbx
jmp 0x34ab
jmp 0x348a
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x348d
movl %r12d, (%r14)
jmp 0x348d
movq %rax, %rbx
jmp 0x349f
jmp 0x3477
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x491a
jmp 0x348d
jmp 0x348a
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x349f
callq 0x2180
leaq -0x2c0(%rbp), %rdi
callq 0x2060
movq -0x68(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x34bc
callq 0x2180
movq %rbx, %rdi
callq 0x22b0