// File: /workspace/github_cpp_makefile_star2_O2/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 0x2603
movq (%rbx), %rsi
leaq 0xb0(%rsp), %rdi
leaq 0x110(%rsp), %rdx
callq 0x2dc2
leaq 0xb0(%rsp), %rdi
callq 0x2ca8
leaq 0xb0(%rsp), %rdi
callq 0x20c0
pushq $0x1
popq %rax
jmp 0x2b80
leaq 0x51de(%rip), %rsi      # 0x77e8
leaq 0x30(%rsp), %rdi
leaq 0x110(%rsp), %rdx
callq 0x2dc2
leaq 0x51c5(%rip), %rsi      # 0x77e8
leaq 0x70(%rsp), %rdi
leaq 0x110(%rsp), %rdx
callq 0x2dc2
leaq 0x51ac(%rip), %rsi      # 0x77e8
leaq 0x50(%rsp), %rdi
leaq 0x110(%rsp), %rdx
callq 0x2dc2
leaq 0x14(%rsp), %rax
andl $0x0, (%rax)
pushq $0x1
popq %rax
movl $0x0, 0x24(%rsp)
leaq 0xf0(%rsp), %r15
leaq 0x110(%rsp), %r14
leaq 0xd0(%rsp), %r12
leaq 0x90(%rsp), %rbp
movl $0x0, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x2c(%rsp)
movl %eax, %r13d
movl $0x0, 0x10(%rsp)
cmpl 0x18(%rsp), %r13d
jge 0x2959
movslq %r13d, %rax
movq (%rbx,%rax,8), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x2dc2
movq %r15, %rdi
leaq 0x4939(%rip), %rsi      # 0x7004
callq 0x2dfd
testb %al, %al
jne 0x26e7
movq %r15, %rdi
leaq 0x4929(%rip), %rsi      # 0x7007
callq 0x2dfd
testb %al, %al
je 0x2714
movq (%rbx), %rsi
movq %r12, %rdi
movq %r14, %rdx
callq 0x2dc2
movq %r12, %rdi
callq 0x2ca8
movq %r12, %rdi
callq 0x20c0
xorl %r12d, %r12d
movl %r13d, %r14d
pushq $0x1
popq %rax
movl %eax, 0x10(%rsp)
jmp 0x2746
movq %r15, %rdi
leaq 0x48ef(%rip), %rsi      # 0x700d
callq 0x2dfd
movb $0x1, %r12b
testb %al, %al
jne 0x273d
movq %r15, %rdi
leaq 0x48dc(%rip), %rsi      # 0x7010
callq 0x2dfd
testb %al, %al
je 0x2772
movb $0x1, %al
movl %eax, 0x24(%rsp)
movl %r13d, %r14d
movq %r15, %rdi
callq 0x20c0
incl %r14d
movl %r14d, %r13d
testb %r12b, %r12b
leaq 0x110(%rsp), %r14
leaq 0xd0(%rsp), %r12
jne 0x26a4
jmp 0x2b5e
movq %r15, %rdi
leaq 0x489d(%rip), %rsi      # 0x7019
callq 0x2dfd
movb $0x1, %r12b
testb %al, %al
jne 0x279b
movq %r15, %rdi
leaq 0x488a(%rip), %rsi      # 0x701c
callq 0x2dfd
testb %al, %al
je 0x27a3
movb $0x1, %al
movl %eax, 0x20(%rsp)
jmp 0x2743
movq %r15, %rdi
leaq 0x4878(%rip), %rsi      # 0x7025
callq 0x2dfd
movb $0x1, %r12b
testb %al, %al
je 0x27c1
movb $0x1, %al
movl %eax, 0x1c(%rsp)
jmp 0x2743
movq %r15, %rdi
leaq 0x485f(%rip), %rsi      # 0x702a
callq 0x2dfd
movb $0x1, %r12b
testb %al, %al
je 0x27e2
movb $0x1, %al
movl %eax, 0x2c(%rsp)
jmp 0x2743
movq %r15, %rdi
leaq 0x4843(%rip), %rsi      # 0x702f
callq 0x2dfd
testb %al, %al
jne 0x2808
movq %r15, %rdi
leaq 0x4833(%rip), %rsi      # 0x7032
callq 0x2dfd
testb %al, %al
je 0x2874
leal 0x1(%r13), %r14d
leaq 0x4825(%rip), %rsi      # 0x7038
cmpl 0x18(%rsp), %r14d
jge 0x2940
movslq %r14d, %rax
movq (%rbx,%rax,8), %rsi
movq %rbp, %rdi
leaq 0x2b(%rsp), %rdx
callq 0x2dc2
leaq 0x110(%rsp), %r13
movq %r13, %rdi
leaq 0x90(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x2340
leaq 0x90(%rsp), %rdi
callq 0x20c0
movq %r13, %rdi
leaq 0x14(%rsp), %rsi
callq 0x2130
movq %r13, %rdi
callq 0x2160
jmp 0x2746
movq %r15, %rdi
leaq 0x47f3(%rip), %rsi      # 0x7071
callq 0x2dfd
testb %al, %al
je 0x28b3
leal 0x1(%r13), %r14d
leaq 0x47e4(%rip), %rsi      # 0x7076
cmpl 0x18(%rsp), %r14d
jge 0x2940
movslq %r14d, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x70(%rsp), %rdi
callq 0x2410
jmp 0x2746
movq %r15, %rdi
leaq 0x47e6(%rip), %rsi      # 0x70a3
callq 0x2dfd
testb %al, %al
je 0x28ee
leal 0x1(%r13), %r14d
leaq 0x47d7(%rip), %rsi      # 0x70a8
cmpl 0x18(%rsp), %r14d
jge 0x2940
movslq %r14d, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x50(%rsp), %rdi
callq 0x2410
jmp 0x2746
movq %r15, %rdi
leaq 0x47dd(%rip), %rsi      # 0x70d5
callq 0x2dfd
testb %al, %al
jne 0x2918
movq %r15, %rdi
leaq 0x47cd(%rip), %rsi      # 0x70d8
callq 0x2dfd
testb %al, %al
je 0x2743
leal 0x1(%r13), %r14d
leaq 0x47bb(%rip), %rsi      # 0x70de
cmpl 0x18(%rsp), %r14d
jge 0x2940
movslq %r14d, %rax
movq (%rbx,%rax,8), %rsi
leaq 0x30(%rsp), %rdi
callq 0x2410
jmp 0x2746
movq 0x86a9(%rip), %rdi      # 0xaff0
callq 0x21f0
movq %rax, %rdi
callq 0x20f0
jmp 0x2705
movq 0x38(%rsp), %rax
testq %rax, %rax
setne %cl
movl 0x24(%rsp), %edx
andb %cl, %dl
cmpb $0x1, %dl
movl 0x2c(%rsp), %ebx
jne 0x29df
testb $0x1, 0x1c(%rsp)
jne 0x297f
testb $0x1, %bl
je 0x29df
cmpq $0x0, 0x78(%rsp)
je 0x2a7b
cmpq $0x0, 0x58(%rsp)
je 0x2a7b
cmpl $0x0, 0x14(%rsp)
jle 0x2acc
movl $0x90, %edi
callq 0x2200
movq %rax, %r14
movl $0x1, (%rsp)
movzbl %bl, %r9d
andl $0x1, %r9d
leaq 0x30(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
leaq 0x14(%rsp), %r8
movq %rax, %rdi
callq 0x414a
jmp 0x2afc
testq %rax, %rax
setne %al
movl 0x20(%rsp), %ecx
andb %al, %cl
cmpb $0x1, %cl
jne 0x2a54
testb $0x1, 0x1c(%rsp)
jne 0x29fc
testb $0x1, %bl
je 0x2a54
cmpq $0x0, 0x78(%rsp)
je 0x2aa6
cmpq $0x0, 0x58(%rsp)
je 0x2aa6
cmpl $0x0, 0x14(%rsp)
jle 0x2b15
movl $0x90, %edi
callq 0x2200
movq %rax, %r14
andl $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 0x414a
jmp 0x2b3f
movq 0x8595(%rip), %rdi      # 0xaff0
leaq 0x469b(%rip), %rsi      # 0x70fd
callq 0x21f0
movq %rax, %rdi
callq 0x20f0
pushq $0x1
popq %rax
movl %eax, 0x10(%rsp)
jmp 0x2b5e
movl $0x90, %edi
callq 0x2200
movq %rax, %r14
movzbl %bl, %ecx
andl $0x1, %ecx
leaq 0x30(%rsp), %rsi
leaq 0x14(%rsp), %rdx
pushq $0x1
popq %r8
movq %rax, %rdi
callq 0x386c
jmp 0x2afc
movl $0x90, %edi
callq 0x2200
movq %rax, %r14
leaq 0x30(%rsp), %rsi
leaq 0x14(%rsp), %rdx
movq %rax, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x386c
jmp 0x2b3f
movl $0x90, %edi
callq 0x2200
movq %rax, %r14
movzbl %bl, %r8d
andl $0x1, %r8d
leaq 0x30(%rsp), %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
pushq $0x1
popq %r9
movq %rax, %rdi
callq 0x3e80
testb $0x1, %bl
je 0x2b0b
movq %r14, %rdi
callq 0x5132
jmp 0x2b56
movq %r14, %rdi
callq 0x544e
jmp 0x2b56
movl $0x90, %edi
callq 0x2200
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 0x3e80
testb $0x1, %bl
je 0x2b4e
movq %r14, %rdi
callq 0x525e
jmp 0x2b56
movq %r14, %rdi
callq 0x5592
movl $0x0, 0x10(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x20c0
leaq 0x70(%rsp), %rdi
callq 0x20c0
leaq 0x30(%rsp), %rdi
callq 0x20c0
movl 0x10(%rsp), %eax
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2bcb
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x2160
jmp 0x2c70
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
jmp 0x2c66
jmp 0x2c6d
jmp 0x2bcb
jmp 0x2bcb
jmp 0x2bcb
jmp 0x2bcb
jmp 0x2c6d
movq %rdx, %r15
movq %rax, %rbx
movl $0x90, %esi
movq %r14, %rdi
callq 0x2210
jmp 0x2c10
movq %rax, %rbx
jmp 0x2c8c
movq %rax, %rbx
jmp 0x2c96
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
jmp 0x2c9b
jmp 0x2c02
movq %rax, %rbx
jmp 0x2ca0
movq %rdx, %r15
movq %rax, %rbx
cmpl $0x1, %r15d
jne 0x2c82
movq %rbx, %rdi
callq 0x20a0
movq %rax, %rbx
movq 0x83c8(%rip), %rdi      # 0xaff0
leaq 0x4507(%rip), %rsi      # 0x7136
callq 0x21f0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21f0
movq %rax, %rdi
callq 0x20f0
callq 0x2370
jmp 0x2a6f
movq %rax, %rbx
callq 0x2370
jmp 0x2c82
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x20c0
jmp 0x2c70
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x20c0
jmp 0x2c82
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x20c0
leaq 0x70(%rsp), %rdi
callq 0x20c0
leaq 0x30(%rsp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x23d0