// File: /workspace/github_c_makefile_star2_O3/skeeto[P]enchive/src/enchive.c
// Function: load_seckey
static void
load_seckey(const char *file, uint8_t *seckey)
{
    FILE *secfile;
    chacha_ctx cha[1];
    SHA256_CTX sha[1];
    uint8_t buf[8 + 4 + 20 + 32];            /* entire key file contents */
    uint8_t protect[32];                     /* protection key */
    uint8_t protect_hash[SHA256_BLOCK_SIZE]; /* hash of protection key */
    int iexp;
    int version;

    uint8_t *buf_iv           = buf + SECFILE_IV;
    uint8_t *buf_iterations   = buf + SECFILE_ITERATIONS;
    uint8_t *buf_version      = buf + SECFILE_VERSION;
    uint8_t *buf_protect_hash = buf + SECFILE_PROTECT_HASH;
    uint8_t *buf_seckey       = buf + SECFILE_SECKEY;

    /* Read the entire file into buf. */
    secfile = fopen(file, "rb");
    if (!secfile)
        fatal("failed to open key file for reading '%s' -- %s",
              file, strerror(errno));
    if (!fread(buf, sizeof(buf), 1, secfile))
        fatal("failed to read key file -- %s", file);
    fclose(secfile);

    version = buf_version[0];
    if (version != ENCHIVE_FORMAT_VERSION)
        fatal("secret key version mismatch -- expected %d, got %d",
              ENCHIVE_FORMAT_VERSION, version);

    iexp = buf_iterations[0];
    if (iexp) {
        /* Secret key is encrypted. */
        int agent_success = agent_read(protect, buf_iv);
        if (agent_success) {
            /* Check validity of agent key. */
            sha256_init(sha);
            sha256_update(sha, protect, 32);
            sha256_final(sha, protect_hash);
            agent_success = !memcmp(protect_hash, buf_protect_hash, 20);
        }

        if (!agent_success) {
            /* Ask user for passphrase. */
            char pass[ENCHIVE_PASSPHRASE_MAX];
            get_passphrase(pass, sizeof(pass), "passphrase: ");
            key_derive(pass, protect, iexp, buf_iv);

            /* Validate passphrase. */
            sha256_init(sha);
            sha256_update(sha, protect, sizeof(protect));
            sha256_final(sha, protect_hash);
            if (memcmp(protect_hash, buf_protect_hash, 20) != 0)
                fatal("wrong passphrase");
        }

        /* We have the correct protection key. Start the agent? */
        if (!agent_success && global_agent_timeout)
            agent_run(protect, buf_iv);

        /* Decrypt the key into the output. */
        chacha_keysetup(cha, protect, 256);
        chacha_ivsetup(cha, buf_iv);
        chacha_encrypt(cha, buf_seckey, seckey, 32);
    } else {
        /* Key is unencrypted, copy into output. */
        memcpy(seckey, buf_seckey, 32);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x508, %rsp            # imm = 0x508
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x4741(%rip), %rsi      # 0x87ce
callq 0x22c0
testq %rax, %rax
je 0x434f
movq %rax, %r15
leaq 0x30(%rsp), %rdi
movl $0x40, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x20e0
testq %rax, %rax
je 0x436f
movq %r15, %rdi
callq 0x2100
movzbl 0x39(%rsp), %edx
cmpl $0x3, %edx
jne 0x4380
leaq 0x50(%rsp), %r14
movzbl -0x18(%r14), %ebp
testl %ebp, %ebp
je 0x4266
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2360
movl %eax, %r15d
leaq 0x100(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f07
testl %eax, %eax
je 0x412d
leaq 0x100(%rsp), %rsi
movl %r15d, %edi
movl $0x6e, %edx
callq 0x2310
testl %eax, %eax
je 0x428c
movl %r15d, %edi
callq 0x2170
leaq 0x4594(%rip), %rsi      # 0x86d0
leaq 0x100(%rsp), %r15
movq %r15, %rdi
callq 0x452f
leaq 0x10(%rsp), %r12
leaq 0x30(%rsp), %r13
movq %r15, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq %r13, %rcx
callq 0x4a21
leaq 0x90(%rsp), %r15
movq %r15, %rdi
callq 0x700c
movl $0x20, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x7032
leaq 0x70(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x709b
movdqu 0xc(%r13), %xmm0
movd 0x10(%r12), %xmm1
movd 0x1c(%r13), %xmm2
pcmpeqb (%r12), %xmm0
pcmpeqb %xmm1, %xmm2
pand %xmm2, %xmm0
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x4393
cmpl $0x0, 0x7013(%rip)      # 0xb1e0
je 0x422a
movabsq $0x1ffffffff, %rax      # imm = 0x1FFFFFFFF
movq %rax, 0x8(%rsp)
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2360
movl %eax, 0x8(%rsp)
cmpl $-0x1, %eax
je 0x431a
movl %eax, %ebp
leaq 0x100(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f07
testl %eax, %eax
je 0x422a
callq 0x2350
cmpl $-0x1, %eax
je 0x432d
testl %eax, %eax
je 0x43a1
leaq 0x100(%rsp), %r15
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x5178
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x51e9
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl $0x20, %ecx
callq 0x51fd
jmp 0x427a
movdqu (%r14), %xmm0
movdqu 0x10(%r14), %xmm1
movdqu %xmm1, 0x10(%rbx)
movdqu %xmm0, (%rbx)
addq $0x508, %rsp            # imm = 0x508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movl %r15d, %edi
callq 0x21b0
movq %rax, %r12
movl %r15d, %edi
callq 0x2170
cmpq $0x20, %r12
jne 0x4135
leaq 0x90(%rsp), %r15
movq %r15, %rdi
callq 0x700c
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movq %r15, %rdi
callq 0x7032
leaq 0x70(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x709b
movdqu 0x3c(%rsp), %xmm0
movd 0x10(%r12), %xmm1
movd 0x4c(%rsp), %xmm2
pcmpeqb (%r12), %xmm0
pcmpeqb %xmm1, %xmm2
pand %xmm2, %xmm0
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x4135
jmp 0x422a
leaq 0x45ac(%rip), %rdi      # 0x88cd
xorl %eax, %eax
callq 0x2380
jmp 0x422a
callq 0x2070
movl (%rax), %edi
callq 0x2340
leaq 0x45ab(%rip), %rdi      # 0x88eb
movq %rax, %rsi
xorl %eax, %eax
callq 0x2380
jmp 0x422a
callq 0x2070
movl (%rax), %edi
callq 0x2340
leaq 0x446f(%rip), %rdi      # 0x87d1
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3ea8
leaq 0x448a(%rip), %rdi      # 0x8800
movq %r14, %rsi
xorl %eax, %eax
callq 0x3ea8
leaq 0x4497(%rip), %rdi      # 0x881e
movl $0x3, %esi
xorl %eax, %eax
callq 0x3ea8
leaq 0x44b7(%rip), %rdi      # 0x8851
xorl %eax, %eax
callq 0x3ea8
xorl %edi, %edi
callq 0x2170
movl $0x1, %edi
callq 0x2170
movl $0xfffffe7f, %edi       # imm = 0xFFFFFE7F
callq 0x21f0
leaq 0x102(%rsp), %rbx
movq %rbx, %rdi
callq 0x2080
testl %eax, %eax
je 0x43e0
callq 0x2070
movl (%rax), %edi
cmpl $0x2, %edi
jne 0x4476
leaq 0x100(%rsp), %rsi
movl %ebp, %edi
movl $0x6e, %edx
callq 0x2280
testl %eax, %eax
jne 0x444f
movl %ebp, %edi
movl $0x1000, %esi           # imm = 0x1000
callq 0x2250
testl %eax, %eax
jne 0x4487
movl $0x2, %edi
callq 0x2170
imull $0x3e8, 0x6dc4(%rip), %edx # imm = 0x3E8
leaq 0x8(%rsp), %rdi
movl $0x1, %esi
callq 0x2270
testl %eax, %eax
jns 0x449d
movq %rbx, %rdi
callq 0x2080
callq 0x2070
movl (%rax), %edi
callq 0x2340
leaq 0x4531(%rip), %rdi      # 0x897b
jmp 0x451a
callq 0x2070
movl (%rax), %edi
cmpl $0x62, %edi
je 0x4493
callq 0x2340
leaq 0x44c8(%rip), %rdi      # 0x892f
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2380
jmp 0x4493
callq 0x2340
leaq 0x4486(%rip), %rdi      # 0x8908
jmp 0x451a
callq 0x2070
movl (%rax), %edi
cmpl $0x62, %edi
jne 0x450e
movl $0x1, %edi
callq 0x2300
leaq 0x8(%rsp), %r14
leaq 0x10(%rsp), %r15
leaq 0x44fa(%rip), %r12      # 0x89a8
testl %eax, %eax
je 0x4522
movl 0x8(%rsp), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22e0
cmpl $-0x1, %eax
je 0x44e2
movl %eax, %ebp
movl $0x20, %edx
movl %eax, %edi
movq %r15, %rsi
callq 0x20f0
cmpq $0x20, %rax
jne 0x4502
movl %ebp, %edi
callq 0x2170
imull $0x3e8, 0x6cf4(%rip), %edx # imm = 0x3E8
movl $0x1, %esi
movq %r14, %rdi
callq 0x2270
testl %eax, %eax
jns 0x44ae
jmp 0x442f
movq %r12, %rdi
xorl %eax, %eax
callq 0x2380
jmp 0x44db
callq 0x2340
leaq 0x443a(%rip), %rdi      # 0x8954
movq %rax, %rsi
jmp 0x4379
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x249e