// File: /workspace/github_c_makefile_star2_O1/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 0x463c(%rip), %rsi      # 0x87b7
callq 0x22c0
testq %rax, %rax
je 0x4458
movq %rax, %r15
leaq 0x30(%rsp), %rdi
movl $0x40, %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x20e0
testq %rax, %rax
je 0x4478
movq %r15, %rdi
callq 0x2100
movzbl 0x39(%rsp), %edx
cmpl $0x3, %edx
jne 0x4489
leaq 0x50(%rsp), %r13
movzbl -0x18(%r13), %ebp
testl %ebp, %ebp
je 0x436d
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2360
movl %eax, %r15d
leaq 0x100(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5012
testl %eax, %eax
je 0x421b
leaq 0x100(%rsp), %rsi
movl %r15d, %edi
movl $0x6e, %edx
callq 0x2310
testl %eax, %eax
je 0x4394
movl %r15d, %edi
callq 0x2170
movb $0x1, %r14b
testb %r14b, %r14b
je 0x42c5
leaq 0x4483(%rip), %rsi      # 0x86b9
leaq 0x100(%rsp), %r15
movq %r15, %rdi
callq 0x4654
leaq 0x10(%rsp), %r12
leaq 0x30(%rsp), %r13
movq %r15, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq %r13, %rcx
callq 0x4b2e
leaq 0x90(%rsp), %r15
movq %r15, %rdi
callq 0x7029
movl $0x20, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x704f
leaq 0x70(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x70b5
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 0x449c
leaq 0x50(%rsp), %r13
cmpl $0x0, 0x6f14(%rip)      # 0xb1e0
setne %al
andb %al, %r14b
cmpb $0x1, %r14b
jne 0x4331
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 0x4423
leaq 0x100(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5012
testl %eax, %eax
je 0x4331
callq 0x2350
cmpl $-0x1, %eax
je 0x4436
testl %eax, %eax
je 0x44aa
leaq 0x100(%rsp), %r15
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x5270
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x52e1
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movl $0x20, %ecx
callq 0x52f5
jmp 0x4382
movdqu (%r13), %xmm0
movdqu 0x10(%r13), %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
movb $0x1, %r14b
cmpq $0x20, %r12
jne 0x4226
leaq 0x90(%rsp), %r15
movq %r15, %rdi
callq 0x7029
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movq %r15, %rdi
callq 0x704f
leaq 0x70(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x70b5
movdqu 0x3c(%rsp), %xmm0
movd 0x10(%r12), %xmm1
movd 0x4c(%rsp), %xmm2
pcmpeqb %xmm1, %xmm2
pcmpeqb (%r12), %xmm0
pand %xmm2, %xmm0
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
setne %r14b
jmp 0x4226
leaq 0x448c(%rip), %rdi      # 0x88b6
xorl %eax, %eax
callq 0x2380
jmp 0x4331
callq 0x2070
movl (%rax), %edi
callq 0x2340
leaq 0x448b(%rip), %rdi      # 0x88d4
movq %rax, %rsi
xorl %eax, %eax
callq 0x2380
jmp 0x4331
callq 0x2070
movl (%rax), %edi
callq 0x2340
leaq 0x434f(%rip), %rdi      # 0x87ba
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3fa5
leaq 0x436a(%rip), %rdi      # 0x87e9
movq %r14, %rsi
xorl %eax, %eax
callq 0x3fa5
leaq 0x4377(%rip), %rdi      # 0x8807
movl $0x3, %esi
xorl %eax, %eax
callq 0x3fa5
leaq 0x4397(%rip), %rdi      # 0x883a
xorl %eax, %eax
callq 0x3fa5
xorl %edi, %edi
callq 0x2170
movl $0x1, %edi
callq 0x2170
movl $0xfffffe7f, %edi       # imm = 0xFFFFFE7F
callq 0x21f0
leaq 0x102(%rsp), %rdi
callq 0x2080
testl %eax, %eax
je 0x44e6
callq 0x2070
movl (%rax), %edi
cmpl $0x2, %edi
jne 0x45f3
movl 0x8(%rsp), %edi
leaq 0x100(%rsp), %rsi
movl $0x6e, %edx
callq 0x2280
testl %eax, %eax
jne 0x45c7
movl 0x8(%rsp), %edi
movl $0x1000, %esi           # imm = 0x1000
callq 0x2250
testl %eax, %eax
jne 0x4601
movl $0x2, %edi
callq 0x2170
leaq 0x8(%rsp), %r14
movq 0x6ac8(%rip), %r13      # 0xaff8
leaq 0x4445(%rip), %r15      # 0x897c
leaq 0x10(%rsp), %r12
imull $0x3e8, 0x6c9a(%rip), %edx # imm = 0x3E8
movl $0x1, %esi
movq %r14, %rdi
callq 0x2270
testl %eax, %eax
js 0x4617
movl %eax, %ebp
je 0x4598
movl 0x8(%rsp), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22e0
cmpl $-0x1, %eax
je 0x458f
movl %eax, %ebx
movl $0x20, %edx
movl %eax, %edi
movq %r12, %rsi
callq 0x20f0
cmpq $0x20, %rax
jne 0x45b7
movl %ebx, %edi
callq 0x2170
testl %ebp, %ebp
jne 0x453c
jmp 0x464d
leaq 0x102(%rsp), %rdi
callq 0x2080
movq (%r13), %rsi
movq %r15, %rdi
callq 0x2150
movl 0x8(%rsp), %ebx
jmp 0x4588
leaq 0x43d3(%rip), %rdi      # 0x8991
xorl %eax, %eax
callq 0x2380
jmp 0x4588
callq 0x2070
movl (%rax), %edi
cmpl $0x62, %edi
je 0x460d
callq 0x2340
leaq 0x4339(%rip), %rdi      # 0x8918
leaq 0x102(%rsp), %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2380
jmp 0x460d
callq 0x2340
leaq 0x42f2(%rip), %rdi      # 0x88f1
jmp 0x4645
callq 0x2070
movl (%rax), %edi
cmpl $0x62, %edi
jne 0x4639
movl $0x1, %edi
callq 0x2300
leaq 0x102(%rsp), %rdi
callq 0x2080
callq 0x2070
movl (%rax), %edi
callq 0x2340
leaq 0x432d(%rip), %rdi      # 0x8964
jmp 0x4645
callq 0x2340
leaq 0x42f8(%rip), %rdi      # 0x893d
movq %rax, %rsi
jmp 0x4482
xorl %edi, %edi
callq 0x2300