// File: /workspace/github_c_makefile_star2_O0/skeeto[P]enchive/src/enchive.c
// Function: command_extract
static void
command_extract(struct optparse *options)
{
    static const struct optparse_long extract[] = {
        {"delete", 'd', OPTPARSE_NONE},
        {0, 0, 0}
    };

    /* Options */
    char *infile;
    char *outfile;
    FILE *in = stdin;
    FILE *out = stdout;
    char *secfile = dupstr(global_seckey);
    int delete = 0;

    /* Workspace */
    SHA256_CTX sha[1];
    uint8_t secret[32];
    uint8_t epublic[32];
    uint8_t shared[32];
    uint8_t iv[8];
    uint8_t check_iv[SHA256_BLOCK_SIZE];

    int option;
    while ((option = optparse_long(options, extract, 0)) != -1) {
        switch (option) {
            case 'd':
                delete = 1;
                break;
            default:
                fatal("%s", options->errmsg);
        }
    }

    if (!secfile)
        secfile = default_secfile();
    load_seckey(secfile, secret);
    free(secfile);

    infile = optparse_arg(options);
    if (infile) {
        in = fopen(infile, "rb");
        if (!in)
            fatal("could not open input file '%s' -- %s",
                  infile, strerror(errno));
    }

    outfile = dupstr(optparse_arg(options));
    if (!outfile && infile) {
        /* Generate an output filename. */
        size_t slen = sizeof(enchive_suffix) - 1;
        size_t len = strlen(infile);
        if (len <= slen || strcmp(enchive_suffix, infile + len - slen) != 0)
            fatal("could not determine output filename from %s", infile);
        outfile = dupstr(infile);
        outfile[len - slen] = 0;
    }
    if (outfile) {
        out = fopen(outfile, "wb");
        if (!out)
            fatal("could not open output file '%s' -- %s",
                  infile, strerror(errno));
        cleanup_register(out, outfile);
    }

    if (!(fread(iv, sizeof(iv), 1, in)))
        fatal("failed to read IV from archive");
    if (!(fread(epublic, sizeof(epublic), 1, in)))
        fatal("failed to read ephemeral key from archive");
    compute_shared(shared, secret, epublic);

    /* Validate key before processing the file. */
    sha256_init(sha);
    sha256_update(sha, shared, sizeof(shared));
    sha256_final(sha, check_iv);
    check_iv[0] += (unsigned)ENCHIVE_FORMAT_VERSION;
    if (memcmp(iv, check_iv, sizeof(iv)) != 0)
        fatal("invalid master key or format");

    symmetric_decrypt(in, out, shared, iv);

    if (in != stdin)
        fclose(in);
    if (out != stdout) {
        cleanup_closed(out);
        fclose(out); /* already flushed */
    }

    if (delete && infile)
        remove(infile);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq 0xb1a2(%rip), %rax      # 0xefd8
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq 0xb18c(%rip), %rax      # 0xefd0
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq 0xb466(%rip), %rdi      # 0xf2b8
callq 0x4320
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xaf53(%rip), %rsi      # 0xedc0
xorl %eax, %eax
movl %eax, %edx
callq 0x2b20
movl %eax, -0x144(%rbp)
cmpl $-0x1, %eax
je 0x3eaf
movl -0x144(%rbp), %eax
subl $0x64, %eax
jne 0x3e97
jmp 0x3e8e
movl $0x1, -0x34(%rbp)
jmp 0x3ead
movq -0x8(%rbp), %rsi
addq $0x20, %rsi
leaq 0x7f78(%rip), %rdi      # 0xbe1e
movb $0x0, %al
callq 0x3340
jmp 0x3e62
cmpq $0x0, -0x30(%rbp)
jne 0x3ebf
callq 0x4400
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x4420
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0x8(%rbp), %rdi
callq 0x2ad0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3f38
movq -0x10(%rbp), %rdi
leaq 0x79b0(%rip), %rsi      # 0xb8a7
callq 0x22d0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3f36
movq -0x10(%rbp), %rax
movq %rax, -0x160(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x2350
movq -0x160(%rbp), %rsi
movq %rax, %rdx
leaq 0x7ecd(%rip), %rdi      # 0xbdfc
movb $0x0, %al
callq 0x3340
jmp 0x3f38
movq -0x8(%rbp), %rdi
callq 0x2ad0
movq %rax, %rdi
callq 0x4320
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3feb
cmpq $0x0, -0x10(%rbp)
je 0x3feb
movq $0x8, -0x150(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2110
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rax
cmpq -0x150(%rbp), %rax
jbe 0x3fb6
movq -0x10(%rbp), %rsi
addq -0x158(%rbp), %rsi
xorl %eax, %eax
subq -0x150(%rbp), %rax
addq %rax, %rsi
leaq 0x7224(%rip), %rdi      # 0xb1d0
callq 0x21e0
cmpl $0x0, %eax
je 0x3fc8
movq -0x10(%rbp), %rsi
leaq 0x7f5a(%rip), %rdi      # 0xbf1b
movb $0x0, %al
callq 0x3340
movq -0x10(%rbp), %rdi
callq 0x4320
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x158(%rbp), %rcx
subq -0x150(%rbp), %rcx
movb $0x0, (%rax,%rcx)
cmpq $0x0, -0x18(%rbp)
je 0x4049
movq -0x18(%rbp), %rdi
leaq 0x7da9(%rip), %rsi      # 0xbda6
callq 0x22d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x403c
movq -0x10(%rbp), %rax
movq %rax, -0x168(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x2350
movq -0x168(%rbp), %rsi
movq %rax, %rdx
leaq 0x7dec(%rip), %rdi      # 0xbe21
movb $0x0, %al
callq 0x3340
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x62f0
leaq -0x118(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x20e0
cmpq $0x0, %rax
jne 0x4077
leaq 0x7ed7(%rip), %rdi      # 0xbf47
movb $0x0, %al
callq 0x3340
leaq -0xf0(%rbp), %rdi
movq -0x20(%rbp), %rcx
movl $0x20, %esi
movl $0x1, %edx
callq 0x20e0
cmpq $0x0, %rax
jne 0x40a5
leaq 0x7ec8(%rip), %rdi      # 0xbf66
movb $0x0, %al
callq 0x3340
leaq -0x110(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
leaq -0xf0(%rbp), %rdx
callq 0x6490
leaq -0xb0(%rbp), %rdi
callq 0xa5d0
leaq -0xb0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0x20, %edx
callq 0xa650
leaq -0xb0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0xa6f0
movzbl -0x140(%rbp), %eax
addl $0x3, %eax
movb %al, -0x140(%rbp)
leaq -0x118(%rbp), %rax
leaq -0x140(%rbp), %rcx
movq (%rcx), %rcx
movq (%rax), %rax
subq %rcx, %rax
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x4136
leaq 0x7e61(%rip), %rdi      # 0xbf90
movb $0x0, %al
callq 0x3340
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x110(%rbp), %rdx
leaq -0x118(%rbp), %rcx
callq 0x6660
movq -0x20(%rbp), %rax
movq 0xae7c(%rip), %rcx      # 0xefd8
cmpq (%rcx), %rax
je 0x416a
movq -0x20(%rbp), %rdi
callq 0x2100
movq -0x28(%rbp), %rax
movq 0xae5b(%rip), %rcx      # 0xefd0
cmpq (%rcx), %rax
je 0x418c
movq -0x28(%rbp), %rdi
callq 0x6380
movq -0x28(%rbp), %rdi
callq 0x2100
cmpl $0x0, -0x34(%rbp)
je 0x41a2
cmpq $0x0, -0x10(%rbp)
je 0x41a2
movq -0x10(%rbp), %rdi
callq 0x2090
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopl (%rax,%rax)