// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
movl $0x0, -0x24(%rbp)
movl %edi, -0x28(%rbp)
movq %rsi, -0x30(%rbp)
movq $0x40, -0x38(%rbp)
movl $0x3, -0x3c(%rbp)
movl $0x19000, -0x40(%rbp)   # imm = 0x19000
movb $0x0, %al
callq 0x11d50
movq %rax, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
movb $0x0, %al
callq 0x11d50
movq %rax, -0x60(%rbp)
movq %rdx, -0x58(%rbp)
movl $0x0, -0x64(%rbp)
leaq 0x10dd2(%rip), %rdi     # 0x12004
callq 0x11e30
movl -0x28(%rbp), %esi
movq -0x30(%rbp), %rdx
leaq -0x80(%rbp), %rdi
callq 0x11440
leaq -0x80(%rbp), %rdi
callq 0x11490
movl %eax, -0x84(%rbp)
cmpl $-0x1, %eax
je 0x14e3
cmpl $0x2d, -0x84(%rbp)
jne 0x127a
leaq -0x80(%rbp), %rdi
callq 0x11730
movq %rax, -0xe8(%rbp)
jmp 0x1285
xorl %eax, %eax
movq %rax, -0xe8(%rbp)
jmp 0x1285
movq -0xe8(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpl $0x6c, -0x84(%rbp)
je 0x12bd
cmpl $0x2d, -0x84(%rbp)
jne 0x12d5
movq -0x90(%rbp), %rdi
leaq 0x10f63(%rip), %rsi     # 0x12216
callq 0x118e0
cmpl $0x0, %eax
je 0x12d5
jmp 0x12bf
jmp 0x12c1
leaq -0x80(%rbp), %rdi
callq 0x1650
cltq
movq %rax, -0x38(%rbp)
jmp 0x1247
cmpl $0x74, -0x84(%rbp)
je 0x12ff
cmpl $0x2d, -0x84(%rbp)
jne 0x1314
movq -0x90(%rbp), %rdi
leaq 0x10f2d(%rip), %rsi     # 0x12222
callq 0x118e0
cmpl $0x0, %eax
je 0x1314
jmp 0x1301
jmp 0x1303
leaq -0x80(%rbp), %rdi
callq 0x16d0
movl %eax, -0x3c(%rbp)
jmp 0x1247
cmpl $0x6b, -0x84(%rbp)
je 0x133e
cmpl $0x2d, -0x84(%rbp)
jne 0x1353
movq -0x90(%rbp), %rdi
leaq 0x10efc(%rip), %rsi     # 0x12230
callq 0x118e0
cmpl $0x0, %eax
je 0x1353
jmp 0x1340
jmp 0x1342
leaq -0x80(%rbp), %rdi
callq 0x1730
movl %eax, -0x40(%rbp)
jmp 0x1247
cmpl $0x6b, -0x84(%rbp)
je 0x137d
cmpl $0x2d, -0x84(%rbp)
jne 0x13b3
movq -0x90(%rbp), %rdi
leaq 0x11090(%rip), %rsi     # 0x12403
callq 0x118e0
cmpl $0x0, %eax
je 0x13b3
jmp 0x137f
jmp 0x1381
leaq -0x80(%rbp), %rdi
callq 0x17b0
movq %rax, -0xa0(%rbp)
movq %rdx, -0x98(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x1247
cmpl $0x61, -0x84(%rbp)
je 0x13dd
cmpl $0x2d, -0x84(%rbp)
jne 0x1413
movq -0x90(%rbp), %rdi
leaq 0x10e6a(%rip), %rsi     # 0x1223d
callq 0x118e0
cmpl $0x0, %eax
je 0x1413
jmp 0x13df
jmp 0x13e1
leaq -0x80(%rbp), %rdi
callq 0x1830
movq %rax, -0xb0(%rbp)
movq %rdx, -0xa8(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x1247
cmpl $0x69, -0x84(%rbp)
je 0x143d
cmpl $0x2d, -0x84(%rbp)
jne 0x144f
movq -0x90(%rbp), %rdi
leaq 0x10e1a(%rip), %rsi     # 0x1224d
callq 0x118e0
cmpl $0x0, %eax
je 0x144f
jmp 0x143f
jmp 0x1441
movl -0x64(%rbp), %eax
orl $0x20, %eax
movl %eax, -0x64(%rbp)
jmp 0x1247
cmpl $0x3f, -0x84(%rbp)
je 0x1479
cmpl $0x2d, -0x84(%rbp)
jne 0x1489
movq -0x90(%rbp), %rdi
leaq 0x10de4(%rip), %rsi     # 0x12253
callq 0x118e0
cmpl $0x0, %eax
je 0x1489
jmp 0x147b
jmp 0x147d
movb $0x0, %al
callq 0x11e50
jmp 0x1247
cmpq $0x0, -0x90(%rbp)
je 0x14b4
movq 0x15b5e(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
movq -0x90(%rbp), %rdx
leaq 0x10dad(%rip), %rsi     # 0x12258
movb $0x0, %al
callq 0x1070
jmp 0x14d2
movq 0x15b3d(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
movl -0x84(%rbp), %edx
leaq 0x10da2(%rip), %rsi     # 0x1226d
movb $0x0, %al
callq 0x1070
leaq 0x11edb(%rip), %rdi     # 0x133b4
callq 0x11e70
jmp 0x1247
jmp 0x14e5
jmp 0x14e7
leaq -0x80(%rbp), %rdi
callq 0x18b0
movq %rax, -0xc0(%rbp)
movq %rdx, -0xb8(%rbp)
movl -0x40(%rbp), %eax
shll $0xa, %eax
movl %eax, %eax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x117d0
movq %rax, -0xd0(%rbp)
movq -0x38(%rbp), %rdi
callq 0x117d0
movq %rax, -0xd8(%rbp)
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
movl -0x64(%rbp), %ecx
leaq 0x10d39(%rip), %rdi     # 0x12281
callq 0x1060
cmpq $0x0, %rax
jne 0x155f
leaq 0x10d34(%rip), %rdi     # 0x1228e
callq 0x11840
movq -0xd0(%rbp), %rdi
callq 0x1040
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %esi
movq -0xd0(%rbp), %rdx
movl -0x40(%rbp), %ecx
movl -0x3c(%rbp), %r8d
movq -0xd0(%rbp), %r9
movq -0xe0(%rbp), %rax
movl %eax, %r12d
movq -0xc0(%rbp), %r15
movq -0xb8(%rbp), %rax
movl %eax, %r14d
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %rax
movl %eax, %r11d
movq -0x60(%rbp), %r10
movq -0x58(%rbp), %rax
movl %r12d, (%rsp)
movq %r15, 0x8(%rsp)
movl %r14d, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movl %r11d, 0x20(%rsp)
movq %r10, 0x28(%rsp)
movl %eax, 0x30(%rsp)
callq 0x7bd0
movq -0xd0(%rbp), %rdi
callq 0x1030
leaq -0x50(%rbp), %rdi
callq 0x11df0
leaq -0x60(%rbp), %rdi
callq 0x11df0
leaq -0xc0(%rbp), %rdi
callq 0x11df0
movq -0xd8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x11b00
leaq 0x11d8a(%rip), %rdi     # 0x133b3
movb $0x0, %al
callq 0x1050
xorl %eax, %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)