// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/paeq128/aesni/encrypt.cpp
// Function: DoubleFPermAsm(long long vector[2] const*, long long vector[2] const*, long long vector[2]*, long long vector[2]*)
void DoubleFPermAsm(const __m128i* input1, const __m128i* input2, __m128i* output1, __m128i* output2)//AESQ permutation
{
	//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 = input1[0];
	__m128i acc1 = input1[1];
	__m128i acc2 = input1[2];
	__m128i acc3 = input1[3];

	__m128i acc4 = input2[0];
	__m128i acc5 = input2[1];
	__m128i acc6 = input2[2];
	__m128i acc7 = input2[3];
	__m128i mixTmp1, mixTmp2;


	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);

			acc4 = _mm_aesenc_si128(acc4, roundkey0);
			acc5 = _mm_aesenc_si128(acc5, roundkey1);
			acc6 = _mm_aesenc_si128(acc6, roundkey2);
			acc7 = _mm_aesenc_si128(acc7, 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
		mixTmp1 = _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(mixTmp1, acc1);//INV
		acc1 = _mm_unpackhi_epi32(mixTmp1, acc1);//INV

		mixTmp2 = _mm_unpackhi_epi32(acc5, acc4);//INV
		acc4 = _mm_unpacklo_epi32(acc5, acc4);//INV
		acc5 = _mm_unpackhi_epi32(acc7, acc6);//INV
		acc6 = _mm_unpacklo_epi32(acc7, acc6);//INV
		acc7 = _mm_unpackhi_epi32(acc6, acc4);//INV
		acc4 = _mm_unpacklo_epi32(acc6, acc4);//INV
		acc6 = _mm_unpacklo_epi32(mixTmp2, acc5);//INV
		acc5 = _mm_unpackhi_epi32(mixTmp2, acc5);//INV


	}
	output1[0] = acc0;
	output1[1] = acc1;
	output1[2] = acc2;
	output1[3] = acc3;

	output2[0] = acc4;
	output2[1] = acc5;
	output2[2] = acc6;
	output2[3] = acc7;
}

// Assembly:
subq $0x4a8, %rsp            # imm = 0x4A8
movq %rdi, 0x98(%rsp)
movq %rsi, 0x90(%rsp)
movq %rdx, 0x88(%rsp)
movq %rcx, 0x80(%rsp)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x118(%rsp)
movq %rax, 0x110(%rsp)
vmovq 0x118(%rsp), %xmm1
vmovq 0x110(%rsp), %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
vmovdqa %xmm0, 0x100(%rsp)
vmovdqa 0x100(%rsp), %xmm0
vmovdqa %xmm0, 0x70(%rsp)
movabsq $0x200000002, %rax      # imm = 0x200000002
movq %rax, 0xf8(%rsp)
movq %rax, 0xf0(%rsp)
vmovq 0xf8(%rsp), %xmm1
vmovq 0xf0(%rsp), %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
vmovdqa %xmm0, 0xe0(%rsp)
vmovdqa 0xe0(%rsp), %xmm0
vmovdqa %xmm0, 0x60(%rsp)
movabsq $0x300000003, %rax      # imm = 0x300000003
movq %rax, 0xd8(%rsp)
movq %rax, 0xd0(%rsp)
vmovq 0xd8(%rsp), %xmm1
vmovq 0xd0(%rsp), %xmm0
vpunpcklqdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
vmovdqa %xmm0, 0xc0(%rsp)
vmovdqa 0xc0(%rsp), %xmm0
vmovdqa %xmm0, 0x50(%rsp)
movabsq $0x400000004, %rax      # imm = 0x400000004
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, 0x40(%rsp)
vmovdqa 0x40(%rsp), %xmm0
vmovdqa %xmm0, 0x30(%rsp)
movq 0x98(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, 0x20(%rsp)
movq 0x98(%rsp), %rax
vmovdqa 0x10(%rax), %xmm0
vmovdqa %xmm0, 0x10(%rsp)
movq 0x98(%rsp), %rax
vmovdqa 0x20(%rax), %xmm0
vmovdqa %xmm0, (%rsp)
movq 0x98(%rsp), %rax
vmovdqa 0x30(%rax), %xmm0
vmovdqa %xmm0, -0x10(%rsp)
movq 0x90(%rsp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, -0x20(%rsp)
movq 0x90(%rsp), %rax
vmovdqa 0x10(%rax), %xmm0
vmovdqa %xmm0, -0x30(%rsp)
movq 0x90(%rsp), %rax
vmovdqa 0x20(%rax), %xmm0
vmovdqa %xmm0, -0x40(%rsp)
movq 0x90(%rsp), %rax
vmovdqa 0x30(%rax), %xmm0
vmovdqa %xmm0, -0x50(%rsp)
movl $0x0, -0x74(%rsp)
cmpl $0xa, -0x74(%rsp)
jae 0x2186
movl $0x0, -0x78(%rsp)
cmpl $0x2, -0x78(%rsp)
jae 0x1ddc
vmovdqa 0x20(%rsp), %xmm1
vmovdqa 0x70(%rsp), %xmm0
vmovdqa %xmm1, 0x210(%rsp)
vmovdqa %xmm0, 0x200(%rsp)
vmovdqa 0x210(%rsp), %xmm0
vmovdqa 0x200(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x20(%rsp)
vmovdqa 0x10(%rsp), %xmm1
vmovdqa 0x60(%rsp), %xmm0
vmovdqa %xmm1, 0x1f0(%rsp)
vmovdqa %xmm0, 0x1e0(%rsp)
vmovdqa 0x1f0(%rsp), %xmm0
vmovdqa 0x1e0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, 0x10(%rsp)
vmovdqa (%rsp), %xmm1
vmovdqa 0x50(%rsp), %xmm0
vmovdqa %xmm1, 0x1d0(%rsp)
vmovdqa %xmm0, 0x1c0(%rsp)
vmovdqa 0x1d0(%rsp), %xmm0
vmovdqa 0x1c0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, (%rsp)
vmovdqa -0x10(%rsp), %xmm1
vmovdqa 0x40(%rsp), %xmm0
vmovdqa %xmm1, 0x1b0(%rsp)
vmovdqa %xmm0, 0x1a0(%rsp)
vmovdqa 0x1b0(%rsp), %xmm0
vmovdqa 0x1a0(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x10(%rsp)
vmovdqa -0x20(%rsp), %xmm1
vmovdqa 0x70(%rsp), %xmm0
vmovdqa %xmm1, 0x190(%rsp)
vmovdqa %xmm0, 0x180(%rsp)
vmovdqa 0x190(%rsp), %xmm0
vmovdqa 0x180(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x20(%rsp)
vmovdqa -0x30(%rsp), %xmm1
vmovdqa 0x60(%rsp), %xmm0
vmovdqa %xmm1, 0x170(%rsp)
vmovdqa %xmm0, 0x160(%rsp)
vmovdqa 0x170(%rsp), %xmm0
vmovdqa 0x160(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x30(%rsp)
vmovdqa -0x40(%rsp), %xmm1
vmovdqa 0x50(%rsp), %xmm0
vmovdqa %xmm1, 0x150(%rsp)
vmovdqa %xmm0, 0x140(%rsp)
vmovdqa 0x150(%rsp), %xmm0
vmovdqa 0x140(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x40(%rsp)
vmovdqa -0x50(%rsp), %xmm1
vmovdqa 0x40(%rsp), %xmm0
vmovdqa %xmm1, 0x130(%rsp)
vmovdqa %xmm0, 0x120(%rsp)
vmovdqa 0x130(%rsp), %xmm0
vmovdqa 0x120(%rsp), %xmm1
vaesenc %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x50(%rsp)
vmovdqa 0x30(%rsp), %xmm1
vmovdqa 0x70(%rsp), %xmm0
vmovdqa %xmm1, 0x290(%rsp)
vmovdqa %xmm0, 0x280(%rsp)
vmovdqa 0x290(%rsp), %xmm0
vpaddq 0x280(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x70(%rsp)
vmovdqa 0x30(%rsp), %xmm1
vmovdqa 0x60(%rsp), %xmm0
vmovdqa %xmm1, 0x270(%rsp)
vmovdqa %xmm0, 0x260(%rsp)
vmovdqa 0x270(%rsp), %xmm0
vpaddq 0x260(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x60(%rsp)
vmovdqa 0x30(%rsp), %xmm1
vmovdqa 0x50(%rsp), %xmm0
vmovdqa %xmm1, 0x250(%rsp)
vmovdqa %xmm0, 0x240(%rsp)
vmovdqa 0x250(%rsp), %xmm0
vpaddq 0x240(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x50(%rsp)
vmovdqa 0x30(%rsp), %xmm1
vmovdqa 0x40(%rsp), %xmm0
vmovdqa %xmm1, 0x230(%rsp)
vmovdqa %xmm0, 0x220(%rsp)
vmovdqa 0x230(%rsp), %xmm0
vpaddq 0x220(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x40(%rsp)
movl -0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rsp)
jmp 0x1b13
vmovdqa 0x10(%rsp), %xmm1
vmovdqa 0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x390(%rsp)
vmovdqa %xmm0, 0x380(%rsp)
vmovdqa 0x390(%rsp), %xmm0
vmovdqa 0x380(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, -0x60(%rsp)
vmovdqa 0x10(%rsp), %xmm1
vmovdqa 0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x490(%rsp)
vmovdqa %xmm0, 0x480(%rsp)
vmovdqa 0x490(%rsp), %xmm0
vmovdqa 0x480(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, 0x20(%rsp)
vmovdqa -0x10(%rsp), %xmm1
vmovdqa (%rsp), %xmm0
vmovdqa %xmm1, 0x370(%rsp)
vmovdqa %xmm0, 0x360(%rsp)
vmovdqa 0x370(%rsp), %xmm0
vmovdqa 0x360(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, 0x10(%rsp)
vmovdqa -0x10(%rsp), %xmm1
vmovdqa (%rsp), %xmm0
vmovdqa %xmm1, 0x470(%rsp)
vmovdqa %xmm0, 0x460(%rsp)
vmovdqa 0x470(%rsp), %xmm0
vmovdqa 0x460(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, (%rsp)
vmovdqa (%rsp), %xmm1
vmovdqa 0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x350(%rsp)
vmovdqa %xmm0, 0x340(%rsp)
vmovdqa 0x350(%rsp), %xmm0
vmovdqa 0x340(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, -0x10(%rsp)
vmovdqa (%rsp), %xmm1
vmovdqa 0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x450(%rsp)
vmovdqa %xmm0, 0x440(%rsp)
vmovdqa 0x450(%rsp), %xmm0
vmovdqa 0x440(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, 0x20(%rsp)
vmovdqa -0x60(%rsp), %xmm1
vmovdqa 0x10(%rsp), %xmm0
vmovdqa %xmm1, 0x430(%rsp)
vmovdqa %xmm0, 0x420(%rsp)
vmovdqa 0x430(%rsp), %xmm0
vmovdqa 0x420(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, (%rsp)
vmovdqa -0x60(%rsp), %xmm1
vmovdqa 0x10(%rsp), %xmm0
vmovdqa %xmm1, 0x330(%rsp)
vmovdqa %xmm0, 0x320(%rsp)
vmovdqa 0x330(%rsp), %xmm0
vmovdqa 0x320(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, 0x10(%rsp)
vmovdqa -0x30(%rsp), %xmm1
vmovdqa -0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x310(%rsp)
vmovdqa %xmm0, 0x300(%rsp)
vmovdqa 0x310(%rsp), %xmm0
vmovdqa 0x300(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, -0x70(%rsp)
vmovdqa -0x30(%rsp), %xmm1
vmovdqa -0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x410(%rsp)
vmovdqa %xmm0, 0x400(%rsp)
vmovdqa 0x410(%rsp), %xmm0
vmovdqa 0x400(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, -0x20(%rsp)
vmovdqa -0x50(%rsp), %xmm1
vmovdqa -0x40(%rsp), %xmm0
vmovdqa %xmm1, 0x2f0(%rsp)
vmovdqa %xmm0, 0x2e0(%rsp)
vmovdqa 0x2f0(%rsp), %xmm0
vmovdqa 0x2e0(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, -0x30(%rsp)
vmovdqa -0x50(%rsp), %xmm1
vmovdqa -0x40(%rsp), %xmm0
vmovdqa %xmm1, 0x3f0(%rsp)
vmovdqa %xmm0, 0x3e0(%rsp)
vmovdqa 0x3f0(%rsp), %xmm0
vmovdqa 0x3e0(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, -0x40(%rsp)
vmovdqa -0x40(%rsp), %xmm1
vmovdqa -0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x2d0(%rsp)
vmovdqa %xmm0, 0x2c0(%rsp)
vmovdqa 0x2d0(%rsp), %xmm0
vmovdqa 0x2c0(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, -0x50(%rsp)
vmovdqa -0x40(%rsp), %xmm1
vmovdqa -0x20(%rsp), %xmm0
vmovdqa %xmm1, 0x3d0(%rsp)
vmovdqa %xmm0, 0x3c0(%rsp)
vmovdqa 0x3d0(%rsp), %xmm0
vmovdqa 0x3c0(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, -0x20(%rsp)
vmovdqa -0x70(%rsp), %xmm1
vmovdqa -0x30(%rsp), %xmm0
vmovdqa %xmm1, 0x3b0(%rsp)
vmovdqa %xmm0, 0x3a0(%rsp)
vmovdqa 0x3b0(%rsp), %xmm0
vmovdqa 0x3a0(%rsp), %xmm1
vpunpckldq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
vmovdqa %xmm0, -0x40(%rsp)
vmovdqa -0x70(%rsp), %xmm1
vmovdqa -0x30(%rsp), %xmm0
vmovdqa %xmm1, 0x2b0(%rsp)
vmovdqa %xmm0, 0x2a0(%rsp)
vmovdqa 0x2b0(%rsp), %xmm0
vmovdqa 0x2a0(%rsp), %xmm1
vpunpckhdq %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[2],xmm1[2],xmm0[3],xmm1[3]
vmovdqa %xmm0, -0x30(%rsp)
movl -0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rsp)
jmp 0x1b00
vmovdqa 0x20(%rsp), %xmm0
movq 0x88(%rsp), %rax
vmovdqa %xmm0, (%rax)
vmovdqa 0x10(%rsp), %xmm0
movq 0x88(%rsp), %rax
vmovdqa %xmm0, 0x10(%rax)
vmovdqa (%rsp), %xmm0
movq 0x88(%rsp), %rax
vmovdqa %xmm0, 0x20(%rax)
vmovdqa -0x10(%rsp), %xmm0
movq 0x88(%rsp), %rax
vmovdqa %xmm0, 0x30(%rax)
vmovdqa -0x20(%rsp), %xmm0
movq 0x80(%rsp), %rax
vmovdqa %xmm0, (%rax)
vmovdqa -0x30(%rsp), %xmm0
movq 0x80(%rsp), %rax
vmovdqa %xmm0, 0x10(%rax)
vmovdqa -0x40(%rsp), %xmm0
movq 0x80(%rsp), %rax
vmovdqa %xmm0, 0x20(%rax)
vmovdqa -0x50(%rsp), %xmm0
movq 0x80(%rsp), %rax
vmovdqa %xmm0, 0x30(%rax)
addq $0x4a8, %rsp            # imm = 0x4A8
retq
nopw %cs:(%rax,%rax)