// File: /workspace/github_cpp_makefile_star2_O3/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
cmpl $0x1, %edi
jg 0x264e
movq (%rbx), %rsi
leaq 0xf0(%rsp), %rdi
leaq 0x110(%rsp), %rdx
callq 0x3106
movq 0xf0(%rsp), %rdi
movq 0xf8(%rsp), %rsi
callq 0x2ed8
leaq 0x100(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2643
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x2250
movl $0x1, %r14d
jmp 0x2ce9
movl %edi, %ebp
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5168(%rip), %rdx      # 0x77c8
leaq 0x28(%rsp), %rdi
movq %rdx, %rsi
callq 0x3144
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5148(%rip), %rdx      # 0x77c8
leaq 0x70(%rsp), %rdi
movq %rdx, %rsi
callq 0x3144
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x512b(%rip), %rdx      # 0x77c8
leaq 0x50(%rsp), %rdi
movq %rdx, %rsi
callq 0x3144
leaq 0x10(%rsp), %rax
movl $0x0, (%rax)
movl $0x1, %r12d
xorl %r14d, %r14d
leaq 0xd0(%rsp), %r13
leaq 0x110(%rsp), %r15
movl $0x0, 0x24(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x1c(%rsp)
movslq %r12d, %rax
movq (%rbx,%rax,8), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x3106
movq %r13, %rdi
leaq 0x48fa(%rip), %rsi      # 0x7004
callq 0x2090
testl %eax, %eax
je 0x2875
movq %r13, %rdi
leaq 0x48e6(%rip), %rsi      # 0x7007
callq 0x2090
testl %eax, %eax
je 0x2875
movq %r13, %rdi
leaq 0x48d5(%rip), %rsi      # 0x700d
callq 0x2090
movb $0x1, %r15b
testl %eax, %eax
je 0x28cd
movq %r13, %rdi
leaq 0x48be(%rip), %rsi      # 0x7010
callq 0x2090
testl %eax, %eax
je 0x28cd
movq %r13, %rdi
leaq 0x48b0(%rip), %rsi      # 0x7019
callq 0x2090
movb $0x1, %r15b
testl %eax, %eax
je 0x28d5
movq %r13, %rdi
leaq 0x4899(%rip), %rsi      # 0x701c
callq 0x2090
testl %eax, %eax
je 0x28d5
movq %r13, %rdi
leaq 0x488b(%rip), %rsi      # 0x7025
callq 0x2090
testl %eax, %eax
je 0x2922
movq %r13, %rdi
leaq 0x4879(%rip), %rsi      # 0x702a
callq 0x2090
movb $0x1, %r15b
testl %eax, %eax
je 0x29dc
movq %r13, %rdi
leaq 0x4864(%rip), %rsi      # 0x702f
callq 0x2090
testl %eax, %eax
je 0x292d
movq %r13, %rdi
leaq 0x4850(%rip), %rsi      # 0x7032
callq 0x2090
testl %eax, %eax
je 0x292d
movq %r13, %rdi
leaq 0x4878(%rip), %rsi      # 0x7071
callq 0x2090
testl %eax, %eax
je 0x29e7
movq %r13, %rdi
leaq 0x4893(%rip), %rsi      # 0x70a3
callq 0x2090
testl %eax, %eax
je 0x2a14
movq %r13, %rdi
leaq 0x48ae(%rip), %rsi      # 0x70d5
callq 0x2090
testl %eax, %eax
je 0x2847
movq %r13, %rdi
leaq 0x489e(%rip), %rsi      # 0x70d8
callq 0x2090
testl %eax, %eax
jne 0x28db
leal 0x1(%r12), %eax
movl $0x1e, %edx
leaq 0x4886(%rip), %rsi      # 0x70de
cmpl %ebp, %eax
jge 0x2a41
movl %eax, %r12d
cltq
movq (%rbx,%rax,8), %rsi
leaq 0x28(%rsp), %rdi
callq 0x22e0
jmp 0x28db
movq (%rbx), %rsi
leaq 0x90(%rsp), %rdi
movq %r15, %rdx
callq 0x3106
movq 0x90(%rsp), %rdi
movq 0x98(%rsp), %rsi
callq 0x2ed8
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x28c2
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2250
movl $0x1, %r14d
xorl %r15d, %r15d
jmp 0x28db
movb $0x1, %al
movl %eax, 0x1c(%rsp)
jmp 0x28db
movb $0x1, %al
movl %eax, 0x18(%rsp)
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x2900
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x2250
testb %r15b, %r15b
je 0x2c8f
incl %r12d
cmpl %ebp, %r12d
leaq 0x110(%rsp), %r15
jl 0x26ee
jmp 0x2a5e
movb $0x1, %al
movl %eax, 0x14(%rsp)
movb $0x1, %r15b
jmp 0x28db
leal 0x1(%r12), %eax
movl $0x38, %edx
leaq 0x46fa(%rip), %rsi      # 0x7038
cmpl %ebp, %eax
jge 0x2a41
movl %eax, 0x4c(%rsp)
cltq
movq (%rbx,%rax,8), %rsi
leaq 0xb0(%rsp), %r12
movq %r12, %rdi
leaq 0x23(%rsp), %rdx
callq 0x3106
leaq 0x110(%rsp), %rdi
movq %r12, %rsi
movl $0x18, %edx
callq 0x2370
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x299f
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2250
leaq 0x110(%rsp), %r12
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x2150
movq %r12, %rdi
movq 0x85f2(%rip), %rsi      # 0xafb0
callq 0x2180
leaq 0x190(%rsp), %rdi
callq 0x20b0
movl 0x4c(%rsp), %eax
movl %eax, %r12d
jmp 0x28db
movb $0x1, %al
movl %eax, 0x24(%rsp)
jmp 0x28db
leal 0x1(%r12), %eax
movl $0x2c, %edx
leaq 0x467e(%rip), %rsi      # 0x7076
cmpl %ebp, %eax
jge 0x2a41
movl %eax, %r12d
cltq
movq (%rbx,%rax,8), %rsi
leaq 0x70(%rsp), %rdi
callq 0x22e0
jmp 0x28db
leal 0x1(%r12), %eax
movl $0x2c, %edx
leaq 0x4683(%rip), %rsi      # 0x70a8
cmpl %ebp, %eax
jge 0x2a41
movl %eax, %r12d
cltq
movq (%rbx,%rax,8), %rsi
leaq 0x50(%rsp), %rdi
callq 0x22e0
jmp 0x28db
movq 0x85a8(%rip), %rdi      # 0xaff0
callq 0x2260
movq 0x859c(%rip), %rdi      # 0xaff0
callq 0x2110
jmp 0x28c2
movq 0x30(%rsp), %rax
testq %rax, %rax
setne %cl
movl 0x1c(%rsp), %edx
andb %cl, %dl
cmpb $0x1, %dl
movl 0x24(%rsp), %ebx
jne 0x2ae4
testb $0x1, 0x14(%rsp)
jne 0x2a84
testb $0x1, %bl
je 0x2ae4
cmpq $0x0, 0x78(%rsp)
je 0x2bad
cmpq $0x0, 0x58(%rsp)
je 0x2bad
cmpl $0x0, 0x10(%rsp)
jle 0x2c00
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
movl $0x1, (%rsp)
movzbl %bl, %r9d
andl $0x1, %r9d
leaq 0x28(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %rax, %rdi
callq 0x48b8
jmp 0x2c32
testq %rax, %rax
setne %al
movl 0x18(%rsp), %ecx
andb %al, %cl
cmpb $0x1, %cl
jne 0x2b5c
testb $0x1, 0x14(%rsp)
jne 0x2b01
testb $0x1, %bl
je 0x2b5c
cmpq $0x0, 0x78(%rsp)
je 0x2bda
cmpq $0x0, 0x58(%rsp)
je 0x2bda
cmpl $0x0, 0x10(%rsp)
jle 0x2c4b
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
movl $0x0, (%rsp)
leaq 0x28(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %rax, %rdi
xorl %r9d, %r9d
callq 0x48b8
jmp 0x2c75
movq 0x848d(%rip), %rbx      # 0xaff0
leaq 0x4593(%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 0x845b(%rip), %rdi      # 0xaff0
callq 0x2040
movl $0x1, %r14d
movq %rax, %rdi
callq 0x2160
jmp 0x2c8f
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
movzbl %bl, %ecx
andl $0x1, %ecx
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %rax, %rdi
movl $0x1, %r8d
callq 0x3bec
jmp 0x2c32
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %rax, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3bec
jmp 0x2c75
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
movzbl %bl, %r8d
andl $0x1, %r8d
leaq 0x28(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq %rax, %rdi
movl $0x1, %r9d
callq 0x453a
testb $0x1, %bl
je 0x2c41
movq %r14, %rdi
callq 0x5cb6
jmp 0x2c8c
movq %r14, %rdi
callq 0x6016
jmp 0x2c8c
movl $0x90, %edi
callq 0x2240
movq %rax, %r14
leaq 0x28(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq %rax, %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x453a
testb $0x1, %bl
je 0x2c84
movq %r14, %rdi
callq 0x5df2
jmp 0x2c8c
movq %r14, %rdi
callq 0x6168
xorl %r14d, %r14d
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2cab
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2250
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x2ccd
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2250
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x2ce9
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2250
movl %r14d, %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2d08
jmp 0x2d08
jmp 0x2d08
jmp 0x2d08
jmp 0x2d08
movq %rdx, %r15
movq %rax, %rbx
movl $0x90, %esi
movq %r14, %rdi
callq 0x2250
jmp 0x2dc1
movq %rax, %rbx
movq 0x8286(%rip), %rsi      # 0xafb0
leaq 0x110(%rsp), %rdi
callq 0x2180
leaq 0x190(%rsp), %rdi
callq 0x20b0
jmp 0x2e4c
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x2e4c
movq 0xc0(%rsp), %rsi
jmp 0x2e3f
jmp 0x2e49
jmp 0x2e49
movq %rax, %rbx
jmp 0x2e92
movq %rax, %rbx
jmp 0x2eb4
movq %rax, %rbx
leaq 0x100(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ed0
movq 0x100(%rsp), %rsi
jmp 0x2ec8
jmp 0x2db3
movq %rax, %rbx
jmp 0x2ed0
movq %rdx, %r15
movq %rax, %rbx
cmpl $0x1, %r15d
jne 0x2e76
movq %rbx, %rdi
callq 0x20d0
movq %rax, %rbx
movq 0x8213(%rip), %rdi      # 0xaff0
leaq 0x4352(%rip), %rsi      # 0x7136
movl $0xb, %edx
callq 0x2260
movq 0x81fb(%rip), %rdi      # 0xaff0
movq %rbx, %rsi
callq 0x2230
movq %rax, %rdi
callq 0x2110
callq 0x23a0
movl $0x1, %r14d
jmp 0x2c8f
movq %rax, %rbx
callq 0x23a0
jmp 0x2e76
movq %rax, %rbx
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2e4c
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2250
jmp 0x2e4c
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x2e76
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x2250
jmp 0x2e76
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2e92
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2250
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x2eb4
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2250
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x2ed0
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2250
movq %rbx, %rdi
callq 0x2400