// File: /workspace/github_c_makefile_star2_O3/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 0x8b79(%rip), %rdi      # 0xa066
callq 0x9153
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x8d4c
movl $0x40, %ebx
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
movl $0x0, 0xc(%rsp)
movl %ebp, %r14d
movq %r15, %rdi
callq 0x8d61
movl %eax, %r12d
movl $0x1, %ebp
cmpl $0x6a, %eax
jg 0x15ce
cmpl $0x3e, %r12d
jle 0x15ed
cmpl $0x3f, %r12d
je 0x1783
cmpl $0x61, %r12d
jne 0x1741
movq %r15, %rdi
callq 0x8e31
movq %rax, %r12
testq %rax, %rax
jne 0x1572
leaq 0x8d4f(%rip), %rdi      # 0xa2bc
callq 0x9178
movq %r12, %rdi
leaq 0x8d56(%rip), %rsi      # 0xa2d2
callq 0x8ed8
movl %r14d, %ebp
movl $0x0, 0xc(%rsp)
testl %eax, %eax
jne 0x151c
movq %r12, %rdi
leaq 0x8d5d(%rip), %rsi      # 0xa2f7
callq 0x8ed8
movl $0x1, 0xc(%rsp)
movl %r14d, %ebp
testl %eax, %eax
jne 0x151c
leaq 0x8d21(%rip), %rdi      # 0xa2da
callq 0x9178
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl %r14d, %ebp
jmp 0x151c
cmpl $0x6b, %r12d
je 0x16c4
cmpl $0x6c, %r12d
je 0x1643
cmpl $0x74, %r12d
je 0x151c
jmp 0x1741
cmpl $0x2d, %r12d
jne 0x173b
movq %r15, %rdi
callq 0x8e31
movq %rax, %r13
movq %rax, %rdi
leaq 0x8bd5(%rip), %rsi      # 0xa1e1
callq 0x8ed8
testl %eax, %eax
jne 0x151c
movq %r13, %rdi
leaq 0x8ca5(%rip), %rsi      # 0xa2c8
callq 0x8ed8
testl %eax, %eax
jne 0x1556
movq %r13, %rdi
leaq 0x8bab(%rip), %rsi      # 0xa1e5
callq 0x8ed8
testl %eax, %eax
je 0x16ad
movq %r15, %rdi
callq 0x8e31
movq %rax, %rdi
callq 0x8f1c
movl %eax, %r12d
movslq %eax, %rbx
cmpl $-0x4, %eax
jbe 0x1674
leaq 0x89af(%rip), %rax      # 0xa014
movslq 0xc(%rax,%rbx,4), %rdi
addq %rax, %rdi
callq 0x9178
jmp 0x1683
leal -0x201(%r12), %eax
cmpl $0xfffffe07, %eax       # imm = 0xFFFFFE07
jae 0x168f
leaq 0x8caf(%rip), %rdi      # 0xa339
callq 0x9178
testb $0x7, %r12b
je 0x16a1
leaq 0x8cc5(%rip), %rdi      # 0xa361
callq 0x9178
shrq $0x3, %rbx
movl %r14d, %ebp
jmp 0x151c
movq %r13, %rdi
leaq 0x8cdf(%rip), %rsi      # 0xa396
callq 0x8ed8
testl %eax, %eax
je 0x1770
movq %r15, %rdi
callq 0x8e31
movl $0x40, %esi
leaq 0x30(%rsp), %rdi
movq %rax, %rdx
callq 0x8fb5
movl %eax, %r12d
leal 0x4(%r12), %eax
cmpl $0x3, %eax
ja 0x172b
leaq 0x8912(%rip), %rcx      # 0xa004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8c88(%rip), %rdi      # 0xa38a
callq 0x9178
leaq 0x8c8c(%rip), %rdi      # 0xa39a
callq 0x9178
leaq 0x8c8d(%rip), %rdi      # 0xa3a7
callq 0x9178
leaq 0x8c9e(%rip), %rdi      # 0xa3c4
callq 0x9178
movslq %r12d, %rax
movq %rax, 0x10(%rsp)
movl %r14d, %ebp
jmp 0x151c
cmpl $-0x1, %r12d
je 0x17b4
movq 0xc8b0(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x8ab9(%rip), %rsi      # 0xa20b
movl %r12d, %edx
xorl %eax, %eax
callq 0x10b0
leaq 0x9a31(%rip), %rdi      # 0xb194
callq 0x9178
movl %r14d, %ebp
jmp 0x151c
movq %r13, %rdi
leaq 0x8a77(%rip), %rsi      # 0xa1f1
callq 0x8ed8
testl %eax, %eax
je 0x1792
xorl %eax, %eax
callq 0x915b
movl %r14d, %ebp
jmp 0x151c
testq %r13, %r13
je 0x1741
movq 0xc85a(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x8a4e(%rip), %rsi      # 0xa1f6
movq %r13, %rdx
xorl %eax, %eax
callq 0x10b0
jmp 0x175c
movl 0xc(%rsp), %ebp
cmpl $0x1, %ebp
jne 0x17e3
cmpq $0x0, 0x10(%rsp)
je 0x17d1
leaq 0x8a53(%rip), %rdi      # 0xa21f
callq 0x9178
cmpq $0x40, %rbx
je 0x17e3
leaq 0x8a61(%rip), %rdi      # 0xa23f
callq 0x9178
movl 0x18(%rsp), %eax
testl %eax, %eax
jne 0x1840
movq 0xc7e6(%rip), %r15      # 0xdfd8
movq (%r15), %rdx
leaq 0x8a5f(%rip), %rsi      # 0xa25b
xorl %edi, %edi
callq 0x10a0
movq (%r15), %rdx
cmpq %rdx, %rax
je 0x181a
leaq 0x8a4c(%rip), %rdi      # 0xa25e
callq 0x8e93
movq (%r15), %rdx
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
leaq 0x8a63(%rip), %rcx      # 0xa28d
leaq 0x30(%rsp), %r9
movl %ebp, %edi
movl %r14d, %esi
movq %rbx, %r8
callq 0x12dc
movl 0x18(%rsp), %eax
testl %eax, %eax
jle 0x18ff
leaq 0x30(%rsp), %r15
xorl %r13d, %r13d
movq 0x20(%rsp), %rax
movq (%rax,%r13,8), %rdi
leaq 0x89fb(%rip), %rsi      # 0xa25b
callq 0x1100
movq %rax, %r12
testq %rax, %rax
je 0x18ad
movq 0x20(%rsp), %rax
movq (%rax,%r13,8), %rcx
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
movl %ebp, %edi
movl %r14d, %esi
movq %r12, %rdx
movq %rbx, %r8
movq %r15, %r9
callq 0x12dc
movq %r12, %rdi
callq 0x1070
testl %eax, %eax
jne 0x18f0
incq %r13
movslq 0x18(%rsp), %rax
cmpq %rax, %r13
jl 0x1850
jmp 0x18ff
movq 0xc744(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movq (%rax,%r13,8), %rdx
leaq 0x89c8(%rip), %rsi      # 0xa28f
xorl %eax, %eax
callq 0x10b0
xorl %edi, %edi
callq 0x8e93
movq 0x20(%rsp), %rax
movq (%rax,%r13,8), %rcx
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
movl %ebp, %edi
movl %r14d, %esi
xorl %edx, %edx
jmp 0x1887
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x1140
jmp 0x189e
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq