// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/hs1sivv2/ref/encrypt.c
// Function: hs1siv_decrypt
int hs1siv_decrypt(hs1siv_ctx_t *ctx, void *c, unsigned cbytes,
                   void *a, unsigned abytes, void *n, void *t, void *m)
{
    unsigned i;
    unsigned abuflen = (abytes+HS1_SIV_NH_LEN-1)/HS1_SIV_NH_LEN*HS1_SIV_NH_LEN;
    unsigned buflen = abuflen + (cbytes+15)/16*16 + 16;
    unsigned char *maybe_m = (unsigned char *)malloc(cbytes);
    unsigned char maybe_t[HS1_SIV_SIV_LEN];
    unsigned char *buf = (unsigned char *)malloc(cbytes+64);
    hs1(ctx, t, HS1_SIV_SIV_LEN, n, buf, cbytes+64);
    for (i=0; i<cbytes; i++)
        ((unsigned char *)maybe_m)[i] = ((unsigned char *)c)[i] ^ buf[64+i];
    free(buf);
    buf = (unsigned char *)malloc(buflen);
    memset(buf, 0, buflen);
    memcpy(buf, a, abytes);
    memcpy(buf+abuflen, maybe_m, cbytes);
    write32le((uint32_t *)(buf+buflen-16), abytes);
    write32le((uint32_t *)(buf+buflen-8), cbytes);
    hs1(ctx, buf, buflen, n, maybe_t, HS1_SIV_SIV_LEN);
    free(buf);
    if (memcmp(t,maybe_t,HS1_SIV_SIV_LEN) == 0) {
        memcpy(m,maybe_m,cbytes);
        free(maybe_m);
        return 0;
    } else {
        free(maybe_m);
        return -1;
    }
}

// Assembly:
subq $0x78, %rsp
movq 0x88(%rsp), %rax
movq 0x80(%rsp), %rax
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movl %edx, 0x5c(%rsp)
movq %rcx, 0x50(%rsp)
movl %r8d, 0x4c(%rsp)
movq %r9, 0x40(%rsp)
movl 0x4c(%rsp), %eax
addl $0x40, %eax
subl $0x1, %eax
shrl $0x6, %eax
shll $0x6, %eax
movl %eax, 0x38(%rsp)
movl 0x38(%rsp), %eax
movl 0x5c(%rsp), %ecx
addl $0xf, %ecx
shrl $0x4, %ecx
shll $0x4, %ecx
addl %ecx, %eax
addl $0x10, %eax
movl %eax, 0x34(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, %edi
callq 0x1080
movq %rax, 0x28(%rsp)
movl 0x5c(%rsp), %eax
addl $0x40, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x1080
movq %rax, 0x8(%rsp)
movq 0x68(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x40(%rsp), %rcx
movq 0x8(%rsp), %r8
movl 0x5c(%rsp), %r9d
addl $0x40, %r9d
movl $0x10, %edx
callq 0x1120
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jae 0x2d4c
movq 0x60(%rsp), %rax
movl 0x3c(%rsp), %ecx
movzbl (%rax,%rcx), %eax
movq 0x8(%rsp), %rcx
movl 0x3c(%rsp), %edx
addl $0x40, %edx
movl %edx, %edx
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, %dl
movq 0x28(%rsp), %rax
movl 0x3c(%rsp), %ecx
movb %dl, (%rax,%rcx)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x2d06
movq 0x8(%rsp), %rdi
callq 0x10a0
movl 0x34(%rsp), %eax
movl %eax, %edi
callq 0x1080
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movl 0x34(%rsp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x1040
movq 0x8(%rsp), %rdi
movq 0x50(%rsp), %rsi
movl 0x4c(%rsp), %eax
movl %eax, %edx
callq 0x1130
movq 0x8(%rsp), %rdi
movl 0x38(%rsp), %eax
addq %rax, %rdi
movq 0x28(%rsp), %rsi
movl 0x5c(%rsp), %eax
movl %eax, %edx
callq 0x1130
movq 0x8(%rsp), %rdi
movl 0x34(%rsp), %eax
addq %rax, %rdi
addq $-0x10, %rdi
movl 0x4c(%rsp), %esi
callq 0x2c10
movq 0x8(%rsp), %rdi
movl 0x34(%rsp), %eax
addq %rax, %rdi
addq $-0x8, %rdi
movl 0x5c(%rsp), %esi
callq 0x2c10
movq 0x68(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x34(%rsp), %edx
movq 0x40(%rsp), %rcx
leaq 0x10(%rsp), %r8
movl $0x10, %r9d
callq 0x1120
movq 0x8(%rsp), %rdi
callq 0x10a0
movq 0x80(%rsp), %rax
leaq 0x10(%rsp), %rcx
vmovdqu (%rcx), %xmm1
vmovdqu (%rax), %xmm0
vpxor %xmm1, %xmm0, %xmm0
vptest %xmm0, %xmm0
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2e5d
movq 0x88(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x5c(%rsp), %eax
movl %eax, %edx
callq 0x1130
movq 0x28(%rsp), %rdi
callq 0x10a0
movl $0x0, 0x74(%rsp)
jmp 0x2e6f
movq 0x28(%rsp), %rdi
callq 0x10a0
movl $0xffffffff, 0x74(%rsp) # imm = 0xFFFFFFFF
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopl (%rax,%rax)