// File: /workspace/github_cpp_makefile_star2_O1/lmclaramunt[P]AES-Crypto/Main.cpp
// Function: main
int main(int argc, char* argv[]) {
    if(argc < 2) {
        help(argv[0]);
        return 1;
}

    string filePath = "", aesKeyPath = "", macKeyPath = "";
    int keyLength = 0;
    bool encrypt = false, decrypt = false, ofb = false, cbc = false;
    for(int i = 1; i < argc; i++) {
        string arg = argv[i];
        if(arg == "-h" || arg== "-help" ) {
            help(argv[0]);
            return 1;
        } else if(arg == "-e" || arg == "-encrypt") {
            encrypt = true;
        } else if(arg == "-d" || arg == "-decrypt") {
            decrypt = true;
        } else if(arg == "-ofb") {
            ofb = true;
        } else if(arg == "-cbc") {
            cbc = true;
        } else if(arg == "-b" || arg == "-bits") {
            if(i+1 < argc) {
                stringstream ss(argv[++i]);
                ss >> keyLength;
            } else {
                cerr<<"-b/bits option requires key length in bits (128/192/256)"<<endl;
                return 1;
            }
        } else if(arg == "-aes") {
            if(i+1 < argc) {
                aesKeyPath = argv[++i];
            } else {
                cerr<<"-aes option requires the path to the AES key"<<endl;
                return 1;
            }
        } else if(arg == "-mac") {
            if(i+1 < argc) {
                macKeyPath = argv[++i];
            } else {
                cerr<<"-mac option requires the path to the MAC key"<<endl;
                return 1;
            }
        } else if (arg == "-p" || arg == "-path") {
            if(i+1 < argc) {
                filePath = argv[++i];
            } else {
                cerr<<"-p/path option requires a path"<<endl;
                return 1;
            }
        }
    }

    try {
        Cipher* c;
        if(encrypt && !filePath.empty() && (ofb || cbc)) {
            if(!aesKeyPath.empty() && !macKeyPath.empty())
                if(keyLength > 0)
                    c = new Cipher(&filePath, &aesKeyPath, &macKeyPath, &keyLength, cbc, true);
                else
                    c = new Cipher(&filePath, &aesKeyPath, &macKeyPath, cbc, true);     //cbc bool determines if 
            else                                                                        //padding is needed
                c = new Cipher(&filePath, &keyLength, cbc, true);                       //true - since we're encrypting
            if(cbc) {
                c->CBC_encrypt();
            } else {
                c->OFB_encrypt();
            }            
        } else if(decrypt && !filePath.empty() && (ofb || cbc)) {
            if(!aesKeyPath.empty() && !macKeyPath.empty())
                if(keyLength > 0)
                    c = new Cipher(&filePath, &aesKeyPath, &macKeyPath, &keyLength, false, false);
                else
                   c = new Cipher(&filePath, &aesKeyPath, &macKeyPath, false, false);  //both bool to false since we are
            else                                                                       //decrypting and no padding is needed
                c = new Cipher(&filePath, &keyLength, false, false);
            if(cbc) {
                c->CBC_decrypt();
            } else {
                c->OFB_decrypt();
            }
        } else {
            cerr<<"Invalid parameters. Use -h/help for assistance if needed"<<endl;
            return 1;
        }
    } catch(const char* str) {
        cerr<<"Exception: "<<str<<endl;
        return 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x298, %rsp            # imm = 0x298
movq %rsi, %rbx
movl %edi, 0x18(%rsp)
cmpl $0x1, %edi
jg 0x2649
movq (%rbx), %rsi
leaq 0xf0(%rsp), %rdi
leaq 0x110(%rsp), %rdx
callq 0x310e
leaq 0xf0(%rsp), %rdi
callq 0x2ee0
leaq 0x100(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x263f
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x2250
movl $0x1, %ebx
jmp 0x2cf3
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x510f(%rip), %rdx      # 0x7768
leaq 0x30(%rsp), %rdi
movq %rdx, %rsi
callq 0x314c
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x50ef(%rip), %rdx      # 0x7768
leaq 0x70(%rsp), %rdi
movq %rdx, %rsi
callq 0x314c
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x50d2(%rip), %rdx      # 0x7768
leaq 0x50(%rsp), %rdi
movq %rdx, %rsi
callq 0x314c
leaq 0x14(%rsp), %rax
movl $0x0, (%rax)
movl $0x1, %r12d
movl $0x0, 0x28(%rsp)
movb $0x1, %r15b
leaq 0xd0(%rsp), %r13
leaq 0x110(%rsp), %r14
movl $0x0, 0x10(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x20(%rsp)
movl $0x0, 0x24(%rsp)
movslq %r12d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
movq %r14, %rdx
callq 0x310e
movq %r13, %rdi
leaq 0x48f9(%rip), %rsi      # 0x7004
callq 0x2090
testl %eax, %eax
je 0x2873
movq %r13, %rdi
leaq 0x48e5(%rip), %rsi      # 0x7007
callq 0x2090
testl %eax, %eax
je 0x2873
movq %r13, %rdi
leaq 0x48d4(%rip), %rsi      # 0x700d
callq 0x2090
testl %eax, %eax
je 0x28c3
movq %r13, %rdi
leaq 0x48c0(%rip), %rsi      # 0x7010
callq 0x2090
testl %eax, %eax
je 0x28c3
movq %r13, %rdi
leaq 0x48b2(%rip), %rsi      # 0x7019
callq 0x2090
testl %eax, %eax
je 0x28cb
movq %r13, %rdi
leaq 0x489e(%rip), %rsi      # 0x701c
callq 0x2090
testl %eax, %eax
je 0x28cb
movq %r13, %rdi
leaq 0x4890(%rip), %rsi      # 0x7025
callq 0x2090
testl %eax, %eax
je 0x2921
movq %r13, %rdi
leaq 0x487e(%rip), %rsi      # 0x702a
callq 0x2090
movb $0x1, %r14b
testl %eax, %eax
je 0x29d3
movq %r13, %rdi
leaq 0x4869(%rip), %rsi      # 0x702f
callq 0x2090
testl %eax, %eax
je 0x2929
movq %r13, %rdi
leaq 0x4855(%rip), %rsi      # 0x7032
callq 0x2090
testl %eax, %eax
je 0x2929
movq %r13, %rdi
leaq 0x487d(%rip), %rsi      # 0x7071
callq 0x2090
testl %eax, %eax
je 0x29de
movq %r13, %rdi
leaq 0x4898(%rip), %rsi      # 0x70a3
callq 0x2090
testl %eax, %eax
je 0x2a0e
movq %r13, %rdi
leaq 0x48b3(%rip), %rsi      # 0x70d5
callq 0x2090
testl %eax, %eax
je 0x2842
movq %r13, %rdi
leaq 0x48a3(%rip), %rsi      # 0x70d8
callq 0x2090
testl %eax, %eax
jne 0x28d4
leal 0x1(%r12), %ebp
movl $0x1e, %edx
leaq 0x488b(%rip), %rsi      # 0x70de
cmpl 0x18(%rsp), %ebp
jge 0x2a3e
movslq %ebp, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x30(%rsp), %rdi
callq 0x22e0
movl %ebp, %r12d
jmp 0x28d4
movq (%rbx), %rsi
leaq 0xb0(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rdx
callq 0x310e
movq %rbp, %rdi
callq 0x2ee0
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x28b6
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2250
movl $0x1, 0x28(%rsp)
xorl %r14d, %r14d
jmp 0x28d4
movb $0x1, %al
movl %eax, 0x24(%rsp)
jmp 0x28d1
movb $0x1, %al
movl %eax, 0x20(%rsp)
movb $0x1, %r14b
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x28f9
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x2250
testb %r14b, %r14b
leaq 0x110(%rsp), %r14
je 0x2a5b
incl %r12d
cmpl 0x18(%rsp), %r12d
setl %r15b
jl 0x26ef
jmp 0x2a5b
movb $0x1, %al
movl %eax, 0x1c(%rsp)
jmp 0x28d1
leal 0x1(%r12), %ebp
movl $0x38, %edx
leaq 0x46fe(%rip), %rsi      # 0x7038
cmpl 0x18(%rsp), %ebp
jge 0x2a3e
movslq %ebp, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x90(%rsp), %r12
movq %r12, %rdi
leaq 0x2f(%rsp), %rdx
callq 0x310e
leaq 0x110(%rsp), %rdi
movq %r12, %rsi
movl $0x18, %edx
callq 0x2370
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x299a
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2250
leaq 0x110(%rsp), %r12
movq %r12, %rdi
leaq 0x14(%rsp), %rsi
callq 0x2150
movq %r12, %rdi
movq 0x85f7(%rip), %rsi      # 0xafb0
callq 0x2180
leaq 0x190(%rsp), %rdi
callq 0x20b0
movl %ebp, %r12d
jmp 0x28d4
movb $0x1, %al
movl %eax, 0x10(%rsp)
jmp 0x28d4
leal 0x1(%r12), %ebp
movl $0x2c, %edx
leaq 0x4687(%rip), %rsi      # 0x7076
cmpl 0x18(%rsp), %ebp
jge 0x2a3e
movslq %ebp, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x70(%rsp), %rdi
callq 0x22e0
movl %ebp, %r12d
jmp 0x28d4
leal 0x1(%r12), %ebp
movl $0x2c, %edx
leaq 0x4689(%rip), %rsi      # 0x70a8
cmpl 0x18(%rsp), %ebp
jge 0x2a3e
movslq %ebp, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x50(%rsp), %rdi
callq 0x22e0
movl %ebp, %r12d
jmp 0x28d4
movq 0x85ab(%rip), %rdi      # 0xaff0
callq 0x2260
movq 0x859f(%rip), %rdi      # 0xaff0
callq 0x2110
jmp 0x28b6
testb $0x1, %r15b
movl 0x28(%rsp), %ebx
jne 0x2c99
testb $0x1, 0x24(%rsp)
je 0x2ae8
cmpq $0x0, 0x38(%rsp)
je 0x2ae8
testb $0x1, 0x1c(%rsp)
jne 0x2a86
testb $0x1, 0x10(%rsp)
je 0x2ae8
cmpq $0x0, 0x78(%rsp)
je 0x2bb0
cmpq $0x0, 0x58(%rsp)
je 0x2bb0
cmpl $0x0, 0x14(%rsp)
jle 0x2c05
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
movl $0x1, (%rsp)
movzbl 0x10(%rsp), %r9d
andl $0x1, %r9d
leaq 0x30(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
leaq 0x14(%rsp), %r8
movq %rax, %rdi
callq 0x48a8
jmp 0x2c39
testb $0x1, 0x20(%rsp)
je 0x2b60
cmpq $0x0, 0x38(%rsp)
je 0x2b60
testb $0x1, 0x1c(%rsp)
jne 0x2b05
testb $0x1, 0x10(%rsp)
je 0x2b60
cmpq $0x0, 0x78(%rsp)
je 0x2bdf
cmpq $0x0, 0x58(%rsp)
je 0x2bdf
cmpl $0x0, 0x14(%rsp)
jle 0x2c54
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
movl $0x0, (%rsp)
leaq 0x30(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
leaq 0x14(%rsp), %r8
movq %rax, %rdi
xorl %r9d, %r9d
callq 0x48a8
jmp 0x2c7e
movq 0x8489(%rip), %rbx      # 0xaff0
leaq 0x458f(%rip), %rsi      # 0x70fd
movl $0x38, %edx
movq %rbx, %rdi
callq 0x2260
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %esi
movq 0x8457(%rip), %rdi      # 0xaff0
callq 0x2040
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2160
jmp 0x2c99
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
movzbl 0x10(%rsp), %ecx
andl $0x1, %ecx
leaq 0x30(%rsp), %rsi
leaq 0x14(%rsp), %rdx
movq %rax, %rdi
movl $0x1, %r8d
callq 0x3bd4
jmp 0x2c39
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
leaq 0x30(%rsp), %rsi
leaq 0x14(%rsp), %rdx
movq %rax, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3bd4
jmp 0x2c7e
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
movzbl 0x10(%rsp), %r8d
andl $0x1, %r8d
leaq 0x30(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq %rax, %rdi
movl $0x1, %r9d
callq 0x452a
testb $0x1, 0x10(%rsp)
je 0x2c4a
movq %r14, %rdi
callq 0x5c9c
jmp 0x2c97
movq %r14, %rdi
callq 0x6006
jmp 0x2c97
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
leaq 0x30(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq %rax, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x452a
testb $0x1, 0x10(%rsp)
je 0x2c8f
movq %r14, %rdi
callq 0x5dd8
jmp 0x2c97
movq %r14, %rdi
callq 0x6158
xorl %ebx, %ebx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2cb5
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2250
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x2cd7
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2250
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2cf3
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2250
movl %ebx, %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2d11
jmp 0x2d11
jmp 0x2d11
jmp 0x2d11
jmp 0x2d11
movq %rdx, %r15
movq %rax, %rbx
movl $0x90, %esi
movq %r14, %rdi
callq 0x2250
jmp 0x2dca
movq %rax, %rbx
movq 0x827d(%rip), %rsi      # 0xafb0
leaq 0x110(%rsp), %rdi
callq 0x2180
leaq 0x190(%rsp), %rdi
callq 0x20b0
jmp 0x2e54
movq %rax, %rbx
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2e54
movq 0xa0(%rsp), %rsi
jmp 0x2e47
jmp 0x2e51
jmp 0x2e51
movq %rax, %rbx
jmp 0x2e9a
movq %rax, %rbx
jmp 0x2ebc
movq %rax, %rbx
leaq 0x100(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ed8
movq 0x100(%rsp), %rsi
jmp 0x2ed0
jmp 0x2dbc
movq %rax, %rbx
jmp 0x2ed8
movq %rdx, %r15
movq %rax, %rbx
cmpl $0x1, %r15d
jne 0x2e7e
movq %rbx, %rdi
callq 0x20d0
movq %rax, %rbx
movq 0x820a(%rip), %rdi      # 0xaff0
leaq 0x4349(%rip), %rsi      # 0x7136
movl $0xb, %edx
callq 0x2260
movq 0x81f2(%rip), %rdi      # 0xaff0
movq %rbx, %rsi
callq 0x2230
movq %rax, %rdi
callq 0x2110
callq 0x23a0
movl $0x1, %ebx
jmp 0x2c99
movq %rax, %rbx
callq 0x23a0
jmp 0x2e7e
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x2e54
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2250
jmp 0x2e54
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x2e7e
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x2250
jmp 0x2e7e
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2e9a
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2250
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x2ebc
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2250
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2ed8
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2250
movq %rbx, %rdi
callq 0x2400