// File: /workspace/github_cpp_makefile_star2_O3/occivink[P]pyct/pyct.cpp
// Function: parse_args(int, char**)
Args parse_args(int argc, char** argv) {
    argc--;
    argv++;
    Args args;
    if (argc == 0)
        throw invalid_argument{"Missing operation"};
    string op(argv[0]);
    if (op == "-h" or op == "--help") {
        args.help = true;
        return args;
    }
    const auto is_prefix = [](const string& pre, const string& s) {
        return pre.size() <= s.size() and equal(pre.begin(), pre.end(), s.begin());
    };
    if (is_prefix(op, "encrypt"))
        args.operation = Args::Operation::Encrypt;
    else if (is_prefix(op, "decrypt"))
        args.operation = Args::Operation::Decrypt;
    else if (is_prefix(op, "hash"))
        args.operation = Args::Operation::Hash;
    else
        throw invalid_argument{"Invalid operation"};

    auto option_value = [argc, argv](int i) {
        if (i >= argc)
            throw invalid_argument{"Missing option value"};
        return string(argv[i]);
    };
    for (int i = 1; i < argc; ++i) {
        string arg(argv[i]);
        if (arg == "-h" or arg == "--help") {
            args.help = true;
        } else if (arg == "-b" or arg == "--base-64") {
            args.base64 = true;
        } else if (arg == "--non-interactive") {
            args.interactive = false;
        } else if (arg == "--no-confirm") {
            args.confirm = false;
        } else if (arg == "--iterations") {
            args.iterations = stoi(option_value(++i));
        } else if (arg == "--work-area-size") {
            args.work_area_size = size_to_number(option_value(++i));
        } else if (arg == "--hash-fd") {
            auto fd = stoi(option_value(++i));
            vector<u8> hash;
            try {
                hash = from_base_64(read_from_fd<string>(fd));
            } catch(...) {
                throw invalid_argument{"Invalid hash"};
            }
            if (hash.size() != 32)
                throw invalid_argument{"Hash is not the correct size"};
            args.hash.emplace();
            copy(hash.begin(), hash.end(), args.hash->begin());
        } else if (arg == "--pass-fd") {
            auto fd = stoi(option_value(++i));
            args.password = read_from_fd<string>(fd);
        } else if (arg == "--input-data-fd") {
            auto fd = stoi(option_value(++i));
            args.input_data_fd = fd;
        } else if (arg == "-s" or arg == "--salt") {
            args.salt = option_value(++i);
            if (args.salt->size() < 8)
                throw invalid_argument{"Salt is too small"};
        } else if (arg == "-l" or arg == "--padded-length") {
            args.padded_length = size_to_number(option_value(++i));
        } else {
            throw invalid_argument{"Unrecognized argument: " + arg};
        }
    }
    if (args.hash and args.password)
        throw invalid_argument{"Can only provide one of hash and password at once"};
    else if (args.operation != Args::Operation::Encrypt and args.padded_length)
        throw invalid_argument{"Can only pad when encrypting"};
    return args;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
xorl %eax, %eax
movl %esi, %ebp
movq $0x1010000, 0x4(%rdi)   # imm = 0x1010000
movb %al, 0x18(%rdi)
movb %al, 0x28(%rdi)
movb %al, 0x50(%rdi)
movb %al, 0x78(%rdi)
movb %al, 0xa0(%rdi)
movb %al, 0xb0(%rdi)
decl %ebp
je 0xb3f5
movq %rdx, %r14
movl %esi, %r15d
addq $0x8, %r14
movq (%r14), %rsi
leaq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xc2de
leaq 0x3491(%rip), %rsi      # 0xe187
leaq 0x60(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0xad54
leaq 0x347f(%rip), %rsi      # 0xe18a
leaq 0x60(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0xad54
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3468(%rip), %rsi      # 0xe191
leaq 0x3468(%rip), %rdx      # 0xe198
leaq 0x30(%rsp), %rdi
movq %rbx, 0x28(%rsp)
callq 0xca2c
movq 0x68(%rsp), %rdx
movq 0x30(%rsp), %r12
cmpq 0x38(%rsp), %rdx
jbe 0xad5d
xorl %ebx, %ebx
jmp 0xad78
movb $0x1, 0x4(%rbx)
jmp 0xb3c5
testq %rdx, %rdx
je 0xad76
movq 0x60(%rsp), %rdi
movq %r12, %rsi
callq 0x2200
testl %eax, %eax
sete %bl
jmp 0xad78
movb $0x1, %bl
leaq 0x40(%rsp), %rax
cmpq %rax, %r12
je 0xad92
movq 0x40(%rsp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x21f0
xorl %eax, %eax
testb %bl, %bl
jne 0xae86
leaq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
movq %rax, (%rdi)
leaq 0x33e9(%rip), %rsi      # 0xe199
leaq 0x33e9(%rip), %rdx      # 0xe1a0
callq 0xca2c
movq 0x68(%rsp), %rdx
movq 0x30(%rsp), %r12
cmpq 0x38(%rsp), %rdx
jbe 0xadd1
xorl %ebx, %ebx
jmp 0xadec
testq %rdx, %rdx
je 0xadea
movq 0x60(%rsp), %rdi
movq %r12, %rsi
callq 0x2200
testl %eax, %eax
sete %bl
jmp 0xadec
movb $0x1, %bl
leaq 0x40(%rsp), %rax
cmpq %rax, %r12
je 0xae06
movq 0x40(%rsp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x21f0
movl $0x1, %eax
testb %bl, %bl
jne 0xae86
leaq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
movq %rax, (%rdi)
leaq 0x33ec(%rip), %rsi      # 0xe20f
leaq 0x33e9(%rip), %rdx      # 0xe213
callq 0xca2c
movq 0x68(%rsp), %rdx
movq 0x30(%rsp), %r12
cmpq 0x38(%rsp), %rdx
jbe 0xae44
xorl %ebx, %ebx
jmp 0xae5f
testq %rdx, %rdx
je 0xae5d
movq 0x60(%rsp), %rdi
movq %r12, %rsi
callq 0x2200
testl %eax, %eax
sete %bl
jmp 0xae5f
movb $0x1, %bl
leaq 0x40(%rsp), %rax
cmpq %rax, %r12
je 0xae79
movq 0x40(%rsp), %rsi
incq %rsi
movq %r12, %rdi
callq 0x21f0
movl $0x2, %eax
testb %bl, %bl
je 0xb4cb
movq 0x28(%rsp), %rbx
movl %eax, (%rbx)
cmpl $0x3, %r15d
jl 0xb3a7
leaq 0x80(%rbx), %rax
movq %rax, 0x80(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x88(%rsp)
leaq 0x58(%rbx), %rax
movq %rax, 0x90(%rsp)
movl $0x1, %r13d
leaq 0x30(%rsp), %r15
movslq %r13d, %rax
movq (%r14,%rax,8), %rsi
movq %r15, %rdi
movq %rsp, %rdx
callq 0xc2de
movq %r15, %rdi
leaq 0x32a2(%rip), %rsi      # 0xe187
callq 0x2070
testl %eax, %eax
je 0xb061
movq %r15, %rdi
leaq 0x328e(%rip), %rsi      # 0xe18a
callq 0x2070
testl %eax, %eax
je 0xb061
movq %r15, %rdi
leaq 0x32a0(%rip), %rsi      # 0xe1b3
callq 0x2070
testl %eax, %eax
je 0xb067
movq %r15, %rdi
leaq 0x328c(%rip), %rsi      # 0xe1b6
callq 0x2070
testl %eax, %eax
je 0xb067
movq %r15, %rdi
leaq 0x327f(%rip), %rsi      # 0xe1c0
callq 0x2070
testl %eax, %eax
je 0xb098
movq %r15, %rdi
leaq 0x327a(%rip), %rsi      # 0xe1d2
callq 0x2070
testl %eax, %eax
je 0xb09e
movq %r15, %rdi
leaq 0x3270(%rip), %rsi      # 0xe1df
callq 0x2070
testl %eax, %eax
je 0xb0a4
movq %r15, %rdi
leaq 0x3266(%rip), %rsi      # 0xe1ec
callq 0x2070
testl %eax, %eax
je 0xb138
movq %r15, %rdi
leaq 0x3260(%rip), %rsi      # 0xe1fd
callq 0x2070
testl %eax, %eax
je 0xb170
movq %r15, %rdi
leaq 0x327d(%rip), %rsi      # 0xe231
callq 0x2070
testl %eax, %eax
je 0xb26b
movq %r15, %rdi
leaq 0x3270(%rip), %rsi      # 0xe23b
callq 0x2070
testl %eax, %eax
je 0xb341
movq %r15, %rdi
leaq 0x3269(%rip), %rsi      # 0xe24b
callq 0x2070
testl %eax, %eax
je 0xb2ed
movq %r15, %rdi
leaq 0x3255(%rip), %rsi      # 0xe24e
callq 0x2070
testl %eax, %eax
je 0xb2ed
movq %r15, %rdi
leaq 0x3257(%rip), %rsi      # 0xe267
callq 0x2070
testl %eax, %eax
je 0xb030
movq %r15, %rdi
leaq 0x3247(%rip), %rsi      # 0xe26a
callq 0x2070
testl %eax, %eax
jne 0xb5a5
incl %r13d
movq %rsp, %r12
movq %r12, %rdi
movl %ebp, %esi
movq %r14, %rdx
movl %r13d, %ecx
callq 0xb7de
movq %r12, %rdi
callq 0x9eac
movq %rax, 0xa8(%rbx)
movb $0x1, 0xb0(%rbx)
jmp 0xb2c9
movb $0x1, 0x4(%rbx)
jmp 0xb06b
movb $0x1, 0x5(%rbx)
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xb087
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21f0
incl %r13d
cmpl %ebp, %r13d
jl 0xaec9
jmp 0xb3a7
movb $0x0, 0x6(%rbx)
jmp 0xb06b
movb $0x0, 0x7(%rbx)
jmp 0xb06b
incl %r13d
cmpl %r13d, %ebp
jle 0xb481
movslq %r13d, %rax
movq (%r14,%rax,8), %rsi
movq %rsp, %rdi
leaq 0x58(%rsp), %rdx
callq 0xc2de
movq (%rsp), %rbx
callq 0x2040
movq %rax, %r12
movl (%rax), %eax
movl %eax, 0x50(%rsp)
movl $0x0, (%r12)
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
movl $0xa, %edx
callq 0x22c0
cmpq %rbx, 0x58(%rsp)
je 0xb4bf
movslq %eax, %rcx
cmpq %rax, %rcx
movq 0x28(%rsp), %rbx
jne 0xb4b3
movl (%r12), %ecx
cmpl $0x22, %ecx
je 0xb4b3
testl %ecx, %ecx
jne 0xb125
movl 0x50(%rsp), %ecx
movl %ecx, (%r12)
cmpb $0x0, 0x18(%rbx)
jne 0xb12f
movb $0x1, 0x18(%rbx)
movq %rax, 0x10(%rbx)
jmp 0xb2c9
incl %r13d
cmpl %r13d, %ebp
jle 0xb502
movslq %r13d, %rax
movq (%r14,%rax,8), %rsi
movq %rsp, %r12
movq %r12, %rdi
leaq 0x58(%rsp), %rdx
callq 0xc2de
movq %r12, %rdi
callq 0x9eac
movq %rax, 0x20(%rbx)
movb $0x1, 0x28(%rbx)
jmp 0xb2c9
incl %r13d
movq %rsp, %r12
movq %r12, %rdi
movl %ebp, %esi
movq %r14, %rdx
movl %r13d, %ecx
callq 0xb7de
movq %r12, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0xc31b
movl %eax, %r12d
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb1b3
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x98(%rsp), %rdi
movl %r12d, %esi
callq 0xc3ad
movq %rsp, %rdi
leaq 0x98(%rsp), %rsi
callq 0xa1ed
movq (%rsp), %r12
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xb220
movq %rsi, 0x50(%rsp)
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x50(%rsp), %rsi
movq %rbx, %rax
subq %r12, %rax
cmpq $0x20, %rax
jne 0xb534
movq 0x90(%rsp), %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rcx)
movups %xmm0, (%rcx)
movq 0x28(%rsp), %rax
movb $0x1, 0x78(%rax)
cmpq %r12, %rbx
je 0xb38d
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
jmp 0xb392
incl %r13d
movq %rsp, %r12
movq %r12, %rdi
movl %ebp, %esi
movq %r14, %rdx
movl %r13d, %ecx
callq 0xb7de
movq %r12, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0xc31b
movl %eax, %r12d
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb2ae
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rsp, %rdi
movl %r12d, %esi
callq 0xc3ad
movq 0x88(%rsp), %rdi
movq %rsp, %rsi
callq 0xc4c6
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb06b
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0xb06b
incl %r13d
movq %rsp, %r12
movq %r12, %rdi
movl %ebp, %esi
movq %r14, %rdx
movl %r13d, %ecx
callq 0xb7de
movq 0x80(%rsp), %rdi
movq %r12, %rsi
callq 0xc4c6
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb32e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21f0
cmpq $0x7, 0x88(%rbx)
ja 0xb06b
jmp 0xb56e
incl %r13d
movq %rsp, %r12
movq %r12, %rdi
movl %ebp, %esi
movq %r14, %rdx
movl %r13d, %ecx
callq 0xb7de
movq %r12, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0xc31b
movl %eax, %r12d
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb384
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21f0
movl %r12d, 0x8(%rbx)
jmp 0xb06b
testq %r12, %r12
je 0xb39d
subq %r12, %rsi
movq %r12, %rdi
callq 0x21f0
movq 0x28(%rsp), %rbx
jmp 0xb06b
cmpb $0x0, 0x78(%rbx)
je 0xb3b7
cmpb $0x1, 0x50(%rbx)
je 0xb44f
cmpl $0x0, (%rbx)
je 0xb3c5
cmpb $0x1, 0xb0(%rbx)
je 0xb431
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb3e0
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, 0x28(%rsp)
movl $0x10, %edi
callq 0x20f0
movq %rax, %r15
leaq 0x2d67(%rip), %rsi      # 0xe175
movq %rax, %rdi
callq 0x23a0
movq 0x6bb3(%rip), %rsi      # 0x11fd0
movq 0x6b9c(%rip), %rdx      # 0x11fc0
movq %r15, %rdi
callq 0x2360
jmp 0xb6f4
movl $0x10, %edi
callq 0x20f0
movq %rax, %r15
leaq 0x2e7f(%rip), %rsi      # 0xe2c4
movq %rax, %rdi
callq 0x23a0
jmp 0xb46b
movl $0x10, %edi
callq 0x20f0
movq %rax, %r15
leaq 0x2e2f(%rip), %rsi      # 0xe292
movq %rax, %rdi
callq 0x23a0
movq 0x6b5e(%rip), %rsi      # 0x11fd0
movq 0x6b47(%rip), %rdx      # 0x11fc0
movq %r15, %rdi
callq 0x2360
movl $0x10, %edi
callq 0x20f0
movq %rax, %r15
leaq 0x343d(%rip), %rsi      # 0xe8d2
movq %rax, %rdi
callq 0x23a0
movq 0x6b2c(%rip), %rsi      # 0x11fd0
movq 0x6b15(%rip), %rdx      # 0x11fc0
movq %r15, %rdi
callq 0x2360
leaq 0x3413(%rip), %rdi      # 0xe8cd
callq 0x22e0
leaq 0x3407(%rip), %rdi      # 0xe8cd
callq 0x2130
movl $0x10, %edi
callq 0x20f0
movq %rax, %r15
leaq 0x2cc2(%rip), %rsi      # 0xe1a1
movq %rax, %rdi
callq 0x23a0
movq 0x6ae2(%rip), %rsi      # 0x11fd0
movq 0x6acb(%rip), %rdx      # 0x11fc0
movq %r15, %rdi
callq 0x2360
jmp 0xb6f4
movl $0x10, %edi
callq 0x20f0
movq %rax, %r15
leaq 0x33bc(%rip), %rsi      # 0xe8d2
movq %rax, %rdi
callq 0x23a0
movq 0x6aab(%rip), %rsi      # 0x11fd0
movq 0x6a94(%rip), %rdx      # 0x11fc0
movq %r15, %rdi
callq 0x2360
movq %rsi, %rbx
movl $0x10, %edi
callq 0x20f0
movq %rax, %r15
leaq 0x2cc9(%rip), %rsi      # 0xe214
movq %rax, %rdi
callq 0x23a0
movq 0x6a76(%rip), %rsi      # 0x11fd0
movq 0x6a5f(%rip), %rdx      # 0x11fc0
movq %r15, %rdi
callq 0x2360
jmp 0xb6f4
movl $0x10, %edi
callq 0x20f0
movq %rax, %r15
leaq 0x2cd3(%rip), %rsi      # 0xe255
movq %rax, %rdi
callq 0x23a0
movq 0x6a3f(%rip), %rsi      # 0x11fd0
movq 0x6a28(%rip), %rdx      # 0x11fc0
movq %r15, %rdi
callq 0x2360
jmp 0xb6f4
movl $0x10, %edi
callq 0x20f0
movq %rax, %r15
leaq 0x2cc1(%rip), %rsi      # 0xe27a
movq %rsp, %rdi
leaq 0x30(%rsp), %rdx
callq 0xc51f
movb $0x1, %bl
movq %rsp, %rsi
movq %r15, %rdi
callq 0x2370
xorl %ebx, %ebx
movq 0x69f4(%rip), %rsi      # 0x11fd0
movq 0x69dd(%rip), %rdx      # 0x11fc0
movq %r15, %rdi
callq 0x2360
jmp 0xb6f4
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb60e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21f0
testb %bl, %bl
jne 0xb71c
jmp 0xb774
jmp 0xb719
jmp 0xb73e
jmp 0xb719
jmp 0xb726
jmp 0xb73e
jmp 0xb726
jmp 0xb73e
jmp 0xb73e
movq %rax, %r14
jmp 0xb653
movq %rax, %r14
movq %r15, %rdi
callq 0x2160
testq %r12, %r12
je 0xb774
movq %rbx, %rsi
subq %r12, %rsi
movq %r12, %rdi
jmp 0xb76f
jmp 0xb73e
jmp 0xb726
jmp 0xb73e
jmp 0xb73e
jmp 0xb719
jmp 0xb7ad
jmp 0xb731
movq %rax, %r14
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xb6ba
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0xb6ba
movq %rax, %r14
movq %r14, %rdi
callq 0x20c0
movl $0x10, %edi
callq 0x20f0
movq %rax, %r15
leaq 0x2b31(%rip), %rsi      # 0xe207
movq %rax, %rdi
callq 0x23a0
movq 0x68eb(%rip), %rsi      # 0x11fd0
movq 0x68d4(%rip), %rdx      # 0x11fc0
movq %r15, %rdi
callq 0x2360
movq %rax, %r14
jmp 0xb704
movq %rax, %r14
movq %r15, %rdi
callq 0x2160
callq 0x2340
jmp 0xb774
movq %rax, %rdi
callq 0xc4bb
jmp 0xb726
jmp 0xb73e
jmp 0xb73e
movq %rax, %r14
movq %r15, %rdi
callq 0x2160
jmp 0xb774
movq %rax, %r14
jmp 0xb759
jmp 0xb73e
jmp 0xb731
jmp 0xb7ad
movq %rax, %r14
movq %r15, %rdi
callq 0x2160
jmp 0xb7b0
movq %rax, %r14
jmp 0xb774
jmp 0xb7ad
jmp 0xb7ad
movq %rax, %r14
cmpl $0x0, (%r12)
jne 0xb759
movl 0x50(%rsp), %eax
movl %eax, (%r12)
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xb774
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xb7b0
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0xb7b0
jmp 0xb7ad
jmp 0xb7a8
movq %rax, %r14
movq %r15, %rdi
callq 0x2160
jmp 0xb7cb
movq %rbx, 0x28(%rsp)
movq %rax, %r14
jmp 0xb7cb
movq %rax, %r14
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xb7cb
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x28(%rsp), %rdi
callq 0xc5a8
movq %r14, %rdi
callq 0x2380
nop