// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/paeq128/aesni/encrypt.cpp
// Function: FPermAsm(long long vector[2] const*, long long vector[2]*)
void FPermAsm(const __m128i* input, __m128i* output)//AESQ permutation
{

	//Round Key initialization
	//Round Key initialization
	__m128i roundkey0 = _mm_set_epi64x(0x0000000100000001, 0x0000000100000001);
	__m128i roundkey1 = _mm_set_epi64x(0x0000000200000002, 0x0000000200000002);
	__m128i roundkey2 = _mm_set_epi64x(0x0000000300000003, 0x0000000300000003);
	__m128i roundkey3 = _mm_set_epi64x(0x0000000400000004, 0x0000000400000004);
	__m128i roundkeyUpdateConstant = roundkey3;

	__m128i acc0 = input[0];
	__m128i acc1 = input[1];
	__m128i acc2 = input[2];
	__m128i acc3 = input[3];
	__m128i mixTmp;


	for (unsigned i = 0; i<AES_GROUPS; ++i)
	{
		for (unsigned j = 0; j<AES_GROUP_ROUNDS; ++j)
		{
			//SubRounds
			acc0 = _mm_aesenc_si128(acc0, roundkey0);
			acc1 = _mm_aesenc_si128(acc1, roundkey1);
			acc2 = _mm_aesenc_si128(acc2, roundkey2);
			acc3 = _mm_aesenc_si128(acc3, roundkey3);

			//Update Constant
			roundkey0 = _mm_add_epi64(roundkeyUpdateConstant, roundkey0);
			roundkey1 = _mm_add_epi64(roundkeyUpdateConstant, roundkey1);
			roundkey2 = _mm_add_epi64(roundkeyUpdateConstant, roundkey2);
			roundkey3 = _mm_add_epi64(roundkeyUpdateConstant, roundkey3);


		}
		//Mixing
		mixTmp = _mm_unpackhi_epi32(acc1, acc0);//INV
		acc0 = _mm_unpacklo_epi32(acc1, acc0);//INV
		acc1 = _mm_unpackhi_epi32(acc3, acc2);//INV
		acc2 = _mm_unpacklo_epi32(acc3, acc2);//INV
		acc3 = _mm_unpackhi_epi32(acc2, acc0);//INV
		acc0 = _mm_unpacklo_epi32(acc2, acc0);//INV
		acc2 = _mm_unpacklo_epi32(mixTmp, acc1);//INV
		acc1 = _mm_unpackhi_epi32(mixTmp, acc1);//INV
	}
	output[0] = acc0;
	output[1] = acc1;
	output[2] = acc2;
	output[3] = acc3;
}

// Assembly:
subq $0x2c8, %rsp            # imm = 0x2C8
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0xb8(%rsp)
movq %rax, 0xb0(%rsp)
vmovq 0xb8(%rsp), %xmm1
vmovq 0xb0(%rsp), %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
vmovdqa %xmm0, 0xa0(%rsp)
vmovdqa 0xa0(%rsp), %xmm0
vmovdqa %xmm0, 0x20(%rsp)
movabsq $0x200000002, %rax      # imm = 0x200000002
movq %rax, 0x98(%rsp)
movq %rax, 0x90(%rsp)
vmovq 0x98(%rsp), %xmm1
vmovq 0x90(%rsp), %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
vmovdqa %xmm0, 0x80(%rsp)
vmovdqa 0x80(%rsp), %xmm0
vmovdqa %xmm0, 0x10(%rsp)
movabsq $0x300000003, %rax      # imm = 0x300000003
movq %rax, 0x78(%rsp)
movq %rax, 0x70(%rsp)
vmovq 0x78(%rsp), %xmm1
vmovq 0x70(%rsp), %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
vmovdqa %xmm0, 0x60(%rsp)
vmovdqa 0x60(%rsp), %xmm0
vmovdqa %xmm0, (%rsp)
movabsq $0x400000004, %rax      # imm = 0x400000004
movq %rax, 0x58(%rsp)
movq %rax, 0x50(%rsp)
vmovq 0x58(%rsp), %xmm1
vmovq 0x50(%rsp), %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
vmovdqa %xmm0, 0x40(%rsp)
vmovdqa 0x40(%rsp), %xmm0
vmovdqa %xmm0, -0x10(%rsp)
vmovdqa -0x10(%rsp), %xmm0
vmovdqa %xmm0, -0x20(%rsp)
movq 0x38(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, -0x30(%rsp)
movq 0x38(%rsp), %rax
vmovdqa 0x10(%rax), %xmm0
vmovdqa %xmm0, -0x40(%rsp)
movq 0x38(%rsp), %rax
vmovdqa 0x20(%rax), %xmm0
vmovdqa %xmm0, -0x50(%rsp)
movq 0x38(%rsp), %rax
vmovdqa 0x30(%rax), %xmm0
vmovdqa %xmm0, -0x60(%rsp)
movl $0x0, -0x74(%rsp)
cmpl $0xa, -0x74(%rsp)
jae 0x275e
movl $0x0, -0x78(%rsp)
cmpl $0x2, -0x78(%rsp)
jae 0x257e
vmovdqa -0x30(%rsp), %xmm1
vmovdqa 0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x130(%rsp)
vmovdqa %xmm0, 0x120(%rsp)
vmovdqa 0x130(%rsp), %xmm0
vmovdqa 0x120(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x30(%rsp)
vmovdqa -0x40(%rsp), %xmm1
vmovdqa 0x10(%rsp), %xmm0
vmovdqa %xmm1, 0x110(%rsp)
vmovdqa %xmm0, 0x100(%rsp)
vmovdqa 0x110(%rsp), %xmm0
vmovdqa 0x100(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x40(%rsp)
vmovdqa -0x50(%rsp), %xmm1
vmovdqa (%rsp), %xmm0
vmovdqa %xmm1, 0xf0(%rsp)
vmovdqa %xmm0, 0xe0(%rsp)
vmovdqa 0xf0(%rsp), %xmm0
vmovdqa 0xe0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x50(%rsp)
vmovdqa -0x60(%rsp), %xmm1
vmovdqa -0x10(%rsp), %xmm0
vmovdqa %xmm1, 0xd0(%rsp)
vmovdqa %xmm0, 0xc0(%rsp)
vmovdqa 0xd0(%rsp), %xmm0
vmovdqa 0xc0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x60(%rsp)
vmovdqa -0x20(%rsp), %xmm1
vmovdqa 0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x1b0(%rsp)
vmovdqa %xmm0, 0x1a0(%rsp)
vmovdqa 0x1b0(%rsp), %xmm0
vpaddq 0x1a0(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x20(%rsp)
vmovdqa -0x20(%rsp), %xmm1
vmovdqa 0x10(%rsp), %xmm0
vmovdqa %xmm1, 0x190(%rsp)
vmovdqa %xmm0, 0x180(%rsp)
vmovdqa 0x190(%rsp), %xmm0
vpaddq 0x180(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x10(%rsp)
vmovdqa -0x20(%rsp), %xmm1
vmovdqa (%rsp), %xmm0
vmovdqa %xmm1, 0x170(%rsp)
vmovdqa %xmm0, 0x160(%rsp)
vmovdqa 0x170(%rsp), %xmm0
vpaddq 0x160(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, (%rsp)
vmovdqa -0x20(%rsp), %xmm1
vmovdqa -0x10(%rsp), %xmm0
vmovdqa %xmm1, 0x150(%rsp)
vmovdqa %xmm0, 0x140(%rsp)
vmovdqa 0x150(%rsp), %xmm0
vpaddq 0x140(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, -0x10(%rsp)
movl -0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rsp)
jmp 0x23a2
vmovdqa -0x40(%rsp), %xmm1
vmovdqa -0x30(%rsp), %xmm0
vmovdqa %xmm1, 0x230(%rsp)
vmovdqa %xmm0, 0x220(%rsp)
vmovdqa 0x230(%rsp), %xmm0
vmovdqa 0x220(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, -0x70(%rsp)
vmovdqa -0x40(%rsp), %xmm1
vmovdqa -0x30(%rsp), %xmm0
vmovdqa %xmm1, 0x2b0(%rsp)
vmovdqa %xmm0, 0x2a0(%rsp)
vmovdqa 0x2b0(%rsp), %xmm0
vmovdqa 0x2a0(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, -0x30(%rsp)
vmovdqa -0x60(%rsp), %xmm1
vmovdqa -0x50(%rsp), %xmm0
vmovdqa %xmm1, 0x210(%rsp)
vmovdqa %xmm0, 0x200(%rsp)
vmovdqa 0x210(%rsp), %xmm0
vmovdqa 0x200(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, -0x40(%rsp)
vmovdqa -0x60(%rsp), %xmm1
vmovdqa -0x50(%rsp), %xmm0
vmovdqa %xmm1, 0x290(%rsp)
vmovdqa %xmm0, 0x280(%rsp)
vmovdqa 0x290(%rsp), %xmm0
vmovdqa 0x280(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, -0x50(%rsp)
vmovdqa -0x50(%rsp), %xmm1
vmovdqa -0x30(%rsp), %xmm0
vmovdqa %xmm1, 0x1f0(%rsp)
vmovdqa %xmm0, 0x1e0(%rsp)
vmovdqa 0x1f0(%rsp), %xmm0
vmovdqa 0x1e0(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, -0x60(%rsp)
vmovdqa -0x50(%rsp), %xmm1
vmovdqa -0x30(%rsp), %xmm0
vmovdqa %xmm1, 0x270(%rsp)
vmovdqa %xmm0, 0x260(%rsp)
vmovdqa 0x270(%rsp), %xmm0
vmovdqa 0x260(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, -0x30(%rsp)
vmovdqa -0x70(%rsp), %xmm1
vmovdqa -0x40(%rsp), %xmm0
vmovdqa %xmm1, 0x250(%rsp)
vmovdqa %xmm0, 0x240(%rsp)
vmovdqa 0x250(%rsp), %xmm0
vmovdqa 0x240(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, -0x50(%rsp)
vmovdqa -0x70(%rsp), %xmm1
vmovdqa -0x40(%rsp), %xmm0
vmovdqa %xmm1, 0x1d0(%rsp)
vmovdqa %xmm0, 0x1c0(%rsp)
vmovdqa 0x1d0(%rsp), %xmm0
vmovdqa 0x1c0(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, -0x40(%rsp)
movl -0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rsp)
jmp 0x238f
vmovdqa -0x30(%rsp), %xmm0
movq 0x30(%rsp), %rax
vmovdqa %xmm0, (%rax)
vmovdqa -0x40(%rsp), %xmm0
movq 0x30(%rsp), %rax
vmovdqa %xmm0, 0x10(%rax)
vmovdqa -0x50(%rsp), %xmm0
movq 0x30(%rsp), %rax
vmovdqa %xmm0, 0x20(%rax)
vmovdqa -0x60(%rsp), %xmm0
movq 0x30(%rsp), %rax
vmovdqa %xmm0, 0x30(%rax)
addq $0x2c8, %rsp            # imm = 0x2C8
retq
nopw %cs:(%rax,%rax)