// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/aezv4/aesni/encrypt.c
// Function: cipher_aez_core
int cipher_aez_core(aez_ctx_t *ctx, block t, int d, char *src, unsigned bytes, unsigned abytes, char *dst) {
    block s, x, y, frag0, frag1, final0, final1;
    block I=ctx->I[0], L=ctx->L, J=ctx->J[0], I4=ctx->I[2];
    unsigned i, frag_bytes, initial_bytes;
    
    if (!d) bytes += abytes;
    frag_bytes = bytes % 32;
    initial_bytes = bytes - frag_bytes - 32;
    
    /* Compute x and store intermediate results */
    x = pass_one(ctx, (block*)src, initial_bytes, (block*)dst);
    if (frag_bytes >= 16) {
        frag0 = load(src + initial_bytes);
        frag1 = one_zero_pad(load(src + initial_bytes + 16), 32-frag_bytes);
        x  = aes4(vxor(frag0, I4),     J, I, L, x);
        x  = vxor(x, aes4(vxor3(frag1, I4, I), J, I, L, zero));
    } else if (frag_bytes) {
        frag0 = one_zero_pad(load(src + initial_bytes), 16-frag_bytes);
        x = aes4(vxor(frag0, I4),     J, I, L, x);
    }
    
    /* Calculate s and final block values (y xor'd to final1 later) */
    final0 = vxor3(loadu(src + (bytes - 32)), x, t);
    if (d || !abytes) final1 = loadu(src+(bytes-32)+16);
    else              final1 = zero_pad(loadu(src+(bytes-32)+16), abytes);
    final0 = aes4(vxor(final1, ctx->I[d]), J, I, L, final0);
    final1 = vxor(final1, aes((block*)ctx, final0, ctx->J[d]));
    s = vxor(final0, final1);
    final0 = vxor(final0, aes((block*)ctx, final1, ctx->J[d^1]));
    /* Decryption: final0 should hold abytes zero bytes. If not, failure */
    if (d && !is_zero(vandnot(loadu(pad+abytes),final0))) return -1;
    final1 = aes4(vxor(final0, ctx->I[d^1]), J, I, L, final1);
    
    /* Compute y and store final results */
    y = pass_two(ctx, s, initial_bytes, (block*)dst);
    if (frag_bytes >= 16) {
        frag0 = vxor(frag0, aes((block*)ctx, s, ctx->J[2]));
        frag1 = vxor(frag1, aes((block*)ctx, s, vxor(ctx->J[2], J)));
        frag1 = one_zero_pad(frag1, 32-frag_bytes);
        y  = aes4(vxor(frag0, I4),     J, I, L, y);
        y  = vxor(y, aes4(vxor3(frag1, I4, I), J, I, L, zero));
        store(dst + initial_bytes, frag0);
        store(dst + initial_bytes + 16, frag1);
    } else if (frag_bytes) {
        frag0 = vxor(frag0, aes((block*)ctx, s, ctx->J[2]));
        frag0 = one_zero_pad(frag0, 16-frag_bytes);
        y = aes4(vxor(frag0, I4), J, I, L, y);
        store(dst + initial_bytes, frag0);
    }
    
    storeu(dst + (bytes - 32), vxor3(final1, y, t));
    if (!d || !abytes)
        storeu(dst + (bytes - 32) + 16, final0);
    else {
        for (i=0; i<16-abytes; i++)
            ((char*)dst + (bytes - 16))[i] = ((char*)&final0)[i];
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %r15
vmovaps (%rdi), %xmm1
vmovaps %xmm1, 0x60(%rsp)
vmovaps 0x20(%rdi), %xmm1
vmovaps %xmm1, 0x90(%rsp)
movq %r9, %rbx
movq %rdx, %r13
vmovaps %xmm0, 0xe0(%rsp)
vmovaps 0x30(%rdi), %xmm0
vmovaps %xmm0, 0x20(%rsp)
vmovdqa 0x60(%rdi), %xmm0
vmovdqa %xmm0, 0x50(%rsp)
xorl %eax, %eax
movl %esi, 0xc(%rsp)
testl %esi, %esi
movl %r8d, 0x8(%rsp)
cmovel %r8d, %eax
addl %ecx, %eax
movl %eax, %ebp
andl $0x1f, %ebp
movq %rax, 0x88(%rsp)
movl %eax, %r12d
andl $-0x20, %r12d
addl $-0x20, %r12d
movq %rdx, %rsi
movl %r12d, %edx
movq %r9, %rcx
callq 0x1070
vmovdqa 0x90(%rsp), %xmm7
movl %ebp, %edx
movl %r12d, %ecx
cmpl $0x10, %ebp
movq %rcx, 0x80(%rsp)
movq %rdx, 0x78(%rsp)
movl %ebp, 0x30(%rsp)
jb 0x25e4
vmovdqu (%r13,%rcx), %xmm2
leaq 0x1b37(%rip), %rax      # 0x4090
subq %rdx, %rax
vmovdqu 0x20(%rax), %xmm1
vmovdqu 0x30(%rax), %xmm3
vpternlogq $0xf8, 0x10(%r13,%rcx), %xmm1, %xmm3
vmovdqa %xmm2, 0xa0(%rsp)
vpxor %xmm7, %xmm2, %xmm1
vmovdqa 0x20(%rsp), %xmm5
vaesenc %xmm5, %xmm1, %xmm1
vmovdqa 0x60(%rsp), %xmm4
vaesenc %xmm4, %xmm1, %xmm1
vmovdqa 0x50(%rsp), %xmm6
vaesenc %xmm6, %xmm1, %xmm1
vaesenc %xmm0, %xmm1, %xmm0
vmovdqa %xmm3, 0x100(%rsp)
vmovdqa %xmm3, %xmm1
vpternlogq $0x96, %xmm4, %xmm7, %xmm1
vaesenc %xmm5, %xmm1, %xmm1
vaesenc %xmm4, %xmm1, %xmm1
vaesenc %xmm6, %xmm1, %xmm1
vpxor %xmm2, %xmm2, %xmm2
vaesenc %xmm2, %xmm1, %xmm1
vpxor %xmm0, %xmm1, %xmm0
movl 0x8(%rsp), %edx
vmovdqa %xmm4, %xmm2
vmovdqa %xmm6, %xmm3
vmovdqa %xmm5, %xmm4
jmp 0x2643
vmovdqa 0x20(%rsp), %xmm4
vmovdqa 0x50(%rsp), %xmm3
vmovdqa 0x60(%rsp), %xmm2
testl %ebp, %ebp
je 0x263f
leaq 0x1a8f(%rip), %rax      # 0x4090
subq %rdx, %rax
vmovdqu 0x10(%rax), %xmm1
vmovdqu 0x20(%rax), %xmm5
vpternlogq $0xf8, (%r13,%rcx), %xmm1, %xmm5
vmovdqa %xmm5, 0xa0(%rsp)
vpxor 0x90(%rsp), %xmm5, %xmm1
vaesenc %xmm4, %xmm1, %xmm1
vaesenc %xmm2, %xmm1, %xmm1
vaesenc %xmm3, %xmm1, %xmm1
vaesenc %xmm0, %xmm1, %xmm0
jmp 0x263f
movl 0x8(%rsp), %edx
leaq 0x30(%r15), %rbp
movq 0x88(%rsp), %rax
leal -0x20(%rax), %esi
vmovdqa 0xe0(%rsp), %xmm1
vpternlogq $0x96, (%r13,%rsi), %xmm1, %xmm0
cmpl $0x0, 0xc(%rsp)
setne %al
testl %edx, %edx
sete %cl
vmovdqu 0x10(%r13,%rsi), %xmm1
orb %al, %cl
movl %edx, %ecx
movq %rsi, 0xd8(%rsp)
movq %rcx, 0xc0(%rsp)
jne 0x269a
leaq 0x19fb(%rip), %rax      # 0x4090
vpand (%rcx,%rax), %xmm1, %xmm1
movl 0xc(%rsp), %r14d
movslq %r14d, %rax
shlq $0x4, %rax
vmovdqa %xmm1, 0x10(%rsp)
vpxor (%r15,%rax), %xmm1, %xmm1
vaesenc %xmm4, %xmm1, %xmm1
vaesenc %xmm2, %xmm1, %xmm1
vaesenc %xmm3, %xmm1, %xmm1
vaesenc %xmm0, %xmm1, %xmm0
vmovdqa %xmm0, 0x40(%rsp)
vmovaps (%rbp,%rax), %xmm1
movq %r15, %rdi
callq 0x29a6
vpxor 0x10(%rsp), %xmm0, %xmm0
movl %r14d, %eax
xorl $0x1, %eax
movslq %eax, %r13
shlq $0x4, %r13
vmovaps (%rbp,%r13), %xmm1
movq %r15, %rdi
vmovdqa %xmm0, 0x10(%rsp)
callq 0x29a6
vmovdqa 0x40(%rsp), %xmm2
vpxor %xmm2, %xmm0, %xmm1
vmovdqa %xmm1, 0x110(%rsp)
testl %r14d, %r14d
je 0x2739
leaq 0x196f(%rip), %rax      # 0x4090
movq 0xc0(%rsp), %rcx
vmovdqu (%rcx,%rax), %xmm0
vptest %xmm1, %xmm0
jae 0x2991
vpxor 0x10(%rsp), %xmm2, %xmm0
vmovdqa %xmm1, 0xc0(%rsp)
vpxor (%r15,%r13), %xmm1, %xmm1
vmovdqa %xmm1, 0xb0(%rsp)
movq %r15, %rdi
vmovdqa %xmm0, 0x40(%rsp)
movl %r12d, %esi
movq %rbx, %rdx
callq 0x1060
vmovdqa %xmm0, %xmm5
vmovdqa 0x20(%rsp), %xmm4
vmovdqa 0xb0(%rsp), %xmm0
vaesenc %xmm4, %xmm0, %xmm0
vmovdqa 0x60(%rsp), %xmm2
vaesenc %xmm2, %xmm0, %xmm0
vmovdqa 0x50(%rsp), %xmm3
vaesenc %xmm3, %xmm0, %xmm0
vaesenc 0x10(%rsp), %xmm0, %xmm6
movl 0x30(%rsp), %eax
cmpl $0x10, %eax
jb 0x289d
vmovaps 0x50(%r15), %xmm1
vmovaps %xmm1, 0xf0(%rsp)
movq %r15, %rdi
vmovaps 0x40(%rsp), %xmm0
vmovdqa %xmm6, 0x10(%rsp)
vmovdqa %xmm5, 0x30(%rsp)
callq 0x29a6
vxorps 0xa0(%rsp), %xmm0, %xmm0
vmovaps %xmm0, 0xb0(%rsp)
vmovaps 0xf0(%rsp), %xmm0
vxorps 0x20(%rsp), %xmm0, %xmm1
movq %r15, %rdi
vmovdqa 0x40(%rsp), %xmm0
callq 0x29a6
vpxor 0x100(%rsp), %xmm0, %xmm0
leaq 0x187b(%rip), %rax      # 0x4090
subq 0x78(%rsp), %rax
vmovdqu 0x20(%rax), %xmm1
vpternlogq $0xea, 0x30(%rax), %xmm0, %xmm1
vmovdqa 0x90(%rsp), %xmm2
vmovdqa 0xb0(%rsp), %xmm4
vpxor %xmm2, %xmm4, %xmm0
vmovdqa 0x20(%rsp), %xmm6
vaesenc %xmm6, %xmm0, %xmm0
vmovdqa 0x60(%rsp), %xmm5
vaesenc %xmm5, %xmm0, %xmm0
vmovdqa 0x50(%rsp), %xmm3
vaesenc %xmm3, %xmm0, %xmm0
vaesenc 0x30(%rsp), %xmm0, %xmm0
vpternlogq $0x96, %xmm5, %xmm1, %xmm2
vaesenc %xmm6, %xmm2, %xmm2
vaesenc %xmm5, %xmm2, %xmm2
vaesenc %xmm3, %xmm2, %xmm2
vpxor %xmm3, %xmm3, %xmm3
vaesenc %xmm3, %xmm2, %xmm2
vpxor %xmm0, %xmm2, %xmm5
movq 0x80(%rsp), %rax
vmovdqu %xmm4, (%rbx,%rax)
vmovdqu %xmm1, 0x10(%rbx,%rax)
jmp 0x2919
vmovdqa 0x40(%rsp), %xmm0
testl %eax, %eax
je 0x291f
vmovdqa %xmm6, 0x10(%rsp)
vmovaps 0x50(%r15), %xmm1
movq %r15, %rdi
vmovdqa %xmm5, 0x30(%rsp)
callq 0x29a6
vmovdqa 0x30(%rsp), %xmm5
vpxor 0xa0(%rsp), %xmm0, %xmm0
leaq 0x17b9(%rip), %rax      # 0x4090
subq 0x78(%rsp), %rax
vmovdqu 0x10(%rax), %xmm1
vpternlogq $0xea, 0x20(%rax), %xmm0, %xmm1
vpxor 0x90(%rsp), %xmm1, %xmm0
vaesenc 0x20(%rsp), %xmm0, %xmm0
vaesenc 0x60(%rsp), %xmm0, %xmm0
vaesenc 0x50(%rsp), %xmm0, %xmm0
vaesenc %xmm5, %xmm0, %xmm5
movq 0x80(%rsp), %rax
vmovdqu %xmm1, (%rbx,%rax)
vmovdqa 0x10(%rsp), %xmm6
movl 0x8(%rsp), %edx
testl %edx, %edx
sete %al
cmpl $0x0, 0xc(%rsp)
sete %cl
vmovdqa 0xe0(%rsp), %xmm0
vpternlogq $0x96, %xmm5, %xmm6, %xmm0
movq 0xd8(%rsp), %rsi
vmovdqu %xmm0, (%rbx,%rsi)
orb %al, %cl
vmovdqa 0xc0(%rsp), %xmm0
jne 0x2987
pushq $0x10
popq %rcx
subl %edx, %ecx
movq 0x88(%rsp), %rax
addl $-0x10, %eax
addq %rax, %rbx
xorl %eax, %eax
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x2994
movb 0x110(%rsp,%rdx), %sil
movb %sil, (%rbx,%rdx)
incq %rdx
jmp 0x2971
vmovdqu %xmm0, 0x10(%rbx,%rsi)
xorl %eax, %eax
jmp 0x2994
pushq $-0x1
popq %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq