// File: /workspace/github_cpp_makefile_star2_O2/DiplIngFrankGerlach[P]MST/./aes/aes.c
// Function: aes_encrypt
void aes_encrypt(const BYTE in[], BYTE out[], const WORD key[], int keysize)
{
	BYTE state[4][4];

	// Copy input array (should be 16 bytes long) to a matrix (sequential bytes are ordered
	// by row, not col) called "state" for processing.
	// *** Implementation note: The official AES documentation references the state by
	// column, then row. Accessing an element in C requires row then column. Thus, all state
	// references in AES must have the column and row indexes reversed for C implementation.
	state[0][0] = in[0];
	state[1][0] = in[1];
	state[2][0] = in[2];
	state[3][0] = in[3];
	state[0][1] = in[4];
	state[1][1] = in[5];
	state[2][1] = in[6];
	state[3][1] = in[7];
	state[0][2] = in[8];
	state[1][2] = in[9];
	state[2][2] = in[10];
	state[3][2] = in[11];
	state[0][3] = in[12];
	state[1][3] = in[13];
	state[2][3] = in[14];
	state[3][3] = in[15];

	// Perform the necessary number of rounds. The round key is added first.
	// The last round does not perform the MixColumns step.
	AddRoundKey(state,&key[0]);
	SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[4]);
	SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[8]);
	SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[12]);
	SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[16]);
	SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[20]);
	SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[24]);
	SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[28]);
	SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[32]);
	SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[36]);
	if (keysize != 128) {
		SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[40]);
		SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[44]);
		if (keysize != 192) {
			SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[48]);
			SubBytes(state); ShiftRows(state); MixColumns(state); AddRoundKey(state,&key[52]);
			SubBytes(state); ShiftRows(state); AddRoundKey(state,&key[56]);
		}
		else {
			SubBytes(state); ShiftRows(state); AddRoundKey(state,&key[48]);
		}
	}
	else {
		SubBytes(state); ShiftRows(state); AddRoundKey(state,&key[40]);
	}

	// Copy the state to the output array.
	out[0] = state[0][0];
	out[1] = state[1][0];
	out[2] = state[2][0];
	out[3] = state[3][0];
	out[4] = state[0][1];
	out[5] = state[1][1];
	out[6] = state[2][1];
	out[7] = state[3][1];
	out[8] = state[0][2];
	out[9] = state[1][2];
	out[10] = state[2][2];
	out[11] = state[3][2];
	out[12] = state[0][3];
	out[13] = state[1][3];
	out[14] = state[2][3];
	out[15] = state[3][3];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %rbx
movdqu (%rdi), %xmm0
pxor %xmm3, %xmm3
movdqa %xmm0, %xmm1
punpckhbw %xmm3, %xmm1    # xmm1 = xmm1[8],xmm3[8],xmm1[9],xmm3[9],xmm1[10],xmm3[10],xmm1[11],xmm3[11],xmm1[12],xmm3[12],xmm1[13],xmm3[13],xmm1[14],xmm3[14],xmm1[15],xmm3[15]
pshufd $0xe7, %xmm1, %xmm2     # xmm2 = xmm1[3,1,2,3]
pshuflw $0x72, %xmm2, %xmm2     # xmm2 = xmm2[2,0,3,1,4,5,6,7]
punpcklbw %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1],xmm0[2],xmm3[2],xmm0[3],xmm3[3],xmm0[4],xmm3[4],xmm0[5],xmm3[5],xmm0[6],xmm3[6],xmm0[7],xmm3[7]
pshufd $0xe7, %xmm0, %xmm3     # xmm3 = xmm0[3,1,2,3]
pshuflw $0x72, %xmm3, %xmm3     # xmm3 = xmm3[2,0,3,1,4,5,6,7]
punpckldq %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
pshufd $0xe8, %xmm1, %xmm1     # xmm1 = xmm1[0,2,2,3]
pshuflw $0xd8, %xmm1, %xmm1     # xmm1 = xmm1[0,2,1,3,4,5,6,7]
pshufd $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3]
pshuflw $0xd8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,1,3,4,5,6,7]
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
packuswb %xmm3, %xmm0
movq %rsp, %r15
movdqa %xmm0, (%r15)
movq %r15, %rdi
movq %rdx, %rsi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x3ba0(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x2d63
leaq 0x10(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x3b44(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x2d63
leaq 0x20(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x3ae8(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x2d63
leaq 0x30(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x3a8c(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x2d63
leaq 0x40(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x3a30(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x2d63
leaq 0x50(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x39d4(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x2d63
leaq 0x60(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x3978(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x2d63
leaq 0x70(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x391c(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x2d63
leaq 0x80(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x38bd(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x2d63
leaq 0x90(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x385e(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movl $0xa0, %eax
cmpl $0x80, %ebp
je 0x198d
movq %rsp, %r15
movq %r15, %rdi
callq 0x2d63
leaq 0xa0(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
pxor %xmm1, %xmm1
punpcklbw %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3],xmm0[4],xmm1[4],xmm0[5],xmm1[5],xmm0[6],xmm1[6],xmm0[7],xmm1[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x2d63
leaq 0xb0(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x378c(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movl $0xc0, %eax
cmpl $0xc0, %ebp
je 0x198d
movq %rsp, %r15
movq %r15, %rdi
callq 0x2d63
leaq 0xc0(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
pxor %xmm1, %xmm1
punpcklbw %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3],xmm0[4],xmm1[4],xmm0[5],xmm1[5],xmm0[6],xmm1[6],xmm0[7],xmm1[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movq %r15, %rdi
callq 0x2d63
leaq 0xd0(%r14), %rsi
movq %r15, %rdi
callq 0x29c6
movq %r15, %rdi
callq 0x2a3d
movq 0x4(%r15), %xmm0
punpcklbw 0x36ba(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3],xmm0[4],mem[4],xmm0[5],mem[5],xmm0[6],mem[6],xmm0[7],mem[7]
pshuflw $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0,4,5,6,7]
pshufd $0xb4, %xmm0, %xmm0     # xmm0 = xmm0[0,1,3,2]
packuswb %xmm0, %xmm0
movq %xmm0, 0x4(%r15)
movd 0xc(%r15), %xmm0
movdqa %xmm0, %xmm1
psrld $0x18, %xmm1
pslld $0x8, %xmm0
por %xmm1, %xmm0
movd %xmm0, 0xc(%r15)
movl $0xe0, %eax
addq %rax, %r14
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x29c6
movdqa (%r15), %xmm0
movdqa %xmm0, %xmm1
pxor %xmm3, %xmm3
punpckhbw %xmm3, %xmm1    # xmm1 = xmm1[8],xmm3[8],xmm1[9],xmm3[9],xmm1[10],xmm3[10],xmm1[11],xmm3[11],xmm1[12],xmm3[12],xmm1[13],xmm3[13],xmm1[14],xmm3[14],xmm1[15],xmm3[15]
pshufd $0xe7, %xmm1, %xmm2     # xmm2 = xmm1[3,1,2,3]
pshuflw $0x72, %xmm2, %xmm2     # xmm2 = xmm2[2,0,3,1,4,5,6,7]
punpcklbw %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1],xmm0[2],xmm3[2],xmm0[3],xmm3[3],xmm0[4],xmm3[4],xmm0[5],xmm3[5],xmm0[6],xmm3[6],xmm0[7],xmm3[7]
pshufd $0xe7, %xmm0, %xmm3     # xmm3 = xmm0[3,1,2,3]
pshuflw $0x72, %xmm3, %xmm3     # xmm3 = xmm3[2,0,3,1,4,5,6,7]
punpckldq %xmm2, %xmm3    # xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
pshufd $0xe8, %xmm1, %xmm1     # xmm1 = xmm1[0,2,2,3]
pshuflw $0xd8, %xmm1, %xmm1     # xmm1 = xmm1[0,2,1,3,4,5,6,7]
pshufd $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3]
pshuflw $0xd8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,1,3,4,5,6,7]
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
packuswb %xmm3, %xmm0
movdqu %xmm0, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq