// File: /workspace/github_c_makefile_star2_O0/skeeto[P]enchive/src/enchive.c
// Function: command_keygen
static void
command_keygen(struct optparse *options)
{
    static const struct optparse_long keygen[] = {
        {"derive",      'd', OPTPARSE_OPTIONAL},
        {"edit"  ,      'e', OPTPARSE_NONE},
        {"force",       'f', OPTPARSE_NONE},
        {"fingerprint", 'i', OPTPARSE_NONE},
        {"iterations",  'k', OPTPARSE_REQUIRED},
        {"plain",       'u', OPTPARSE_NONE},
        {"repeats",     'r', OPTPARSE_REQUIRED},
        {0, 0, 0}
    };

    char *pubfile = dupstr(global_pubkey);
    char *secfile = dupstr(global_seckey);
    int pubfile_exists;
    int secfile_exists;
    uint8_t public[32];
    uint8_t secret[32];
    int clobber = 0;
    int derive = 0;
    int edit = 0;
    int protect = 1;
    int fingerprint = 0;
    int repeats = 1;
    int key_derive_iterations = ENCHIVE_KEY_DERIVE_ITERATIONS;
    int seckey_derive_iterations = ENCHIVE_SECKEY_DERIVE_ITERATIONS;

    int option;
    while ((option = optparse_long(options, keygen, 0)) != -1) {
        switch (option) {
            case 'd': {
                char *p;
                char *arg = options->optarg;
                derive = 1;
                if (arg) {
                    long n;
                    errno = 0;
                    n = strtol(arg, &p, 10);
                    if (errno || *p)
                        fatal("invalid argument -- %s", arg);
                    if (n < 5 || n > 31)
                        fatal("--derive argument must be 5 <= n <= 31 -- %s",
                              arg);
                    seckey_derive_iterations = n;
                }
            } break;
            case 'e':
                edit = 1;
                break;
            case 'f':
                clobber = 1;
                break;
            case 'i':
                fingerprint = 1;
                break;
            case 'k': {
                char *p;
                char *arg = options->optarg;
                long n;
                errno = 0;
                n = strtol(arg, &p, 10);
                if (errno || *p)
                    fatal("invalid argument -- %s", arg);
                if (n < 5 || n > 31)
                    fatal("--iterations argument must be 5 <= n <= 31 -- %s",
                          arg);
                key_derive_iterations = n;
            } break;
            case 'r': {
                char *p;
                char *arg = options->optarg;
                long n;
                errno = 0;
                n = strtol(arg, &p, 10);
                if (errno || *p || n < 0 || n >= 256)
                    fatal("invalid --repeats (-r) -- %s", arg);
                repeats = n;
            } break;
            case 'u':
                protect = 0;
                break;
            default:
                fatal("%s", options->errmsg);
        }
    }

    if (edit && derive)
        fatal("--edit and --derive are mutually exclusive");

    if (!pubfile)
        pubfile = default_pubfile();
    pubfile_exists = file_exists(pubfile);
    if (!secfile)
        secfile = default_secfile();
    secfile_exists = file_exists(secfile);

    if (!edit && !clobber) {
        if (pubfile_exists)
            fatal("operation would clobber %s", pubfile);
        if (secfile_exists)
            fatal("operation would clobber %s", secfile);
    }

    if (edit) {
        if (!secfile_exists)
            fatal("cannot edit non-existing file %s", secfile);
        load_seckey(secfile, secret);
    } else if (derive) {
        /* Generate secret key from passphrase. */
        char pass[2][ENCHIVE_PASSPHRASE_MAX];
        get_passphrase(pass[0], sizeof(pass[0]),
                       "secret key passphrase: ");
        while (repeats--) {
            get_passphrase(pass[1], sizeof(pass[0]),
                           "secret key passphrase (repeat): ");
            if (strcmp(pass[0], pass[1]) != 0)
                fatal("secret key passphrases don't match");
        }
        key_derive(pass[0], secret, seckey_derive_iterations, 0);
        secret[0] &= 248;
        secret[31] &= 127;
        secret[31] |= 64;
    } else {
        /* Generate secret key from entropy. */
        generate_secret(secret);
    }

    compute_public(public, secret);

    if (fingerprint) {
        fputs("keyid: ", stdout);
        print_fingerprint(public);
        putchar('\n');
    }

    write_seckey(secfile, secret, protect ? key_derive_iterations : 0);
    write_pubkey(pubfile, public);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x8f0, %rsp            # imm = 0x8F0
movq %rdi, -0x8(%rbp)
movq 0xbd1a(%rip), %rdi      # 0xf2b0
callq 0x4320
movq %rax, -0x10(%rbp)
movq 0xbd12(%rip), %rdi      # 0xf2b8
callq 0x4320
movq %rax, -0x18(%rbp)
movl $0x0, -0x64(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x1, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl $0x1, -0x78(%rbp)
movl $0x19, -0x7c(%rbp)
movl $0x1d, -0x80(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xb72e(%rip), %rsi      # 0xed20
xorl %eax, %eax
movl %eax, %edx
callq 0x2b20
movl %eax, -0x84(%rbp)
cmpl $-0x1, %eax
je 0x3861
movl -0x84(%rbp), %eax
addl $-0x64, %eax
movl %eax, %ecx
movq %rcx, -0x8d8(%rbp)
subl $0x11, %eax
ja 0x3846
movq -0x8d8(%rbp), %rax
leaq 0x7ad1(%rip), %rcx      # 0xb104
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x98(%rbp)
movl $0x1, -0x68(%rbp)
cmpq $0x0, -0x98(%rbp)
je 0x36eb
callq 0x2070
movl $0x0, (%rax)
movq -0x98(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl $0xa, %edx
callq 0x2220
movq %rax, -0xa0(%rbp)
callq 0x2070
cmpl $0x0, (%rax)
jne 0x36a3
movq -0x90(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x36b8
movq -0x98(%rbp), %rsi
leaq 0x7ff4(%rip), %rdi      # 0xb6a5
movb $0x0, %al
callq 0x3340
cmpq $0x5, -0xa0(%rbp)
jl 0x36cc
cmpq $0x1f, -0xa0(%rbp)
jle 0x36e1
movq -0x98(%rbp), %rsi
leaq 0x7fe2(%rip), %rdi      # 0xb6bc
movb $0x0, %al
callq 0x3340
movq -0xa0(%rbp), %rax
movl %eax, -0x80(%rbp)
jmp 0x385c
movl $0x1, -0x6c(%rbp)
jmp 0x385c
movl $0x1, -0x64(%rbp)
jmp 0x385c
movl $0x1, -0x74(%rbp)
jmp 0x385c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xb0(%rbp)
callq 0x2070
movl $0x0, (%rax)
movq -0xb0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
movl $0xa, %edx
callq 0x2220
movq %rax, -0xb8(%rbp)
callq 0x2070
cmpl $0x0, (%rax)
jne 0x3766
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x377b
movq -0xb0(%rbp), %rsi
leaq 0x7f31(%rip), %rdi      # 0xb6a5
movb $0x0, %al
callq 0x3340
cmpq $0x5, -0xb8(%rbp)
jl 0x378f
cmpq $0x1f, -0xb8(%rbp)
jle 0x37a4
movq -0xb0(%rbp), %rsi
leaq 0x7f4c(%rip), %rdi      # 0xb6e9
movb $0x0, %al
callq 0x3340
movq -0xb8(%rbp), %rax
movl %eax, -0x7c(%rbp)
jmp 0x385c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xc8(%rbp)
callq 0x2070
movl $0x0, (%rax)
movq -0xc8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movl $0xa, %edx
callq 0x2220
movq %rax, -0xd0(%rbp)
callq 0x2070
cmpl $0x0, (%rax)
jne 0x381c
movq -0xc0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x381c
cmpq $0x0, -0xd0(%rbp)
jl 0x381c
cmpq $0x100, -0xd0(%rbp) # imm = 0x100
jl 0x3831
movq -0xc8(%rbp), %rsi
leaq 0x7ef0(%rip), %rdi      # 0xb71a
movb $0x0, %al
callq 0x3340
movq -0xd0(%rbp), %rax
movl %eax, -0x78(%rbp)
jmp 0x385c
movl $0x0, -0x70(%rbp)
jmp 0x385c
movq -0x8(%rbp), %rsi
addq $0x20, %rsi
leaq 0x85c9(%rip), %rdi      # 0xbe1e
movb $0x0, %al
callq 0x3340
jmp 0x35e7
cmpl $0x0, -0x6c(%rbp)
je 0x387b
cmpl $0x0, -0x68(%rbp)
je 0x387b
leaq 0x7ec3(%rip), %rdi      # 0xb737
movb $0x0, %al
callq 0x3340
cmpq $0x0, -0x10(%rbp)
jne 0x388b
callq 0x4390
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x43b0
movl %eax, -0x1c(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x38a7
callq 0x4400
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x43b0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x6c(%rbp)
jne 0x38f1
cmpl $0x0, -0x64(%rbp)
jne 0x38f1
cmpl $0x0, -0x1c(%rbp)
je 0x38d7
movq -0x10(%rbp), %rsi
leaq 0x7e92(%rip), %rdi      # 0xb762
movb $0x0, %al
callq 0x3340
cmpl $0x0, -0x20(%rbp)
je 0x38ef
movq -0x18(%rbp), %rsi
leaq 0x7e7a(%rip), %rdi      # 0xb762
movb $0x0, %al
callq 0x3340
jmp 0x38f1
cmpl $0x0, -0x6c(%rbp)
je 0x3921
cmpl $0x0, -0x20(%rbp)
jne 0x390f
movq -0x18(%rbp), %rsi
leaq 0x7e75(%rip), %rdi      # 0xb77d
movb $0x0, %al
callq 0x3340
movq -0x18(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x4420
jmp 0x39e5
cmpl $0x0, -0x68(%rbp)
je 0x39da
leaq -0x8d0(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
leaq 0x7e60(%rip), %rdx      # 0xb79e
callq 0x4730
movl -0x78(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x78(%rbp)
cmpl $0x0, %eax
je 0x39a1
leaq -0x8d0(%rbp), %rdi
addq $0x400, %rdi            # imm = 0x400
movl $0x400, %esi            # imm = 0x400
leaq 0x7e49(%rip), %rdx      # 0xb7b6
callq 0x4730
leaq -0x8d0(%rbp), %rdi
leaq -0x8d0(%rbp), %rsi
addq $0x400, %rsi            # imm = 0x400
callq 0x21e0
cmpl $0x0, %eax
je 0x399f
leaq 0x7e3f(%rip), %rdi      # 0xb7d7
movb $0x0, %al
callq 0x3340
jmp 0x3943
leaq -0x8d0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl -0x80(%rbp), %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x4920
movzbl -0x60(%rbp), %eax
andl $0xf8, %eax
movb %al, -0x60(%rbp)
movzbl -0x41(%rbp), %eax
andl $0x7f, %eax
movb %al, -0x41(%rbp)
movzbl -0x41(%rbp), %eax
orl $0x40, %eax
movb %al, -0x41(%rbp)
jmp 0x39e3
leaq -0x60(%rbp), %rdi
callq 0x4be0
jmp 0x39e5
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x4c30
cmpl $0x0, -0x74(%rbp)
je 0x3a21
movq 0xb5d1(%rip), %rax      # 0xefd0
movq (%rax), %rsi
leaq 0x7df1(%rip), %rdi      # 0xb7fa
callq 0x2150
leaq -0x40(%rbp), %rdi
callq 0x4c60
movl $0xa, %edi
callq 0x2050
movq -0x18(%rbp), %rax
movq %rax, -0x8e8(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x8e0(%rbp)
cmpl $0x0, -0x70(%rbp)
je 0x3a48
movl -0x7c(%rbp), %eax
movl %eax, -0x8ec(%rbp)
jmp 0x3a52
xorl %eax, %eax
movl %eax, -0x8ec(%rbp)
jmp 0x3a52
movq -0x8e0(%rbp), %rsi
movq -0x8e8(%rbp), %rdi
movl -0x8ec(%rbp), %edx
callq 0x4d50
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x5000
addq $0x8f0, %rsp            # imm = 0x8F0
popq %rbp
retq
nopw %cs:(%rax,%rax)