// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/aezv3/aesni/aez_ni.c
// Function: cipher_aez_core
int cipher_aez_core(aez_ctx_t *ctx, __m128i t, int d, char *src, unsigned bytes, unsigned abytes, char *dst) {
    __m128i s, x, y, frag0, frag1, final0, final1;
    __m128i I=ctx->I, L=ctx->L, J=ctx->J[0], J4=ctx->J[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, (__m128i*)src, initial_bytes, (__m128i*)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, J4),     I, J, L, x);
        x  = vxor(x, aes4(vxor3(frag1, J4, J), I, J, L, zero));
    } else if (frag_bytes) {
        frag0 = one_zero_pad(load(src + initial_bytes), 16-frag_bytes);
        x = aes4(vxor(frag0, J4),     I, J, 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->J[d]), I, J, L, final0);
    final1 = vxor(final1, aes((__m128i*)ctx, vxor(final0, ctx->J[d])));
    s = vxor(final0, final1);
    final0 = vxor(final0, aes((__m128i*)ctx, vxor(final1, ctx->J[d^1])));
    /* Decryption: final0 should hold abytes zero bytes. If not, failure */
    if (d && !_mm_testc_si128(loadu(pad+abytes),final0)) return -1;
    final1 = aes4(vxor(final0, ctx->J[d^1]), I, J, L, final1);

    /* Compute y and store final results */
    y = pass_two(ctx, s, (__m128i*)dst, initial_bytes, (__m128i*)dst);
    if (frag_bytes >= 16) {
        frag0 = vxor(frag0, aes((__m128i*)ctx, vxor(s, J4)));
        frag1 = vxor(frag1, aes((__m128i*)ctx, vxor3(s, J4, J)));
        frag1 = one_zero_pad(frag1, 32-frag_bytes);
        y  = aes4(vxor(frag0, J4),     I, J, L, y);
        y  = vxor(y, aes4(vxor3(frag1, J4, J), I, J, L, zero));
       store(dst + initial_bytes, frag0);
       store(dst + initial_bytes + 16, frag1);
    } else if (frag_bytes) {
        frag0 = vxor(frag0, aes((__m128i*)ctx, vxor(s, J4)));
        frag0 = one_zero_pad(frag0, 16-frag_bytes);
        y = aes4(vxor(frag0, J4), I, J, 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 $0x118, %rsp            # imm = 0x118
movq %rdi, %r15
vmovaps (%rdi), %xmm1
vmovaps %xmm1, 0x70(%rsp)
vmovaps 0x10(%rdi), %xmm1
vmovaps %xmm1, 0x80(%rsp)
movq %r9, %rbx
movq %rdx, %r13
vmovaps %xmm0, 0xd0(%rsp)
vmovaps 0x20(%rdi), %xmm0
vmovaps %xmm0, 0x40(%rsp)
vmovdqa 0x40(%rdi), %xmm0
vmovdqa %xmm0, 0x30(%rsp)
xorl %eax, %eax
movl %esi, 0xc(%rsp)
testl %esi, %esi
movl %r8d, 0x8(%rsp)
cmovel %r8d, %eax
addl %ecx, %eax
movl %eax, %r14d
andl $0x1f, %r14d
movq %rax, 0xa8(%rsp)
movl %eax, %r12d
andl $-0x20, %r12d
addl $-0x20, %r12d
movq %rdx, %rsi
movl %r12d, %edx
movq %r9, %rcx
callq 0x1070
movl %r14d, %edx
movl %r12d, %ecx
cmpl $0x10, %r14d
movq %rcx, 0xa0(%rsp)
movq %rdx, 0x98(%rsp)
jb 0x276c
vmovdqu (%r13,%rcx), %xmm2
leaq 0x1a24(%rip), %rax      # 0x4100
subq %rdx, %rax
vmovdqu 0x20(%rax), %xmm1
vmovdqu 0x30(%rax), %xmm3
vpternlogq $0xf8, 0x10(%r13,%rcx), %xmm1, %xmm3
vmovdqa %xmm2, 0xb0(%rsp)
vmovdqa 0x30(%rsp), %xmm7
vpxor %xmm7, %xmm2, %xmm1
vmovdqa 0x70(%rsp), %xmm4
vaesenc %xmm4, %xmm1, %xmm1
vmovdqa 0x40(%rsp), %xmm6
vaesenc %xmm6, %xmm1, %xmm1
vmovdqa 0x80(%rsp), %xmm5
vaesenc %xmm5, %xmm1, %xmm1
vaesenc %xmm0, %xmm1, %xmm0
vmovdqa %xmm3, 0xf0(%rsp)
vmovdqa %xmm3, %xmm1
vpternlogq $0x96, %xmm6, %xmm7, %xmm1
vaesenc %xmm4, %xmm1, %xmm1
vaesenc %xmm6, %xmm1, %xmm1
vaesenc %xmm5, %xmm1, %xmm1
vpxor %xmm2, %xmm2, %xmm2
vaesenc %xmm2, %xmm1, %xmm1
vpxor %xmm0, %xmm1, %xmm0
movl 0x8(%rsp), %edx
vmovdqa %xmm5, %xmm3
vmovdqa %xmm6, %xmm5
jmp 0x27cc
vmovdqa 0x40(%rsp), %xmm5
vmovdqa 0x70(%rsp), %xmm4
vmovdqa 0x80(%rsp), %xmm3
testl %r14d, %r14d
je 0x27c8
leaq 0x1973(%rip), %rax      # 0x4100
subq %rdx, %rax
vmovdqu 0x10(%rax), %xmm1
vmovdqu 0x20(%rax), %xmm2
vpternlogq $0xf8, (%r13,%rcx), %xmm1, %xmm2
vmovdqa %xmm2, 0xb0(%rsp)
vpxor 0x30(%rsp), %xmm2, %xmm1
vaesenc %xmm4, %xmm1, %xmm1
vaesenc %xmm5, %xmm1, %xmm1
vaesenc %xmm3, %xmm1, %xmm1
vaesenc %xmm0, %xmm1, %xmm0
jmp 0x27c8
movl 0x8(%rsp), %edx
leaq 0x20(%r15), %rbp
movq 0xa8(%rsp), %rax
leal -0x20(%rax), %esi
vmovdqa 0xd0(%rsp), %xmm1
vpternlogq $0x96, (%r13,%rsi), %xmm1, %xmm0
cmpl $0x0, 0xc(%rsp)
setne %al
testl %edx, %edx
sete %cl
vmovdqu 0x10(%r13,%rsi), %xmm2
orb %al, %cl
movl %edx, %ecx
movq %rsi, 0xc8(%rsp)
movq %rcx, 0x20(%rsp)
jne 0x2820
leaq 0x18e5(%rip), %rax      # 0x4100
vpand (%rcx,%rax), %xmm2, %xmm2
movl 0xc(%rsp), %r13d
movslq %r13d, %rax
shlq $0x4, %rax
vmovdqa (%rbp,%rax), %xmm1
vmovdqa %xmm2, 0x10(%rsp)
vpxor %xmm2, %xmm1, %xmm2
vaesenc %xmm4, %xmm2, %xmm2
vaesenc %xmm5, %xmm2, %xmm2
vaesenc %xmm3, %xmm2, %xmm2
vaesenc %xmm0, %xmm2, %xmm0
vmovdqa %xmm0, 0x60(%rsp)
vpxor %xmm1, %xmm0, %xmm0
movq %r15, %rdi
callq 0x2b2f
vpxor 0x10(%rsp), %xmm0, %xmm0
movl %r13d, %eax
xorl $0x1, %eax
cltq
shlq $0x4, %rax
vmovdqa (%rbp,%rax), %xmm1
vmovdqa %xmm0, 0x10(%rsp)
vmovdqa %xmm1, 0x50(%rsp)
vpxor %xmm1, %xmm0, %xmm0
movq %r15, %rdi
callq 0x2b2f
vmovdqa 0x60(%rsp), %xmm2
vpxor %xmm2, %xmm0, %xmm1
vmovdqa %xmm1, 0x100(%rsp)
testl %r13d, %r13d
je 0x28c6
leaq 0x184f(%rip), %rax      # 0x4100
movq 0x20(%rsp), %rcx
vmovdqu (%rcx,%rax), %xmm0
vptest %xmm1, %xmm0
jae 0x2b1a
vpxor 0x10(%rsp), %xmm2, %xmm0
movq %r15, %rdi
vmovdqa %xmm0, 0x20(%rsp)
movl %r12d, %edx
movq %rbx, %rcx
vmovdqa %xmm1, 0x60(%rsp)
callq 0x1060
vmovdqa 0x60(%rsp), %xmm4
vmovdqa %xmm0, %xmm6
vpxor 0x50(%rsp), %xmm4, %xmm0
vmovdqa 0x70(%rsp), %xmm2
vaesenc %xmm2, %xmm0, %xmm0
vmovdqa 0x40(%rsp), %xmm3
vaesenc %xmm3, %xmm0, %xmm0
vmovdqa 0x80(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vaesenc 0x10(%rsp), %xmm0, %xmm5
cmpl $0x10, %r14d
jb 0x2a21
vmovaps 0x20(%rsp), %xmm0
vxorps 0x30(%rsp), %xmm0, %xmm0
vmovaps %xmm0, 0xe0(%rsp)
movq %r15, %rdi
vmovdqa %xmm5, 0x10(%rsp)
vmovdqa %xmm6, 0x50(%rsp)
callq 0x2b2f
vxorps 0xb0(%rsp), %xmm0, %xmm0
vmovaps %xmm0, 0x20(%rsp)
vmovdqa 0xe0(%rsp), %xmm0
vpxor 0x40(%rsp), %xmm0, %xmm0
movq %r15, %rdi
callq 0x2b2f
vmovdqa 0x10(%rsp), %xmm5
vmovdqa 0x60(%rsp), %xmm4
vpxor 0xf0(%rsp), %xmm0, %xmm0
leaq 0x176a(%rip), %rax      # 0x4100
subq 0x98(%rsp), %rax
vmovdqu 0x20(%rax), %xmm1
vpternlogq $0xea, 0x30(%rax), %xmm0, %xmm1
vmovdqa 0x30(%rsp), %xmm2
vmovdqa 0x20(%rsp), %xmm7
vpxor %xmm2, %xmm7, %xmm0
vmovdqa 0x70(%rsp), %xmm8
vaesenc %xmm8, %xmm0, %xmm0
vmovdqa 0x40(%rsp), %xmm6
vaesenc %xmm6, %xmm0, %xmm0
vmovdqa 0x80(%rsp), %xmm3
vaesenc %xmm3, %xmm0, %xmm0
vaesenc 0x50(%rsp), %xmm0, %xmm0
vpternlogq $0x96, %xmm6, %xmm1, %xmm2
vaesenc %xmm8, %xmm2, %xmm2
vaesenc %xmm6, %xmm2, %xmm2
vaesenc %xmm3, %xmm2, %xmm2
vpxor %xmm3, %xmm3, %xmm3
vaesenc %xmm3, %xmm2, %xmm2
vpxor %xmm0, %xmm2, %xmm6
movq 0xa0(%rsp), %rax
vmovdqu %xmm7, (%rbx,%rax)
vmovdqu %xmm1, 0x10(%rbx,%rax)
jmp 0x2ab1
vmovdqa 0x20(%rsp), %xmm7
testl %r14d, %r14d
vmovdqa 0x30(%rsp), %xmm0
je 0x2ab1
vpxor %xmm0, %xmm7, %xmm0
movq %r15, %rdi
vmovdqa %xmm5, 0x10(%rsp)
vmovdqa %xmm6, 0x50(%rsp)
callq 0x2b2f
vmovdqa 0x50(%rsp), %xmm6
vmovdqa 0x10(%rsp), %xmm5
vmovdqa 0x60(%rsp), %xmm4
vpxor 0xb0(%rsp), %xmm0, %xmm0
leaq 0x1694(%rip), %rax      # 0x4100
subq 0x98(%rsp), %rax
vmovdqu 0x10(%rax), %xmm1
vpternlogq $0xea, 0x20(%rax), %xmm0, %xmm1
vpxor 0x30(%rsp), %xmm1, %xmm0
vaesenc 0x70(%rsp), %xmm0, %xmm0
vaesenc 0x40(%rsp), %xmm0, %xmm0
vaesenc 0x80(%rsp), %xmm0, %xmm0
vaesenc %xmm6, %xmm0, %xmm6
movq 0xa0(%rsp), %rax
vmovdqu %xmm1, (%rbx,%rax)
movl 0x8(%rsp), %edx
testl %edx, %edx
sete %al
cmpl $0x0, 0xc(%rsp)
sete %cl
vmovdqa 0xd0(%rsp), %xmm0
vpternlogq $0x96, %xmm6, %xmm5, %xmm0
movq 0xc8(%rsp), %rsi
vmovdqu %xmm0, (%rbx,%rsi)
orb %al, %cl
jne 0x2b10
pushq $0x10
popq %rcx
subl %edx, %ecx
movq 0xa8(%rsp), %rax
addl $-0x10, %eax
addq %rax, %rbx
xorl %eax, %eax
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x2b1d
movb 0x100(%rsp,%rdx), %sil
movb %sil, (%rbx,%rdx)
incq %rdx
jmp 0x2afa
vmovdqu %xmm4, 0x10(%rbx,%rsi)
xorl %eax, %eax
jmp 0x2b1d
pushq $-0x1
popq %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq