// File: /workspace/github_c_makefile_star2_O0/skeeto[P]enchive/src/enchive.c
// Function: symmetric_decrypt
static void
symmetric_decrypt(FILE *in, FILE *out, const uint8_t *key, const uint8_t *iv)
{
    static uint8_t buffer[2][CHACHA_BLOCKLENGTH * 1024 + SHA256_BLOCK_SIZE];
    uint8_t mac[SHA256_BLOCK_SIZE];
    SHA256_CTX hmac[1];
    chacha_ctx ctx[1];

    chacha_keysetup(ctx, key, 256);
    chacha_ivsetup(ctx, iv);
    hmac_init(hmac, key);

    /* Always keep SHA256_BLOCK_SIZE bytes in the buffer. */
    if (!(fread(buffer[0], SHA256_BLOCK_SIZE, 1, in))) {
        if (ferror(in))
            fatal("cannot read ciphertext file");
        else
            fatal("ciphertext file too short");
    }

    for (;;) {
        uint8_t *p = buffer[0] + SHA256_BLOCK_SIZE;
        size_t z = fread(p, 1, sizeof(buffer[0]) - SHA256_BLOCK_SIZE, in);
        if (!z) {
            if (ferror(in))
                fatal("error reading ciphertext file");
            break;
        }
        chacha_encrypt(ctx, buffer[0], buffer[1], z);
        sha256_update(hmac, buffer[1], z);
        if (!fwrite(buffer[1], z, 1, out))
            fatal("error writing plaintext file");

        /* Move last SHA256_BLOCK_SIZE bytes to the front. */
        memmove(buffer[0], buffer[0] + z, SHA256_BLOCK_SIZE);

        if (z < sizeof(buffer[0]) - SHA256_BLOCK_SIZE)
            break;
    }

    hmac_final(hmac, key, mac);
    if (memcmp(buffer[0], mac, sizeof(mac)) != 0)
        fatal("checksum mismatch!");
    if (fflush(out))
        fatal("error flushing to plaintext file -- %s", strerror(errno));

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq -0xf0(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x6890
leaq -0xf0(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x6b60
leaq -0xb0(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6100
movq -0x8(%rbp), %rcx
leaq 0x28c25(%rip), %rdi     # 0x2f2e0
movl $0x20, %esi
movl $0x1, %edx
callq 0x20e0
cmpq $0x0, %rax
jne 0x66fe
movq -0x8(%rbp), %rdi
callq 0x20d0
cmpl $0x0, %eax
je 0x66ee
leaq 0x58c8(%rip), %rdi      # 0xbfad
movb $0x0, %al
callq 0x3340
jmp 0x66fc
leaq 0x58d4(%rip), %rdi      # 0xbfc9
movb $0x0, %al
callq 0x3340
jmp 0x66fe
jmp 0x6700
leaq 0x28bd9(%rip), %rax     # 0x2f2e0
addq $0x20, %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x20e0
movq %rax, -0x100(%rbp)
cmpq $0x0, -0x100(%rbp)
jne 0x675e
movq -0x8(%rbp), %rdi
callq 0x20d0
cmpl $0x0, %eax
je 0x6759
leaq 0x5891(%rip), %rdi      # 0xbfe3
movb $0x0, %al
callq 0x3340
jmp 0x6813
leaq -0xf0(%rbp), %rdi
movq -0x100(%rbp), %rax
movl %eax, %ecx
leaq 0x28b6b(%rip), %rsi     # 0x2f2e0
movq %rsi, %rdx
addq $0x10020, %rdx          # imm = 0x10020
callq 0x6bf0
leaq -0xb0(%rbp), %rdi
movq -0x100(%rbp), %rdx
leaq 0x28b47(%rip), %rsi     # 0x2f2e0
addq $0x10020, %rsi          # imm = 0x10020
callq 0xa650
movq -0x100(%rbp), %rsi
movq -0x10(%rbp), %rcx
leaq 0x28b29(%rip), %rdi     # 0x2f2e0
addq $0x10020, %rdi          # imm = 0x10020
movl $0x1, %edx
callq 0x2330
cmpq $0x0, %rax
jne 0x67dc
leaq 0x582c(%rip), %rdi      # 0xc001
movb $0x0, %al
callq 0x3340
leaq 0x28afd(%rip), %rax     # 0x2f2e0
addq -0x100(%rbp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x28af8(%rip)    # 0x2f2f0
movups %xmm0, 0x28ae1(%rip)    # 0x2f2e0
cmpq $0x10000, -0x100(%rbp) # imm = 0x10000
jae 0x680e
jmp 0x6813
jmp 0x6700
leaq -0xb0(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x6170
leaq -0x40(%rbp), %rsi
leaq 0x28aae(%rip), %rdi     # 0x2f2e0
movl $0x20, %edx
callq 0x21c0
cmpl $0x0, %eax
je 0x684f
leaq 0x57d6(%rip), %rdi      # 0xc01e
movb $0x0, %al
callq 0x3340
movq -0x10(%rbp), %rdi
callq 0x2250
cmpl $0x0, %eax
je 0x687a
callq 0x2070
movl (%rax), %edi
callq 0x2350
movq %rax, %rsi
leaq 0x57be(%rip), %rdi      # 0xc031
movb $0x0, %al
callq 0x3340
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)