// File: /workspace/github_c_makefile_star2_O1/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 0x8b44(%rip), %rdi      # 0xa066
callq 0x9188
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x8d4c
movq %r14, %rdi
callq 0x8d61
cmpl $-0x1, %eax
je 0x17d4
movl %eax, %r13d
movl $0x40, %eax
movq %rax, 0x8(%rsp)
leaq 0x18(%rsp), %r15
xorl %r14d, %r14d
xorl %ebp, %ebp
movq $0x0, 0x10(%rsp)
cmpl $0x2d, %r13d
jne 0x157d
movq %r15, %rdi
callq 0x8e29
movq %rax, %r12
jmp 0x1580
xorl %r12d, %r12d
cmpl $0x74, %r13d
je 0x159f
cmpl $0x2d, %r13d
jne 0x15b9
movq %r12, %rdi
leaq 0x8c4b(%rip), %rsi      # 0xa1e1
callq 0x8ed0
testl %eax, %eax
je 0x15b9
movl $0x1, %ebp
movq %r15, %rdi
callq 0x8d61
movl %eax, %r13d
cmpl $-0x1, %eax
jne 0x156a
jmp 0x17ec
cmpl $0x61, %r13d
je 0x15d8
cmpl $0x2d, %r13d
jne 0x163a
movq %r12, %rdi
leaq 0x8cf9(%rip), %rsi      # 0xa2c8
callq 0x8ed0
testl %eax, %eax
je 0x163a
movq %r15, %rdi
callq 0x8e29
movq %rax, %rbx
testq %rax, %rax
jne 0x15f4
leaq 0x8ccd(%rip), %rdi      # 0xa2bc
callq 0x91ad
movq %rbx, %rdi
leaq 0x8cd4(%rip), %rsi      # 0xa2d2
callq 0x8ed0
xorl %r14d, %r14d
testl %eax, %eax
jne 0x15a4
movq %rbx, %rdi
leaq 0x8ce3(%rip), %rsi      # 0xa2f7
callq 0x8ed0
movl $0x1, %r14d
testl %eax, %eax
jne 0x15a4
leaq 0x8cb0(%rip), %rdi      # 0xa2da
callq 0x91ad
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x15a4
cmpl $0x6c, %r13d
je 0x165d
cmpl $0x2d, %r13d
jne 0x16ce
movq %r12, %rdi
leaq 0x8b91(%rip), %rsi      # 0xa1e5
callq 0x8ed0
testl %eax, %eax
je 0x16ce
movq %r15, %rdi
callq 0x8e29
movq %rax, %rdi
callq 0x8f14
movl %eax, %r12d
cltq
movq %rax, 0x8(%rsp)
cmpl $-0x3, %r12d
jb 0x1696
movq 0x8(%rsp), %rax
leaq 0x898b(%rip), %rcx      # 0xa014
movslq 0xc(%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x91ad
leal -0x201(%r12), %eax
cmpl $0xfffffe06, %eax       # imm = 0xFFFFFE06
ja 0x16b1
leaq 0x8c8d(%rip), %rdi      # 0xa339
callq 0x91ad
testb $0x7, %r12b
je 0x16c3
leaq 0x8ca3(%rip), %rdi      # 0xa361
callq 0x91ad
shrq $0x3, 0x8(%rsp)
jmp 0x15a4
cmpl $0x6b, %r13d
je 0x16f1
cmpl $0x2d, %r13d
jne 0x1765
movq %r12, %rdi
leaq 0x8cae(%rip), %rsi      # 0xa396
callq 0x8ed0
testl %eax, %eax
je 0x1765
movq %r15, %rdi
callq 0x8e29
movl $0x40, %esi
leaq 0x30(%rsp), %rdi
movq %rax, %rdx
callq 0x8fc0
movl %eax, %r12d
leal 0x4(%r12), %eax
cmpl $0x3, %eax
ja 0x1758
leaq 0x88e5(%rip), %rcx      # 0xa004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8c5b(%rip), %rdi      # 0xa38a
callq 0x91ad
leaq 0x8c5f(%rip), %rdi      # 0xa39a
callq 0x91ad
leaq 0x8c60(%rip), %rdi      # 0xa3a7
callq 0x91ad
leaq 0x8c71(%rip), %rdi      # 0xa3c4
callq 0x91ad
movslq %r12d, %rax
movq %rax, 0x10(%rsp)
jmp 0x15a4
cmpl $0x3f, %r13d
je 0x1784
cmpl $0x2d, %r13d
jne 0x1790
movq %r12, %rdi
leaq 0x8a76(%rip), %rsi      # 0xa1f1
callq 0x8ed0
testl %eax, %eax
je 0x1790
xorl %eax, %eax
callq 0x9190
jmp 0x15a4
movq 0xc861(%rip), %rax      # 0xdff8
movq (%rax), %rdi
testq %r12, %r12
jne 0x17b2
leaq 0x8a65(%rip), %rsi      # 0xa20b
movl %r13d, %edx
xorl %eax, %eax
callq 0x10b0
jmp 0x17c3
leaq 0x8a3d(%rip), %rsi      # 0xa1f6
movq %r12, %rdx
xorl %eax, %eax
callq 0x10b0
leaq 0x99ca(%rip), %rdi      # 0xb194
callq 0x91ad
jmp 0x15a4
movq $0x0, 0x10(%rsp)
movl $0x40, %eax
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
cmpl $0x1, %r14d
jne 0x181a
cmpq $0x0, 0x10(%rsp)
je 0x1806
leaq 0x8a1e(%rip), %rdi      # 0xa21f
callq 0x91ad
cmpq $0x40, 0x8(%rsp)
je 0x181a
leaq 0x8a2a(%rip), %rdi      # 0xa23f
callq 0x91ad
cmpl $0x0, 0x18(%rsp)
jne 0x1871
movq 0xc7b0(%rip), %rbx      # 0xdfd8
movq (%rbx), %rdx
leaq 0x8a29(%rip), %rsi      # 0xa25b
xorl %edi, %edi
callq 0x10a0
cmpq (%rbx), %rax
je 0x184a
leaq 0x8a19(%rip), %rdi      # 0xa25e
callq 0x8e8b
movq (%rbx), %rdx
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
leaq 0x8a30(%rip), %rcx      # 0xa28d
leaq 0x30(%rsp), %r9
movl %r14d, %edi
movl %ebp, %esi
movq 0x8(%rsp), %r8
callq 0x130c
cmpl $0x0, 0x18(%rsp)
jle 0x1904
xorl %r12d, %r12d
leaq 0x89d5(%rip), %r13      # 0xa25b
leaq 0x30(%rsp), %r15
movq 0x20(%rsp), %rax
movq (%rax,%r12,8), %rdi
movq %r13, %rsi
callq 0x1100
movq %rax, %rbx
testq %rax, %rax
je 0x18e6
movq 0x20(%rsp), %rax
movq (%rax,%r12,8), %rcx
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
movl %r14d, %edi
movl %ebp, %esi
movq %rbx, %rdx
movq 0x8(%rsp), %r8
movq %r15, %r9
callq 0x130c
movq %rbx, %rdi
callq 0x1070
testl %eax, %eax
jne 0x18f5
incq %r12
movslq 0x18(%rsp), %rax
cmpq %rax, %r12
jl 0x188b
jmp 0x1904
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x1140
jmp 0x18a4
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x116f
jmp 0x18d7
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)