// File: /workspace/github_cpp_makefile_star2_O1/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 $0x288, %rsp            # imm = 0x288
movq %rsi, %rbx
leaq 0xd0(%rdi), %rax
movq %rax, -0x68(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0xd0(%rdi)
movq %rdi, -0x38(%rbp)
movq $0x0, 0xe0(%rdi)
leaq -0x2b0(%rbp), %rdi
callq 0x21c0
leaq -0x2b0(%rbp), %rdi
movq %rbx, -0x30(%rbp)
movq %rbx, %rsi
movl $0x8, %edx
callq 0x2100
leaq -0x238(%rbp), %rdi
callq 0x2050
testb %al, %al
je 0x3324
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %ebx, %ebx
movl %ebx, -0x3c(%rbp)
leaq -0x2b0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x20, %edx
callq 0x22c0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3128
movq -0x60(%rbp), %r13
movq -0x58(%rbp), %r12
leaq (%r12,%r13), %r14
movq %r12, %rbx
sarq $0x2, %rbx
testq %rbx, %rbx
jle 0x2f88
andq $-0x4, %r12
addq %r13, %r12
incq %rbx
addq $0x3, %r13
movq %r13, %r15
movsbl -0x3(%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x2fda
movsbl -0x2(%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x2fe0
movsbl -0x1(%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x2fe6
movsbl (%r15), %edi
callq 0x2040
testl %eax, %eax
jne 0x2fe9
decq %rbx
addq $0x4, %r15
cmpq $0x1, %rbx
jg 0x2f39
movq %r12, %r13
movq %r14, %rax
subq %r13, %rax
cmpq $0x1, %rax
je 0x2fc5
cmpq $0x2, %rax
je 0x2fb4
movq %r14, %r15
cmpq $0x3, %rax
jne 0x2fe9
movsbl (%r13), %edi
callq 0x2040
testl %eax, %eax
jne 0x2fd5
incq %r13
movsbl (%r13), %edi
callq 0x2040
testl %eax, %eax
jne 0x2fd5
incq %r13
movsbl (%r13), %edi
callq 0x2040
testl %eax, %eax
cmoveq %r14, %r13
movq %r13, %r15
jmp 0x2fe9
addq $-0x3, %r15
jmp 0x2fe9
addq $-0x2, %r15
jmp 0x2fe9
decq %r15
cmpq %r14, %r15
sete %al
leaq 0x1(%r15), %rbx
cmpq %r14, %rbx
sete %cl
orb %al, %cl
jne 0x301b
movb (%rbx), %r12b
movsbl %r12b, %edi
callq 0x2040
testl %eax, %eax
jne 0x3013
movb %r12b, (%r15)
incq %r15
incq %rbx
cmpq %r14, %rbx
jne 0x2ffd
movq %r15, %rax
subq -0x60(%rbp), %rax
movq %rax, -0x58(%rbp)
movb $0x0, (%r15)
movq -0x58(%rbp), %rax
testq %rax, %rax
movl -0x3c(%rbp), %ebx
je 0x2ee9
movq -0x60(%rbp), %rcx
movsbl (%rcx), %edx
addl $-0x30, %edx
cmpl $0x9, %edx
ja 0x32dd
movl $0x1, %esi
cmpq %rsi, %rax
je 0x3072
movq %rsi, %rdx
movsbl (%rcx,%rsi), %edi
addl $-0x30, %edi
incq %rsi
cmpl $0xa, %edi
jb 0x3052
cmpq %rdx, %rax
jne 0x32dd
leaq -0x60(%rbp), %rdi
callq 0x2b7e
testb %al, %al
je 0x33dc
movq -0x60(%rbp), %r15
callq 0x2030
movq %rax, %r14
movl (%rax), %r12d
movl $0x0, (%rax)
movq %r15, %rdi
leaq -0xa8(%rbp), %rsi
movl $0xa, %edx
callq 0x2210
cmpq %r15, -0xa8(%rbp)
je 0x3453
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x345f
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x345f
testl %ecx, %ecx
jne 0x30d8
movl %r12d, (%r14)
movl %eax, -0x40(%rbp)
cmpl $0x19, %ebx
ja 0x30f1
movl %ebx, %ecx
movq -0x38(%rbp), %rdx
movl %eax, (%rdx,%rcx,4)
cltq
movl %ebx, 0x68(%rdx,%rax,4)
jmp 0x3121
movq -0x38(%rbp), %rcx
movq 0xd8(%rcx), %rsi
cmpq 0xe0(%rcx), %rsi
je 0x3114
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0xd8(%rcx)
jmp 0x3121
movq -0x68(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0x4978
incl %ebx
jmp 0x2ee6
cmpl $0x19, %ebx
jbe 0x3398
leaq -0x78(%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 %r13d, %r13d
leaq -0x70(%rbp), %r14
movq -0x38(%rbp), %r15
movq %r15, %rbx
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
movq %rbx, %rsi
movq %r14, %rdx
callq 0x4d3a
testb $0x1, %dl
je 0x31d8
decq %r13
addq $0x4, %rbx
cmpq $-0x1a, %r13
jne 0x3161
movl $0x0, 0xe8(%r15)
movb $0x0, 0xec(%r15)
leaq -0xa8(%rbp), %rdi
callq 0x48f4
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x31ba
callq 0x2180
leaq -0x2b0(%rbp), %rdi
callq 0x2060
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68(%r15), %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x5028
movq %rax, %r12
movq 0x5dff(%rip), %rdi      # 0x8ff0
leaq 0x2fa0(%rip), %rsi      # 0x6198
movl $0x19, %edx
callq 0x21d0
negq %r13
movq 0x5de4(%rip), %rdi      # 0x8ff0
movl %r13d, %esi
callq 0x22a0
movq %rax, %r14
leaq 0x2f94(%rip), %rsi      # 0x61b2
movl $0xb, %edx
movq %rax, %rdi
callq 0x21d0
movl (%rbx), %esi
movq %r14, %rdi
callq 0x22a0
movq %rax, %r14
leaq 0x2f7f(%rip), %rsi      # 0x61be
movl $0x9, %edx
movq %rax, %rdi
callq 0x21d0
movl (%rbx), %esi
movq %r14, %rdi
callq 0x22a0
movq %rax, %rbx
leaq 0x2f68(%rip), %rsi      # 0x61c8
movl $0x21, %edx
movq %rax, %rdi
callq 0x21d0
subq -0x38(%rbp), %r12
sarq $0x2, %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2190
movq %rax, %rbx
leaq 0x2f60(%rip), %rsi      # 0x61ea
movl $0x11, %edx
movq %rax, %rdi
callq 0x21d0
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0x21a0
leaq 0x2dba(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl $0x7, (%rax)
movq 0x5ce2(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
jmp 0x3398
movq 0x5d0c(%rip), %rdi      # 0x8ff0
leaq 0x2e56(%rip), %rsi      # 0x6141
movl $0x30, %edx
callq 0x21d0
movq 0x5cf4(%rip), %rdi      # 0x8ff0
movq -0x30(%rbp), %rsi
callq 0x21a0
movl $0x4, %r14d
leaq 0x2d52(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
jmp 0x3435
movq 0x5cc5(%rip), %rdi      # 0x8ff0
leaq 0x2eca(%rip), %rsi      # 0x61fc
movl $0xb, %edx
callq 0x21d0
movq 0x5cad(%rip), %rdi      # 0x8ff0
movq -0x30(%rbp), %rsi
callq 0x21a0
movq %rax, %rbx
leaq 0x2dbb(%rip), %rsi      # 0x6111
movl $0x1a, %edx
movq %rax, %rdi
callq 0x21d0
leaq 0x2cfa(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rbx, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl $0xb, (%rax)
movq 0x5c22(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
movq 0x5c51(%rip), %rdi      # 0x8ff0
leaq 0x2dcc(%rip), %rsi      # 0x6172
movl $0x25, %edx
callq 0x21d0
movq 0x5c39(%rip), %rdi      # 0x8ff0
movq -0x30(%rbp), %rsi
callq 0x21a0
movl $0x7, %r14d
leaq 0x2c97(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rax, %rdi
callq 0x21d0
jmp 0x3435
movq 0x5c0d(%rip), %rdi      # 0x8ff0
leaq 0x2d42(%rip), %rsi      # 0x612c
movl $0x14, %edx
callq 0x21d0
movq 0x5bf5(%rip), %rdi      # 0x8ff0
movq -0x30(%rbp), %rsi
callq 0x21a0
movq %rax, %rbx
leaq 0x2c2b(%rip), %rsi      # 0x6039
movl $0x2a, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x3, %r14d
leaq 0x2c3c(%rip), %rsi      # 0x6064
movl $0x1, %edx
movq %rbx, %rdi
callq 0x21d0
movl $0x4, %edi
callq 0x20c0
movl %r14d, (%rax)
movq 0x5b67(%rip), %rsi      # 0x8fb0
movq %rax, %rdi
xorl %edx, %edx
callq 0x2290
leaq 0x2fe9(%rip), %rdi      # 0x6443
callq 0x20f0
leaq 0x2fdd(%rip), %rdi      # 0x6443
callq 0x2220
movq %rax, %rbx
jmp 0x34bb
jmp 0x349a
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x349d
movl %r12d, (%r14)
jmp 0x349d
movq %rax, %rbx
jmp 0x34af
jmp 0x349a
jmp 0x3489
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x48f4
jmp 0x349d
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x34af
callq 0x2180
leaq -0x2b0(%rbp), %rdi
callq 0x2060
movq -0x68(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x34cc
callq 0x2180
movq %rbx, %rdi
callq 0x22b0