// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aezv4/ref/encrypt.c
// Function: E
static void E(byte *K, unsigned kbytes, int j, unsigned i,
                                                byte src[16], byte dst[16]) {
    byte extracted_key[3*16], buf[16], delta[16], I[16], J[16], L[16];

    Extract(K, kbytes, extracted_key);
    memcpy(I,extracted_key,16);
    memcpy(J,extracted_key+16,16);
    memcpy(L,extracted_key+32,16);

    /* Encipher */
    if (j == -1) {
        u32 aes_key[4*11];
        memset(aes_key,0,16);                                  /* 0        */
        memcpy((byte*)aes_key+ 16, extracted_key, 48);         /* I J L    */
        correct_key(aes_key+4,3*16);
        memcpy((byte*)aes_key+ 64, (byte*)aes_key+16, 48);     /* I J L    */
        memcpy((byte*)aes_key+112, (byte*)aes_key+16, 48);     /* I J L    */
        memcpy((byte*)aes_key+160, (byte*)aes_key+16, 16);     /* I        */
        mult_block(i,J,buf); xor_bytes(buf,src,16,buf);
        rijndaelEncryptRound(aes_key, 99, buf, 10); /*incl final MixColumns*/
    } else {
        u32 aes4_key[4*5];
	    memset(aes4_key,0,16);
        if (j==2) {
        	memcpy((byte*)aes4_key+16, L, 16);
        	memcpy((byte*)aes4_key+32, I, 16);
        	memcpy((byte*)aes4_key+48, J, 16);
        	memcpy((byte*)aes4_key+64, L, 16);
        } else {
        	memcpy((byte*)aes4_key+16, J, 16);
        	memcpy((byte*)aes4_key+32, I, 16);
        	memcpy((byte*)aes4_key+48, L, 16);
	        memset((byte*)aes4_key+64,0,16);
        }
        correct_key(aes4_key+4,4*16);
        if (j==0) {
        	mult_block(i,I,buf); xor_bytes(buf, src, 16, buf);
        	rijndaelEncryptRound(aes4_key, 99, buf, 4);
        } else if (j==1 || j==2) {
        	mult_block((i-1)%8,I,delta);
        	for (i=3+(i-1)/8; i>0; i--) mult_block(2,I,I);
        	xor_bytes(delta, I, 16, delta);
        	xor_bytes(delta, src, 16, buf);
        	rijndaelEncryptRound(aes4_key, 99, buf, 4);
        } else if (j>=3 && i==0) {
        	mult_block(1<<(j-3),L,delta); xor_bytes(delta, src, 16, buf);
        	rijndaelEncryptRound(aes4_key, 99, buf, 4);
        	xor_bytes(buf, delta, 16, buf);
        } else {
        	mult_block(1<<(j-3),L,delta);
        	mult_block((i-1)%8,J,buf); xor_bytes(delta, buf, 16, delta);
        	for (i=3+(i-1)/8; i>0; i--) mult_block(2,J,J);
        	xor_bytes(delta, J, 16, delta);
        	xor_bytes(src, delta, 16, buf);
        	rijndaelEncryptRound(aes4_key, 99, buf, 4);
        	xor_bytes(buf, delta, 16, buf);
        }
    }
    memcpy(dst, buf, 16);
}

// Assembly:
subq $0x1a8, %rsp            # imm = 0x1A8
movq %rdi, 0x1a0(%rsp)
movl %esi, 0x19c(%rsp)
movl %edx, 0x198(%rsp)
movl %ecx, 0x194(%rsp)
movq %r8, 0x188(%rsp)
movq %r9, 0x180(%rsp)
movq 0x1a0(%rsp), %rdi
movl 0x19c(%rsp), %esi
leaq 0x150(%rsp), %rdx
callq 0x3530
movq 0x150(%rsp), %rax
movq %rax, 0x120(%rsp)
movq 0x158(%rsp), %rax
movq %rax, 0x128(%rsp)
movq 0x160(%rsp), %rax
movq %rax, 0x110(%rsp)
movq 0x168(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x170(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x178(%rsp), %rax
movq %rax, 0x108(%rsp)
cmpl $-0x1, 0x198(%rsp)
jne 0x307e
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
leaq 0x50(%rsp), %rdi
addq $0x10, %rdi
leaq 0x150(%rsp), %rsi
movl $0x30, %edx
callq 0x1110
leaq 0x50(%rsp), %rdi
addq $0x10, %rdi
movl $0x30, %esi
callq 0x3590
leaq 0x50(%rsp), %rdi
addq $0x40, %rdi
leaq 0x50(%rsp), %rsi
addq $0x10, %rsi
movl $0x30, %edx
callq 0x1110
leaq 0x50(%rsp), %rdi
addq $0x70, %rdi
leaq 0x50(%rsp), %rsi
addq $0x10, %rsi
movl $0x30, %edx
callq 0x1110
movq 0x60(%rsp), %rax
movq %rax, 0xf0(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0xf8(%rsp)
movl 0x194(%rsp), %edi
leaq 0x110(%rsp), %rsi
leaq 0x140(%rsp), %rdx
callq 0x35f0
leaq 0x140(%rsp), %rdi
movq 0x188(%rsp), %rsi
leaq 0x140(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
leaq 0x50(%rsp), %rdi
leaq 0x140(%rsp), %rdx
movl $0x63, %esi
movl $0xa, %ecx
callq 0x1100
jmp 0x34a8
movq %rsp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
cmpl $0x2, 0x198(%rsp)
jne 0x3101
movq 0x100(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0x48(%rsp)
jmp 0x3162
movq 0x110(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x118(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x108(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %rsp, %rdi
addq $0x40, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
movq %rsp, %rdi
addq $0x10, %rdi
movl $0x40, %esi
callq 0x3590
cmpl $0x0, 0x198(%rsp)
jne 0x31da
movl 0x194(%rsp), %edi
leaq 0x120(%rsp), %rsi
leaq 0x140(%rsp), %rdx
callq 0x35f0
leaq 0x140(%rsp), %rdi
movq 0x188(%rsp), %rsi
leaq 0x140(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
movq %rsp, %rdi
leaq 0x140(%rsp), %rdx
movl $0x63, %esi
movl $0x4, %ecx
callq 0x1100
jmp 0x34a6
cmpl $0x1, 0x198(%rsp)
je 0x31f2
cmpl $0x2, 0x198(%rsp)
jne 0x32c5
movl 0x194(%rsp), %edi
subl $0x1, %edi
andl $0x7, %edi
leaq 0x120(%rsp), %rsi
leaq 0x130(%rsp), %rdx
callq 0x35f0
movl 0x194(%rsp), %eax
subl $0x1, %eax
shrl $0x3, %eax
addl $0x3, %eax
movl %eax, 0x194(%rsp)
cmpl $0x0, 0x194(%rsp)
jbe 0x3262
leaq 0x120(%rsp), %rsi
leaq 0x120(%rsp), %rdx
movl $0x2, %edi
callq 0x35f0
movl 0x194(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x194(%rsp)
jmp 0x322b
leaq 0x130(%rsp), %rdi
leaq 0x120(%rsp), %rsi
leaq 0x130(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
leaq 0x130(%rsp), %rdi
movq 0x188(%rsp), %rsi
leaq 0x140(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
movq %rsp, %rdi
leaq 0x140(%rsp), %rdx
movl $0x63, %esi
movl $0x4, %ecx
callq 0x1100
jmp 0x34a4
cmpl $0x3, 0x198(%rsp)
jl 0x336a
cmpl $0x0, 0x194(%rsp)
jne 0x336a
movl 0x198(%rsp), %ecx
subl $0x3, %ecx
movl $0x1, %edi
shll %cl, %edi
leaq 0x100(%rsp), %rsi
leaq 0x130(%rsp), %rdx
callq 0x35f0
leaq 0x130(%rsp), %rdi
movq 0x188(%rsp), %rsi
leaq 0x140(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
movq %rsp, %rdi
leaq 0x140(%rsp), %rdx
movl $0x63, %esi
movl $0x4, %ecx
callq 0x1100
leaq 0x140(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0x140(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
jmp 0x34a2
movl 0x198(%rsp), %ecx
subl $0x3, %ecx
movl $0x1, %edi
shll %cl, %edi
leaq 0x100(%rsp), %rsi
leaq 0x130(%rsp), %rdx
callq 0x35f0
movl 0x194(%rsp), %edi
subl $0x1, %edi
andl $0x7, %edi
leaq 0x110(%rsp), %rsi
leaq 0x140(%rsp), %rdx
callq 0x35f0
leaq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rsi
leaq 0x130(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
movl 0x194(%rsp), %eax
subl $0x1, %eax
shrl $0x3, %eax
addl $0x3, %eax
movl %eax, 0x194(%rsp)
cmpl $0x0, 0x194(%rsp)
jbe 0x3422
leaq 0x110(%rsp), %rsi
leaq 0x110(%rsp), %rdx
movl $0x2, %edi
callq 0x35f0
movl 0x194(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x194(%rsp)
jmp 0x33eb
leaq 0x130(%rsp), %rdi
leaq 0x110(%rsp), %rsi
leaq 0x130(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
movq 0x188(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0x140(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
movq %rsp, %rdi
leaq 0x140(%rsp), %rdx
movl $0x63, %esi
movl $0x4, %ecx
callq 0x1100
leaq 0x140(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0x140(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
jmp 0x34a4
jmp 0x34a6
jmp 0x34a8
movq 0x180(%rsp), %rax
movq 0x140(%rsp), %rcx
movq %rcx, (%rax)
movq 0x148(%rsp), %rcx
movq %rcx, 0x8(%rax)
addq $0x1a8, %rsp            # imm = 0x1A8
retq
nop