// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x498, %rsp            # imm = 0x498
movq %rdi, 0x160(%rsp)
vmovdqa %xmm0, 0x150(%rsp)
movl %esi, 0x14c(%rsp)
movq %rdx, 0x140(%rsp)
movl %ecx, 0x13c(%rsp)
movl %r8d, 0x138(%rsp)
movq %r9, 0x130(%rsp)
movq 0x160(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, 0xb0(%rsp)
movq 0x160(%rsp), %rax
vmovdqa 0x60(%rax), %xmm0
vmovdqa %xmm0, 0xa0(%rsp)
movq 0x160(%rsp), %rax
vmovdqa 0x30(%rax), %xmm0
vmovdqa %xmm0, 0x90(%rsp)
movq 0x160(%rsp), %rax
vmovdqa 0x20(%rax), %xmm0
vmovdqa %xmm0, 0x80(%rsp)
cmpl $0x0, 0x14c(%rsp)
jne 0x79c4
movl 0x138(%rsp), %eax
addl 0x13c(%rsp), %eax
movl %eax, 0x13c(%rsp)
movl 0x13c(%rsp), %eax
andl $0x1f, %eax
movl %eax, 0x78(%rsp)
movl 0x13c(%rsp), %eax
subl 0x78(%rsp), %eax
subl $0x20, %eax
movl %eax, 0x74(%rsp)
movq 0x160(%rsp), %rdi
movq 0x140(%rsp), %rsi
movl 0x74(%rsp), %edx
movq 0x130(%rsp), %rcx
callq 0x1080
vmovdqa %xmm0, 0x110(%rsp)
cmpl $0x10, 0x78(%rsp)
jb 0x7bb9
movq 0x140(%rsp), %rdi
movl 0x74(%rsp), %eax
addq %rax, %rdi
callq 0x1380
vmovdqa %xmm0, 0xf0(%rsp)
movq 0x140(%rsp), %rax
movl 0x74(%rsp), %ecx
leaq 0x10(%rax,%rcx), %rdi
callq 0x1380
movl 0x78(%rsp), %eax
movl $0x20, %edi
subl %eax, %edi
callq 0x2bf0
vmovdqa %xmm0, 0xe0(%rsp)
vmovdqa 0xf0(%rsp), %xmm1
vmovdqa 0x80(%rsp), %xmm0
vmovdqa %xmm1, 0x460(%rsp)
vmovdqa %xmm0, 0x450(%rsp)
vmovdqa 0x460(%rsp), %xmm0
vmovdqa 0x450(%rsp), %xmm1
vpxor %xmm1, %xmm0, %xmm0
vmovdqa 0x90(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm2
vmovdqa 0xa0(%rsp), %xmm3
vmovdqa 0x110(%rsp), %xmm4
callq 0x2b10
vmovdqa %xmm0, 0x110(%rsp)
vmovdqa 0x110(%rsp), %xmm0
vmovaps %xmm0, 0x60(%rsp)
vmovdqa 0xe0(%rsp), %xmm1
vmovdqa 0x80(%rsp), %xmm0
vmovdqa %xmm1, 0x440(%rsp)
vmovdqa %xmm0, 0x430(%rsp)
vmovdqa 0x440(%rsp), %xmm0
vmovdqa 0x430(%rsp), %xmm1
vpxor %xmm1, %xmm0, %xmm1
vmovdqa 0xb0(%rsp), %xmm0
vmovdqa %xmm1, 0x420(%rsp)
vmovdqa %xmm0, 0x410(%rsp)
vmovdqa 0x420(%rsp), %xmm0
vmovdqa 0x410(%rsp), %xmm1
vpxor %xmm1, %xmm0, %xmm0
vmovdqa 0x90(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm2
vmovdqa 0xa0(%rsp), %xmm3
vpxor %xmm4, %xmm4, %xmm4
vmovdqa %xmm4, 0x180(%rsp)
vmovdqa 0x180(%rsp), %xmm4
callq 0x2b10
vmovaps 0x60(%rsp), %xmm1
vmovdqa %xmm1, 0x400(%rsp)
vmovdqa %xmm0, 0x3f0(%rsp)
vmovdqa 0x400(%rsp), %xmm0
vpxor 0x3f0(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x110(%rsp)
jmp 0x7c59
cmpl $0x0, 0x78(%rsp)
je 0x7c57
movq 0x140(%rsp), %rdi
movl 0x74(%rsp), %eax
addq %rax, %rdi
callq 0x1380
movl $0x10, %edi
subl 0x78(%rsp), %edi
callq 0x2bf0
vmovdqa %xmm0, 0xf0(%rsp)
vmovdqa 0xf0(%rsp), %xmm1
vmovdqa 0x80(%rsp), %xmm0
vmovdqa %xmm1, 0x3e0(%rsp)
vmovdqa %xmm0, 0x3d0(%rsp)
vmovdqa 0x3e0(%rsp), %xmm0
vpxor 0x3d0(%rsp), %xmm0, %xmm0
vmovdqa 0x90(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm2
vmovdqa 0xa0(%rsp), %xmm3
vmovdqa 0x110(%rsp), %xmm4
callq 0x2b10
vmovdqa %xmm0, 0x110(%rsp)
jmp 0x7c59
movq 0x140(%rsp), %rdi
movl 0x13c(%rsp), %eax
subl $0x20, %eax
movl %eax, %eax
addq %rax, %rdi
callq 0x1380
vmovaps %xmm0, %xmm1
vmovdqa 0x110(%rsp), %xmm0
vmovdqa %xmm1, 0x3c0(%rsp)
vmovdqa %xmm0, 0x3b0(%rsp)
vmovdqa 0x3c0(%rsp), %xmm0
vpxor 0x3b0(%rsp), %xmm0, %xmm1
vmovdqa 0x150(%rsp), %xmm0
vmovdqa %xmm1, 0x3a0(%rsp)
vmovdqa %xmm0, 0x390(%rsp)
vmovdqa 0x3a0(%rsp), %xmm0
vpxor 0x390(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0xd0(%rsp)
cmpl $0x0, 0x14c(%rsp)
jne 0x7cf0
cmpl $0x0, 0x138(%rsp)
jne 0x7d1b
movq 0x140(%rsp), %rdi
movl 0x13c(%rsp), %eax
subl $0x20, %eax
movl %eax, %eax
addq %rax, %rdi
addq $0x10, %rdi
callq 0x1380
vmovdqa %xmm0, 0xc0(%rsp)
jmp 0x7d50
movq 0x140(%rsp), %rdi
movl 0x13c(%rsp), %eax
subl $0x20, %eax
movl %eax, %eax
addq %rax, %rdi
addq $0x10, %rdi
callq 0x1380
movl 0x138(%rsp), %edi
callq 0x8510
vmovdqa %xmm0, 0xc0(%rsp)
vmovdqa 0xc0(%rsp), %xmm1
movq 0x160(%rsp), %rax
movslq 0x14c(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm1, 0x380(%rsp)
vmovdqa %xmm0, 0x370(%rsp)
vmovdqa 0x380(%rsp), %xmm0
vpxor 0x370(%rsp), %xmm0, %xmm0
vmovdqa 0x90(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm2
vmovdqa 0xa0(%rsp), %xmm3
vmovdqa 0xd0(%rsp), %xmm4
callq 0x2b10
vmovdqa %xmm0, 0xd0(%rsp)
vmovdqa 0xc0(%rsp), %xmm0
vmovaps %xmm0, 0x40(%rsp)
movq 0x160(%rsp), %rdi
vmovdqa 0xd0(%rsp), %xmm0
movq 0x160(%rsp), %rax
addq $0x30, %rax
movslq 0x14c(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
vmovdqa (%rax), %xmm1
callq 0x8560
vmovaps 0x40(%rsp), %xmm1
vmovdqa %xmm1, 0x360(%rsp)
vmovdqa %xmm0, 0x350(%rsp)
vmovdqa 0x360(%rsp), %xmm0
vpxor 0x350(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0xc0(%rsp)
vmovdqa 0xd0(%rsp), %xmm1
vmovdqa 0xc0(%rsp), %xmm0
vmovdqa %xmm1, 0x340(%rsp)
vmovdqa %xmm0, 0x330(%rsp)
vmovdqa 0x340(%rsp), %xmm0
vpxor 0x330(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x120(%rsp)
vmovdqa 0xd0(%rsp), %xmm0
vmovaps %xmm0, 0x50(%rsp)
movq 0x160(%rsp), %rdi
vmovdqa 0xc0(%rsp), %xmm0
movq 0x160(%rsp), %rax
addq $0x30, %rax
movl 0x14c(%rsp), %ecx
xorl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
vmovdqa (%rax), %xmm1
callq 0x8560
vmovaps 0x50(%rsp), %xmm1
vmovdqa %xmm1, 0x320(%rsp)
vmovdqa %xmm0, 0x310(%rsp)
vmovdqa 0x320(%rsp), %xmm0
vpxor 0x310(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0xd0(%rsp)
cmpl $0x0, 0x14c(%rsp)
je 0x7f6e
movl 0x138(%rsp), %eax
leaq 0x30ec(%rip), %rdi      # 0xb000
addq %rax, %rdi
callq 0x1380
vmovaps %xmm0, %xmm1
vmovdqa 0xd0(%rsp), %xmm0
vmovdqa %xmm1, 0x480(%rsp)
vmovdqa %xmm0, 0x470(%rsp)
vmovdqa 0x480(%rsp), %xmm0
vpternlogq $0xf, %xmm0, %xmm0, %xmm0
vpand 0x470(%rsp), %xmm0, %xmm0
callq 0x87e0
cmpl $0x0, %eax
jne 0x7f6e
movl $0xffffffff, 0x16c(%rsp) # imm = 0xFFFFFFFF
jmp 0x84fc
vmovdqa 0xd0(%rsp), %xmm1
movq 0x160(%rsp), %rax
movl 0x14c(%rsp), %ecx
xorl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm1, 0x300(%rsp)
vmovdqa %xmm0, 0x2f0(%rsp)
vmovdqa 0x300(%rsp), %xmm0
vpxor 0x2f0(%rsp), %xmm0, %xmm0
vmovdqa 0x90(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm2
vmovdqa 0xa0(%rsp), %xmm3
vmovdqa 0xc0(%rsp), %xmm4
callq 0x2b10
vmovdqa %xmm0, 0xc0(%rsp)
movq 0x160(%rsp), %rdi
vmovdqa 0x120(%rsp), %xmm0
movl 0x74(%rsp), %esi
movq 0x130(%rsp), %rdx
callq 0x1070
vmovdqa %xmm0, 0x100(%rsp)
cmpl $0x10, 0x78(%rsp)
jb 0x82ca
vmovdqa 0xf0(%rsp), %xmm0
vmovaps %xmm0, 0x10(%rsp)
movq 0x160(%rsp), %rdi
vmovdqa 0x120(%rsp), %xmm0
vmovdqa 0x50(%rdi), %xmm1
callq 0x8560
vmovaps 0x10(%rsp), %xmm1
vmovdqa %xmm1, 0x2e0(%rsp)
vmovdqa %xmm0, 0x2d0(%rsp)
vmovdqa 0x2e0(%rsp), %xmm0
vmovdqa 0x2d0(%rsp), %xmm1
vpxor %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0xf0(%rsp)
vmovdqa 0xe0(%rsp), %xmm0
vmovaps %xmm0, 0x20(%rsp)
movq 0x160(%rsp), %rdi
vmovdqa 0x120(%rsp), %xmm0
vmovdqa 0x50(%rdi), %xmm2
vmovdqa 0x90(%rsp), %xmm1
vmovdqa %xmm2, 0x2c0(%rsp)
vmovdqa %xmm1, 0x2b0(%rsp)
vmovdqa 0x2c0(%rsp), %xmm1
vmovdqa 0x2b0(%rsp), %xmm2
vpxor %xmm2, %xmm1, %xmm1
callq 0x8560
vmovaps 0x20(%rsp), %xmm1
vmovdqa %xmm1, 0x2a0(%rsp)
vmovdqa %xmm0, 0x290(%rsp)
vmovdqa 0x2a0(%rsp), %xmm0
vmovdqa 0x290(%rsp), %xmm1
vpxor %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0xe0(%rsp)
vmovdqa 0xe0(%rsp), %xmm0
movl 0x78(%rsp), %eax
movl $0x20, %edi
subl %eax, %edi
callq 0x2bf0
vmovdqa %xmm0, 0xe0(%rsp)
vmovdqa 0xf0(%rsp), %xmm1
vmovdqa 0x80(%rsp), %xmm0
vmovdqa %xmm1, 0x280(%rsp)
vmovdqa %xmm0, 0x270(%rsp)
vmovdqa 0x280(%rsp), %xmm0
vmovdqa 0x270(%rsp), %xmm1
vpxor %xmm1, %xmm0, %xmm0
vmovdqa 0x90(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm2
vmovdqa 0xa0(%rsp), %xmm3
vmovdqa 0x100(%rsp), %xmm4
callq 0x2b10
vmovdqa %xmm0, 0x100(%rsp)
vmovdqa 0x100(%rsp), %xmm0
vmovaps %xmm0, 0x30(%rsp)
vmovdqa 0xe0(%rsp), %xmm1
vmovdqa 0x80(%rsp), %xmm0
vmovdqa %xmm1, 0x260(%rsp)
vmovdqa %xmm0, 0x250(%rsp)
vmovdqa 0x260(%rsp), %xmm0
vmovdqa 0x250(%rsp), %xmm1
vpxor %xmm1, %xmm0, %xmm1
vmovdqa 0xb0(%rsp), %xmm0
vmovdqa %xmm1, 0x240(%rsp)
vmovdqa %xmm0, 0x230(%rsp)
vmovdqa 0x240(%rsp), %xmm0
vmovdqa 0x230(%rsp), %xmm1
vpxor %xmm1, %xmm0, %xmm0
vmovdqa 0x90(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm2
vmovdqa 0xa0(%rsp), %xmm3
vpxor %xmm4, %xmm4, %xmm4
vmovdqa %xmm4, 0x170(%rsp)
vmovdqa 0x170(%rsp), %xmm4
callq 0x2b10
vmovaps 0x30(%rsp), %xmm1
vmovdqa %xmm1, 0x220(%rsp)
vmovdqa %xmm0, 0x210(%rsp)
vmovdqa 0x220(%rsp), %xmm0
vpxor 0x210(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x100(%rsp)
movq 0x130(%rsp), %rdi
movl 0x74(%rsp), %eax
addq %rax, %rdi
vmovdqa 0xf0(%rsp), %xmm0
callq 0x4d40
movq 0x130(%rsp), %rdi
movl 0x74(%rsp), %eax
addq %rax, %rdi
addq $0x10, %rdi
vmovdqa 0xe0(%rsp), %xmm0
callq 0x4d40
jmp 0x83df
cmpl $0x0, 0x78(%rsp)
je 0x83dd
vmovdqa 0xf0(%rsp), %xmm0
vmovaps %xmm0, (%rsp)
movq 0x160(%rsp), %rdi
vmovdqa 0x120(%rsp), %xmm0
movq 0x160(%rsp), %rax
vmovdqa 0x50(%rax), %xmm1
callq 0x8560
vmovaps (%rsp), %xmm1
vmovdqa %xmm1, 0x200(%rsp)
vmovdqa %xmm0, 0x1f0(%rsp)
vmovdqa 0x200(%rsp), %xmm0
vpxor 0x1f0(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0xf0(%rsp)
vmovdqa 0xf0(%rsp), %xmm0
movl $0x10, %edi
subl 0x78(%rsp), %edi
callq 0x2bf0
vmovdqa %xmm0, 0xf0(%rsp)
vmovdqa 0xf0(%rsp), %xmm1
vmovdqa 0x80(%rsp), %xmm0
vmovdqa %xmm1, 0x1e0(%rsp)
vmovdqa %xmm0, 0x1d0(%rsp)
vmovdqa 0x1e0(%rsp), %xmm0
vpxor 0x1d0(%rsp), %xmm0, %xmm0
vmovdqa 0x90(%rsp), %xmm1
vmovdqa 0xb0(%rsp), %xmm2
vmovdqa 0xa0(%rsp), %xmm3
vmovdqa 0x100(%rsp), %xmm4
callq 0x2b10
vmovdqa %xmm0, 0x100(%rsp)
movq 0x130(%rsp), %rdi
movl 0x74(%rsp), %eax
addq %rax, %rdi
vmovdqa 0xf0(%rsp), %xmm0
callq 0x4d40
jmp 0x83df
movq 0x130(%rsp), %rdi
movl 0x13c(%rsp), %eax
subl $0x20, %eax
movl %eax, %eax
addq %rax, %rdi
vmovdqa 0xc0(%rsp), %xmm1
vmovdqa 0x100(%rsp), %xmm0
vmovdqa %xmm1, 0x1c0(%rsp)
vmovdqa %xmm0, 0x1b0(%rsp)
vmovdqa 0x1c0(%rsp), %xmm0
vpxor 0x1b0(%rsp), %xmm0, %xmm1
vmovdqa 0x150(%rsp), %xmm0
vmovdqa %xmm1, 0x1a0(%rsp)
vmovdqa %xmm0, 0x190(%rsp)
vmovdqa 0x1a0(%rsp), %xmm0
vpxor 0x190(%rsp), %xmm0, %xmm0
callq 0x4d40
cmpl $0x0, 0x14c(%rsp)
je 0x8472
cmpl $0x0, 0x138(%rsp)
jne 0x849d
movq 0x130(%rsp), %rdi
movl 0x13c(%rsp), %eax
subl $0x20, %eax
movl %eax, %eax
addq %rax, %rdi
addq $0x10, %rdi
vmovdqa 0xd0(%rsp), %xmm0
callq 0x4d40
jmp 0x84f1
movl $0x0, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
movl $0x10, %ecx
subl 0x138(%rsp), %ecx
cmpl %ecx, %eax
jae 0x84ef
movl 0x7c(%rsp), %eax
movb 0xd0(%rsp,%rax), %dl
movq 0x130(%rsp), %rax
movl 0x13c(%rsp), %ecx
subl $0x10, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movl 0x7c(%rsp), %ecx
movb %dl, (%rax,%rcx)
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x84a5
jmp 0x84f1
movl $0x0, 0x16c(%rsp)
movl 0x16c(%rsp), %eax
addq $0x498, %rsp            # imm = 0x498
retq
nopl (%rax,%rax)