// File: /workspace/github_c_makefile_star2_O3/LoupVaillant[P]Monocypher-Utils/src/pwhash.c
// Function: main
int main(int argc, char* argv[])
{
    size_t   digest_size   = 64;
    uint32_t nb_iterations = 3;
    uint32_t nb_kibybytes  = 102400; // 100 Mib
    vector   key           = new_vector();
    vector   ad            = new_vector();
    int      rpp_flags     = 0;

    set_usage_string(
        "Usage: pwhash [OPTION]... salt\n"
        "Read the password from standard input\n"
        "The salt must be at least 8 bytes long (16 hex digits)\n"
        "\n"
        "-l --digest-size      digest length in bytes (32 bytes by default)\n"
        "-t --nb-iterations    number of iterations (default 3)\n"
        "-m --nb-kilobytes     memory usage in KiB (default 100MiB)\n"
        "-k --key              secret key (hexadecimal, default none)\n"
        "-a --additional-data  additionnal data (hexadecimal, default none)\n"
        "-i --stdin            read password from stdin"
        "-? --help             display this help and exit\n");

    // Parse and validate arguments
    getopt_ctx ctx;
    OPT_BEGIN(ctx, argc, argv);
    OPT('l', "digest-size"    );  digest_size   = parse_digest(&ctx);
    OPT('t', "nb-iterations"  );  nb_iterations = parse_nb_it (&ctx);
    OPT('k', "nb-kilobytes"   );  nb_kibybytes  = parse_kib   (&ctx);
    OPT('k', "key"            );  key           = parse_key   (&ctx);
    OPT('a', "additional-data");  ad            = parse_ad    (&ctx);
    OPT('i', "stdin"          );  rpp_flags    |= RPP_STDIN;
    OPT('?', "help"           );  usage();
    OPT_END;
    vector   salt      = parse_salt(&ctx);
    size_t   work_size = 1024 * nb_kibybytes;
    void    *work_area = alloc(work_size);
    uint8_t *digest    = alloc(digest_size);

    // read password
    if (readpassphrase("Passphrase: ", work_area, work_size, rpp_flags) == 0) {
        panic("Could not read password");
    }
    size_t password_size = strlen(work_area);

    // hash password
    crypto_argon2i_general(digest, digest_size,
                           work_area, nb_kibybytes,
                           nb_iterations,
                           work_area  , password_size,
                           salt.buffer, salt.size,
                           key .buffer, key .size,
                           ad  .buffer, ad  .size);

    // free resources
    free(work_area);
    free_vector(&key );
    free_vector(&ad  );
    free_vector(&salt);

    // print password
    print_buffer(digest, digest_size);
    printf("\n");

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %rbx
movl %edi, %ebp
xorl %eax, %eax
callq 0x8edc
movq %rax, 0x28(%rsp)
movq %rax, 0x50(%rsp)
movq %rdx, 0x20(%rsp)
movq %rdx, 0x58(%rsp)
xorl %eax, %eax
callq 0x8edc
movq %rax, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq %rdx, 0x30(%rsp)
movq %rdx, 0x48(%rsp)
leaq 0x7d45(%rip), %rdi      # 0x9004
callq 0x8f87
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x8b80
movl $0x40, %r15d
movl $0x3, %ebp
movl $0x19000, %ebx          # imm = 0x19000
movl $0x0, 0x1c(%rsp)
movq %r14, %rdi
callq 0x8b95
movl %eax, %r12d
cmpl $0x68, %eax
jle 0x1353
cmpl $0x6b, %r12d
jg 0x13c4
cmpl $0x69, %r12d
je 0x1590
cmpl $0x6b, %r12d
jne 0x153a
movq %r14, %rdi
callq 0x8c65
movq %rax, %rdi
callq 0x8d50
movl %eax, %ebx
cmpl $-0x4, %eax
jbe 0x147e
movslq %ebx, %rax
leaq 0x8223(%rip), %rcx      # 0x9564
movslq 0xc(%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x8fac
jmp 0x1487
cmpl $0x3e, %r12d
jle 0x140b
cmpl $0x3f, %r12d
je 0x15ad
cmpl $0x61, %r12d
jne 0x153a
movq %r14, %rdi
callq 0x8c65
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x8ee1
cmpl $-0x4, %eax
jb 0x13a1
addl $0x4, %eax
leaq 0x81eb(%rip), %rcx      # 0x9580
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x8fac
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rax, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq %rcx, 0x30(%rsp)
movq %rcx, 0x48(%rsp)
jmp 0x12ee
cmpl $0x6c, %r12d
je 0x1433
cmpl $0x74, %r12d
jne 0x153a
movq %r14, %rdi
callq 0x8c65
movq %rax, %rdi
callq 0x8d50
movl %eax, %ebp
cmpl $-0x3, %eax
jb 0x12ee
movslq %ebp, %rax
leaq 0x815f(%rip), %rcx      # 0x9558
movslq 0xc(%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x8fac
jmp 0x12ee
cmpl $0x2d, %r12d
jne 0x1530
movq %r14, %rdi
callq 0x8c65
movq %rax, %r13
movq %rax, %rdi
leaq 0x7dec(%rip), %rsi      # 0x9216
callq 0x8d0c
testl %eax, %eax
je 0x1498
movq %r14, %rdi
callq 0x8c65
movq %rax, %rdi
callq 0x8d50
movl %eax, %r12d
cmpl $-0x4, %eax
jbe 0x1464
movslq %r12d, %rax
leaq 0x80f7(%rip), %rcx      # 0x954c
movslq 0xc(%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x8fac
jmp 0x146a
cmpl $0x4, %r12d
jge 0x1476
leaq 0x7e87(%rip), %rdi      # 0x92f8
callq 0x8fac
movslq %r12d, %r15
jmp 0x12ee
cmpl $0x8, %ebx
jge 0x12ee
leaq 0x7f4d(%rip), %rdi      # 0x93db
callq 0x8fac
jmp 0x12ee
movq %r13, %rdi
leaq 0x7d80(%rip), %rsi      # 0x9222
callq 0x8d0c
testl %eax, %eax
jne 0x13d4
movq %r13, %rdi
leaq 0x7d77(%rip), %rsi      # 0x9230
callq 0x8d0c
testl %eax, %eax
jne 0x131c
movq %r13, %rdi
leaq 0x7f33(%rip), %rsi      # 0x9403
callq 0x8d0c
testl %eax, %eax
je 0x1566
movq %r14, %rdi
callq 0x8c65
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x8ee1
cmpl $-0x4, %eax
jb 0x150d
addl $0x4, %eax
leaq 0x806f(%rip), %rcx      # 0x9570
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x8fac
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rax, 0x28(%rsp)
movq %rax, 0x50(%rsp)
movq %rcx, 0x20(%rsp)
movq %rcx, 0x58(%rsp)
jmp 0x12ee
cmpl $-0x1, %r12d
je 0x15e2
movq 0xbab7(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x7d22(%rip), %rsi      # 0x926d
movl %r12d, %edx
xorl %eax, %eax
callq 0x1090
leaq 0x8df8(%rip), %rdi      # 0xa354
callq 0x8fac
jmp 0x12ee
movq %r13, %rdi
leaq 0x7ccd(%rip), %rsi      # 0x923d
callq 0x8d0c
testl %eax, %eax
jne 0x1371
movq %r13, %rdi
leaq 0x7cc6(%rip), %rsi      # 0x924d
callq 0x8d0c
testl %eax, %eax
je 0x159a
orl $0x20, 0x1c(%rsp)
jmp 0x12ee
movq %r13, %rdi
leaq 0x7caf(%rip), %rsi      # 0x9253
callq 0x8d0c
testl %eax, %eax
je 0x15b9
xorl %eax, %eax
callq 0x8f8f
jmp 0x12ee
testq %r13, %r13
je 0x153a
movq 0xba2f(%rip), %rax      # 0xcff8
movq (%rax), %rdi
leaq 0x7c85(%rip), %rsi      # 0x9258
movq %r13, %rdx
xorl %eax, %eax
callq 0x1090
jmp 0x1555
movl 0x70(%rsp), %eax
testl %eax, %eax
jne 0x15fa
leaq 0x7ee2(%rip), %rdi      # 0x94d3
callq 0x8fac
movl 0x70(%rsp), %eax
testl %eax, %eax
jg 0x160a
leaq 0x7edb(%rip), %rdi      # 0x94e0
callq 0x8fac
movq 0x78(%rsp), %rax
movq (%rax), %rsi
leaq 0x8(%rsp), %rdi
callq 0x8ee1
addl $0x4, %eax
cmpl $0x2, %eax
ja 0x1639
movl %eax, %eax
leaq 0x7f63(%rip), %rcx      # 0x9590
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x8fac
movq 0x10(%rsp), %r14
cmpq $0x7, %r14
ja 0x1655
leaq 0x7ef1(%rip), %rdi      # 0x953c
callq 0x8fac
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rax
movq %rax, 0x60(%rsp)
movq %rax, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movl %ebx, %r13d
shll $0xa, %r13d
movq %r13, %rdi
callq 0x8ca8
movq %rax, %r12
movq %r15, %rdi
callq 0x8ca8
movq %rax, 0x68(%rsp)
leaq 0x7bf2(%rip), %rdi      # 0x9281
movq %r12, %rsi
movq %r13, %rdx
movl 0x1c(%rsp), %ecx
callq 0x1080
testq %rax, %rax
jne 0x16af
leaq 0x7be4(%rip), %rdi      # 0x928e
callq 0x8cc7
movq %r12, %rdi
callq 0x1050
subq $0x8, %rsp
movq 0x70(%rsp), %r13
movq %r13, %rdi
movl %r15d, %esi
movq %r12, %rdx
movl %ebx, %ecx
movl %ebp, %r8d
movq %r12, %r9
pushq 0x38(%rsp)
pushq 0x48(%rsp)
pushq 0x38(%rsp)
pushq 0x48(%rsp)
pushq %r14
pushq 0x90(%rsp)
pushq %rax
callq 0x3bcd
addq $0x40, %rsp
movq %r12, %rdi
callq 0x1030
leaq 0x50(%rsp), %rdi
callq 0x8f65
leaq 0x40(%rsp), %rdi
callq 0x8f65
leaq 0x8(%rsp), %rdi
callq 0x8f65
movq %r13, %rdi
movq %r15, %rsi
callq 0x8da9
movl $0xa, %edi
callq 0x1040
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop