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

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

    /* Workspace */
    uint8_t public[32];
    uint8_t esecret[32];
    uint8_t epublic[32];
    uint8_t shared[32];
    uint8_t iv[SHA256_BLOCK_SIZE];
    SHA256_CTX sha[1];

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

    if (!pubfile)
        pubfile = default_pubfile();
    load_pubkey(pubfile, public);
    free(pubfile);

    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. */
        outfile = joinstr(2, infile, enchive_suffix);
    }
    if (outfile) {
        out = fopen(outfile, "wb");
        if (!out)
            fatal("could not open output file '%s' -- %s",
                  outfile, strerror(errno));
        cleanup_register(out, outfile);
    }

    /* Generare ephemeral keypair. */
    generate_secret(esecret);
    compute_public(epublic, esecret);

    /* Create shared secret between ephemeral key and master key. */
    compute_shared(shared, esecret, public);
    sha256_init(sha);
    sha256_update(sha, shared, sizeof(shared));
    sha256_final(sha, iv);
    iv[0] += (unsigned)ENCHIVE_FORMAT_VERSION;
    if (!fwrite(iv, 8, 1, out))
        fatal("failed to write IV to archive");
    if (!fwrite(epublic, sizeof(epublic), 1, out))
        fatal("failed to write ephemeral key to archive");
    symmetric_encrypt(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 0xb4a2(%rip), %rax      # 0xefd8
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq 0xb48c(%rip), %rax      # 0xefd0
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq 0xb75e(%rip), %rdi      # 0xf2b0
callq 0x4320
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xb233(%rip), %rsi      # 0xeda0
xorl %eax, %eax
movl %eax, %edx
callq 0x2b20
movl %eax, -0x154(%rbp)
cmpl $-0x1, %eax
je 0x3baf
movl -0x154(%rbp), %eax
subl $0x64, %eax
jne 0x3b97
jmp 0x3b8e
movl $0x1, -0x34(%rbp)
jmp 0x3bad
movq -0x8(%rbp), %rsi
addq $0x20, %rsi
leaq 0x8278(%rip), %rdi      # 0xbe1e
movb $0x0, %al
callq 0x3340
jmp 0x3b62
cmpq $0x0, -0x30(%rbp)
jne 0x3bbf
callq 0x4390
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x63f0
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0x8(%rbp), %rdi
callq 0x2ad0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3c35
movq -0x10(%rbp), %rdi
leaq 0x7cb3(%rip), %rsi      # 0xb8a7
callq 0x22d0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3c33
movq -0x10(%rbp), %rax
movq %rax, -0x160(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x2350
movq -0x160(%rbp), %rsi
movq %rax, %rdx
leaq 0x81d0(%rip), %rdi      # 0xbdfc
movb $0x0, %al
callq 0x3340
jmp 0x3c35
movq -0x8(%rbp), %rdi
callq 0x2ad0
movq %rax, %rdi
callq 0x4320
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3c73
cmpq $0x0, -0x10(%rbp)
je 0x3c73
movq -0x10(%rbp), %rsi
movl $0x2, %edi
leaq 0x7568(%rip), %rdx      # 0xb1d0
movb $0x0, %al
callq 0x5240
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x3cd1
movq -0x18(%rbp), %rdi
leaq 0x8121(%rip), %rsi      # 0xbda6
callq 0x22d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3cc4
movq -0x18(%rbp), %rax
movq %rax, -0x168(%rbp)
callq 0x2070
movl (%rax), %edi
callq 0x2350
movq -0x168(%rbp), %rsi
movq %rax, %rdx
leaq 0x8164(%rip), %rdi      # 0xbe21
movb $0x0, %al
callq 0x3340
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x62f0
leaq -0x80(%rbp), %rdi
callq 0x4be0
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x4c30
leaq -0xc0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x6490
leaq -0x150(%rbp), %rdi
callq 0xa5d0
leaq -0x150(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
movl $0x20, %edx
callq 0xa650
leaq -0x150(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xa6f0
movzbl -0xe0(%rbp), %eax
addl $0x3, %eax
movb %al, -0xe0(%rbp)
leaq -0xe0(%rbp), %rdi
movq -0x28(%rbp), %rcx
movl $0x8, %esi
movl $0x1, %edx
callq 0x2330
cmpq $0x0, %rax
jne 0x3d73
leaq 0x80db(%rip), %rdi      # 0xbe47
movb $0x0, %al
callq 0x3340
leaq -0xa0(%rbp), %rdi
movq -0x28(%rbp), %rcx
movl $0x20, %esi
movl $0x1, %edx
callq 0x2330
cmpq $0x0, %rax
jne 0x3da1
leaq 0x80cb(%rip), %rdi      # 0xbe65
movb $0x0, %al
callq 0x3340
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
callq 0x64c0
movq -0x20(%rbp), %rax
movq 0xb211(%rip), %rcx      # 0xefd8
cmpq (%rcx), %rax
je 0x3dd5
movq -0x20(%rbp), %rdi
callq 0x2100
movq -0x28(%rbp), %rax
movq 0xb1f0(%rip), %rcx      # 0xefd0
cmpq (%rcx), %rax
je 0x3df7
movq -0x28(%rbp), %rdi
callq 0x6380
movq -0x28(%rbp), %rdi
callq 0x2100
cmpl $0x0, -0x34(%rbp)
je 0x3e0d
cmpq $0x0, -0x10(%rbp)
je 0x3e0d
movq -0x10(%rbp), %rdi
callq 0x2090
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopw %cs:(%rax,%rax)