// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movq %rsi, %rbx
movl %edi, %ebp
xorl %eax, %eax
callq 0x8ed5
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
xorl %eax, %eax
callq 0x8ed5
movq %rax, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
leaq 0x7d5c(%rip), %rdi      # 0x9004
callq 0x8f80
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x8b44
movq %r14, %rdi
callq 0x8b59
cmpl $-0x1, %eax
je 0x1591
movl %eax, %r15d
movl $0x19000, (%rsp)        # imm = 0x19000
movl $0x3, %ebp
movl $0x40, %ebx
leaq 0x40(%rsp), %r12
leaq 0x825c(%rip), %r14      # 0x954c
movl $0x0, 0x4(%rsp)
cmpl $0x2d, %r15d
jne 0x130b
movq %r12, %rdi
callq 0x8c21
movq %rax, %r13
jmp 0x130e
xorl %r13d, %r13d
cmpl $0x6c, %r15d
je 0x132d
cmpl $0x2d, %r15d
jne 0x136d
movq %r13, %rdi
leaq 0x7ef2(%rip), %rsi      # 0x9216
callq 0x8cc8
testl %eax, %eax
je 0x136d
movq %r12, %rdi
callq 0x8c21
movq %rax, %rdi
callq 0x8d0c
movl %eax, %ebx
cmpl $-0x3, %eax
jb 0x1354
movslq %ebx, %rax
movslq 0xc(%r14,%rax,4), %rdi
addq %r14, %rdi
callq 0x8fa5
cmpl $0x3, %ebx
jg 0x1365
leaq 0x7f98(%rip), %rdi      # 0x92f8
callq 0x8fa5
movslq %ebx, %rbx
jmp 0x1438
cmpl $0x74, %r15d
je 0x138c
cmpl $0x2d, %r15d
jne 0x13be
movq %r13, %rdi
leaq 0x7e9f(%rip), %rsi      # 0x9222
callq 0x8cc8
testl %eax, %eax
je 0x13be
movq %r12, %rdi
callq 0x8c21
movq %rax, %rdi
callq 0x8d0c
movl %eax, %ebp
cmpl $-0x3, %eax
je 0x142c
cmpl $-0x2, %ebp
je 0x1423
cmpl $-0x1, %ebp
jne 0x1438
leaq 0x7f59(%rip), %rdi      # 0x9315
jmp 0x1433
cmpl $0x6b, %r15d
je 0x13e1
cmpl $0x2d, %r15d
jne 0x14a0
movq %r13, %rdi
leaq 0x7e58(%rip), %rsi      # 0x9230
callq 0x8cc8
testl %eax, %eax
je 0x1451
movq %r12, %rdi
callq 0x8c21
movq %rax, %rdi
callq 0x8d0c
movl %eax, %r15d
cmpl $-0x3, %eax
jb 0x1410
movslq %r15d, %rax
leaq 0x8155(%rip), %rcx      # 0x9558
movslq 0xc(%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x8fa5
movl %r15d, (%rsp)
cmpl $0x7, %r15d
jg 0x1438
leaq 0x7fba(%rip), %rdi      # 0x93db
jmp 0x1433
leaq 0x7f0c(%rip), %rdi      # 0x9336
jmp 0x1433
leaq 0x7f33(%rip), %rdi      # 0x9366
callq 0x8fa5
movq %r12, %rdi
callq 0x8b59
movl %eax, %r15d
cmpl $-0x1, %eax
jne 0x12f8
jmp 0x15aa
movq %r13, %rdi
leaq 0x7fa8(%rip), %rsi      # 0x9403
callq 0x8cc8
testl %eax, %eax
je 0x14a0
movq %r12, %rdi
callq 0x8c21
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x8eda
cmpl $-0x4, %eax
jb 0x1494
addl $0x4, %eax
leaq 0x80dc(%rip), %rcx      # 0x9564
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x8fa5
movups 0x8(%rsp), %xmm0
movups %xmm0, 0x30(%rsp)
jmp 0x1438
cmpl $0x61, %r15d
je 0x14bf
cmpl $0x2d, %r15d
jne 0x14fe
movq %r13, %rdi
leaq 0x7d87(%rip), %rsi      # 0x923d
callq 0x8cc8
testl %eax, %eax
je 0x14fe
movq %r12, %rdi
callq 0x8c21
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x8eda
cmpl $-0x4, %eax
jb 0x14ef
addl $0x4, %eax
leaq 0x8091(%rip), %rcx      # 0x9574
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x8fa5
movups 0x8(%rsp), %xmm0
movups %xmm0, 0x20(%rsp)
jmp 0x1438
cmpl $0x69, %r15d
je 0x151d
cmpl $0x2d, %r15d
jne 0x1527
movq %r13, %rdi
leaq 0x7d39(%rip), %rsi      # 0x924d
callq 0x8cc8
testl %eax, %eax
je 0x1527
orl $0x20, 0x4(%rsp)
jmp 0x1438
cmpl $0x3f, %r15d
je 0x1546
cmpl $0x2d, %r15d
jne 0x1552
movq %r13, %rdi
leaq 0x7d16(%rip), %rsi      # 0x9253
callq 0x8cc8
testl %eax, %eax
je 0x1552
xorl %eax, %eax
callq 0x8f88
jmp 0x1438
movq 0xba9f(%rip), %rax      # 0xcff8
movq (%rax), %rdi
testq %r13, %r13
jne 0x1574
leaq 0x7d05(%rip), %rsi      # 0x926d
movl %r15d, %edx
xorl %eax, %eax
callq 0x1090
jmp 0x1585
leaq 0x7cdd(%rip), %rsi      # 0x9258
movq %r13, %rdx
xorl %eax, %eax
callq 0x1090
leaq 0x8db8(%rip), %rdi      # 0xa344
jmp 0x1433
movl $0x0, 0x4(%rsp)
movl $0x40, %ebx
movl $0x3, %ebp
movl $0x19000, (%rsp)        # imm = 0x19000
cmpl $0x0, 0x40(%rsp)
jne 0x15bd
leaq 0x7f1b(%rip), %rdi      # 0x94d3
callq 0x8fa5
cmpl $0x0, 0x40(%rsp)
movl (%rsp), %r15d
jg 0x15d4
leaq 0x7f11(%rip), %rdi      # 0x94e0
callq 0x8fa5
movq 0x48(%rsp), %rax
movq (%rax), %rsi
leaq 0x8(%rsp), %rdi
callq 0x8eda
addl $0x4, %eax
cmpl $0x2, %eax
ja 0x1603
movl %eax, %eax
leaq 0x7f8d(%rip), %rcx      # 0x9584
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x8fa5
movl %ebp, 0x1c(%rsp)
cmpq $0x7, 0x10(%rsp)
ja 0x161b
leaq 0x7f26(%rip), %rdi      # 0x953c
callq 0x8fa5
movups 0x8(%rsp), %xmm0
movups %xmm0, 0x8(%rsp)
movl %r15d, %r14d
shll $0xa, %r14d
movq %r14, %rdi
callq 0x8c64
movq %rax, %r12
movq %rbx, %rdi
callq 0x8c64
movl %r15d, (%rsp)
movq %rax, %r15
leaq 0x7c34(%rip), %rdi      # 0x9281
movq %r12, %rsi
movq %r14, %rdx
movl 0x4(%rsp), %ecx
callq 0x1080
testq %rax, %rax
movq %rbx, %rbp
jne 0x1670
leaq 0x7c23(%rip), %rdi      # 0x928e
callq 0x8c83
movq %r12, %rdi
callq 0x1050
leaq 0x8(%rsp), %rcx
movl 0x8(%rcx), %r10d
leaq 0x30(%rsp), %r13
movl 0x8(%r13), %r11d
leaq 0x20(%rsp), %r14
movl 0x8(%r14), %ebx
subq $0x8, %rsp
movq %r15, %rdi
movl %ebp, %esi
movq %r12, %rdx
movl 0x8(%rsp), %ecx
movl 0x24(%rsp), %r8d
movq %r12, %r9
pushq %rbx
pushq (%r14)
pushq %r11
pushq (%r13)
pushq %r10
leaq 0x38(%rsp), %rbx
pushq (%rbx)
pushq %rax
callq 0x3be6
addq $0x40, %rsp
movq %r12, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x8f5e
movq %r14, %rdi
callq 0x8f5e
movq %rbx, %rdi
callq 0x8f5e
movq %r15, %rdi
movq %rbp, %rsi
callq 0x8d78
movl $0xa, %edi
callq 0x1040
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop