// File: /workspace/github_c_makefile_star2_O2/LoupVaillant[P]Monocypher-Utils/src/hash.c
// Function: main
int main(int argc, char* argv[])
{
    int     algorithm   = BLAKE2B;
    int     tag         = 0;
    uint8_t key[64];
    size_t  key_size    = 0;
    size_t  digest_size = 64;

    set_usage_string(
        "Usage: hash [OPTION]... [FILE]... \n"
        "With no FILE, or when FILE is -, read standard input\n"
        "\n"
        "-a --algorithm      blake2b or sha512 (blake2b by default)\n"
        "-l --digest-length  digest length (8-512 bits, 512 bits by default)\n"
        "-k --key            secret key (in hexadecimal, no key by default)\n"
        "-t --tag            create a BSD-style checksum\n"
        "-? --help           display this help and exit\n");

    // Parse and validate arguments
    getopt_ctx ctx;
    OPT_BEGIN(ctx, argc, argv);
    OPT('t', "tag"        );  tag         = 1;
    OPT('a', "algorithm"  );  algorithm   = parse_algorithm  (&ctx     );
    OPT('l', "digest-size");  digest_size = parse_digest_size(&ctx     );
    OPT('k', "key"        );  key_size    = parse_key        (&ctx, key);
    OPT('?', "help"       );  usage();
    OPT_END;
    if (algorithm == SHA512) {
        if (key_size    !=  0) error("sha512 does not use secret keys");
        if (digest_size != 64) error("sha512 digests are 512 bits");
    }

    // parse input from stdin if no file is given
    if (ctx.argc == 0) {
        if(freopen(0, "rb", stdin) != stdin) {
            panic("Could not reopen standard input in binary mode");
        }
        hash_input(algorithm, tag, stdin, "-", digest_size, key, key_size);
    }

    // Read each input file in succession (if any)
    for (int i = 0; i < ctx.argc; i++) {
        FILE *input = fopen(ctx.argv[i], "rb");
        if (input == 0) {
            fprintf(stderr, "Could not open \"%s\": ", ctx.argv[i]);
            panic(0);
        }
        hash_input(algorithm, tag, input, ctx.argv[i],
                   digest_size, key, key_size);
        if (fclose(input)) {
            fprintf(stderr, "Could not close \"%s\": ", ctx.argv[i]);
            panic(0);
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x7c43(%rip), %rdi      # 0x9066
callq 0x8604
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x81f8
pushq $0x40
popq %rbx
movq $0x0, 0x10(%rsp)
xorl %ecx, %ecx
xorl %r14d, %r14d
movl %ecx, %ebp
movq %r15, %rdi
callq 0x820a
movl %eax, %r13d
cmpl $0x2d, %eax
je 0x14c3
cmpl $0x3f, %r13d
je 0x1680
cmpl $0x61, %r13d
je 0x14fb
cmpl $0x6b, %r13d
je 0x15f9
cmpl $0x6c, %r13d
je 0x157d
pushq $0x1
popq %rcx
cmpl $0x74, %r13d
je 0x144b
cmpl $-0x1, %r13d
je 0x16b7
movq 0xcb59(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x7d62(%rip), %rsi      # 0x920b
movl %r13d, %edx
xorl %eax, %eax
callq 0x10a0
leaq 0x8cda(%rip), %rdi      # 0xa194
callq 0x8629
movl %ebp, %ecx
jmp 0x144b
movq %r15, %rdi
callq 0x82f5
movq %rax, %r12
movq %rax, %rdi
leaq 0x7d09(%rip), %rsi      # 0x91e1
callq 0x83e7
pushq $0x1
popq %rcx
testl %eax, %eax
jne 0x144b
movq %r12, %rdi
leaq 0x7dd6(%rip), %rsi      # 0x92c8
callq 0x83e7
testl %eax, %eax
je 0x156a
movq %r15, %rdi
callq 0x82f5
movq %rax, %r12
testq %rax, %rax
jne 0x1517
leaq 0x7daa(%rip), %rdi      # 0x92bc
callq 0x8629
movq %r12, %rdi
leaq 0x7db1(%rip), %rsi      # 0x92d2
callq 0x83e7
movl %ebp, %ecx
movl $0x0, %r14d
testl %eax, %eax
jne 0x144b
movq %r12, %rdi
leaq 0x7db7(%rip), %rsi      # 0x92f7
callq 0x83e7
movl %ebp, %ecx
pushq $0x1
popq %r14
testl %eax, %eax
jne 0x144b
leaq 0x7d80(%rip), %rdi      # 0x92da
callq 0x8629
movl %ebp, %ecx
pushq $-0x1
popq %r14
jmp 0x144b
movq %r12, %rdi
leaq 0x7c71(%rip), %rsi      # 0x91e5
callq 0x83e7
testl %eax, %eax
je 0x15e6
movq %r15, %rdi
callq 0x82f5
movq %rax, %rdi
callq 0x841a
movl %eax, %r12d
movslq %eax, %rbx
cmpl $-0x4, %eax
jbe 0x15ae
leaq 0x7a75(%rip), %rax      # 0x9014
movslq 0xc(%rax,%rbx,4), %rdi
addq %rax, %rdi
callq 0x8629
jmp 0x15bd
leal -0x201(%r12), %eax
cmpl $0xfffffe07, %eax       # imm = 0xFFFFFE07
jae 0x15c9
leaq 0x7d75(%rip), %rdi      # 0x9339
callq 0x8629
testb $0x7, %r12b
je 0x15db
leaq 0x7d8b(%rip), %rdi      # 0x9361
callq 0x8629
shrq $0x3, %rbx
movl %ebp, %ecx
jmp 0x144b
movq %r12, %rdi
leaq 0x7da6(%rip), %rsi      # 0x9396
callq 0x83e7
testl %eax, %eax
je 0x166d
movq %r15, %rdi
callq 0x82f5
leaq 0x30(%rsp), %rdi
pushq $0x40
popq %rsi
movq %rax, %rdx
callq 0x84b3
movl %eax, %r12d
leal 0x4(%r12), %eax
cmpl $0x3, %eax
ja 0x165e
leaq 0x79df(%rip), %rcx      # 0x9004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x7d55(%rip), %rdi      # 0x938a
callq 0x8629
leaq 0x7d59(%rip), %rdi      # 0x939a
callq 0x8629
leaq 0x7d5a(%rip), %rdi      # 0x93a7
callq 0x8629
leaq 0x7d6b(%rip), %rdi      # 0x93c4
callq 0x8629
movslq %r12d, %rax
movq %rax, 0x10(%rsp)
movl %ebp, %ecx
jmp 0x144b
movq %r12, %rdi
leaq 0x7b7a(%rip), %rsi      # 0x91f1
callq 0x83e7
testl %eax, %eax
je 0x168e
xorl %eax, %eax
callq 0x860c
movl %ebp, %ecx
jmp 0x144b
testq %r12, %r12
je 0x1498
movq 0xc95a(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x7b4e(%rip), %rsi      # 0x91f6
movq %r12, %rdx
xorl %eax, %eax
callq 0x10a0
jmp 0x14b3
cmpl $0x1, %r14d
jne 0x16e3
cmpq $0x0, 0x10(%rsp)
je 0x16d1
leaq 0x7b53(%rip), %rdi      # 0x921f
callq 0x8629
cmpq $0x40, %rbx
je 0x16e3
leaq 0x7b61(%rip), %rdi      # 0x923f
callq 0x8629
cmpl $0x0, 0x18(%rsp)
jne 0x173b
movq 0xc8e7(%rip), %r15      # 0xdfd8
movq (%r15), %rdx
leaq 0x7b60(%rip), %rsi      # 0x925b
xorl %edi, %edi
callq 0x1090
movq (%r15), %rdx
cmpq %rdx, %rax
je 0x1719
leaq 0x7b4d(%rip), %rdi      # 0x925e
callq 0x837e
movq (%r15), %rdx
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
leaq 0x7b64(%rip), %rcx      # 0x928d
leaq 0x30(%rsp), %r9
movl %r14d, %edi
movl %ebp, %esi
movq %rbx, %r8
callq 0x121c
leaq 0x30(%rsp), %r13
xorl %r15d, %r15d
movslq 0x18(%rsp), %rax
cmpq %rax, %r15
jge 0x17f8
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rdi
leaq 0x7afa(%rip), %rsi      # 0x925b
callq 0x10f0
movq %rax, %r12
testq %rax, %rax
je 0x17a4
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rcx
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
movl %r14d, %edi
movl %ebp, %esi
movq %r12, %rdx
movq %rbx, %r8
movq %r13, %r9
callq 0x121c
movq %r12, %rdi
callq 0x1070
testl %eax, %eax
jne 0x17ce
incq %r15
jmp 0x1743
movq 0xc84d(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rdx
leaq 0x7ad1(%rip), %rsi      # 0x928f
xorl %eax, %eax
callq 0x10a0
xorl %edi, %edi
callq 0x837e
jmp 0x176e
movq 0xc823(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rdx
leaq 0x7abd(%rip), %rsi      # 0x92a5
xorl %eax, %eax
callq 0x10a0
xorl %edi, %edi
callq 0x837e
jmp 0x179f
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)