// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/paeq128/aesni/encrypt.cpp
// Function: PAEQ128_opt_AESNI_decrypt(unsigned char*, unsigned long long*, unsigned char const*, unsigned long long, unsigned char const*, unsigned long long, unsigned char const*, unsigned char const*)
int PAEQ128_opt_AESNI_decrypt(unsigned char *m, unsigned long long *mlen,
	const unsigned char *c, unsigned long long clen,
	const unsigned char *ad, unsigned long long adlen,
	const unsigned char *npub,
	const unsigned char *k)
{

	if (mlen == NULL)
		return -1;
	if ((clen == 0) && (adlen == 0))
	{
		*mlen = 0;
		return 0;
	}

	(*mlen) = 0;
	//Minimum tag length verification
	if (clen < CRYPTO_ABYTES)
		return -1;

	//Here we do decryption and/or authentication so we need a key and a ciphertext pointer valid
	if ((k == NULL) || (c == NULL))
		return -2;

	//1.1 Initializing constants
	uint64_t D_left = ((uint64_t)CRYPTO_NPUBBYTES * 8) + (((uint64_t)CRYPTO_KEYBYTES * 8) << 8);
	__m128i D0 = _mm_set_epi64x(0, D_left);
	__m128i D2 = _mm_set_epi64x(0, D_left + 2);
	__m128i D3 = _mm_set_epi64x(0, D_left + 3);
	__m128i one128 = _mm_set_epi64x(0, 1);
	__m128i four128 = _mm_set_epi64x(0, 4);
	__m128i six128 = _mm_set_epi64x(0, 6);
	__m128i counter_one128 = _mm_set_epi64x(0, 1 << 16);  //value to increase the counter
	__m128i Dmask = _mm_set_epi32(0xffffffff, 0xffffffff, 0xffffffff, 0xffff0000);

	//Block variables
	__m128i BlockInput[4];  //V1 - input to the first layer call of F
	__m128i BlockMiddle[4];  //W1 - output of the first layer call of F
	__m128i BlockOutput[4];  //Y1 - output of the second layer call of F

	//Extra variables
	__m128i BlockExtraInput[4];
	__m128i BlockExtraMiddle[4];
	__m128i BlockExtraOutput[4];


	__m128i BlockLastInput[4];  //Z1 - input to the last call of F
	__m128i Tag[4]; //Tag output

	//1.2 Clearing variables
	memset(BlockLastInput, 0, 64);
	memset(BlockInput, 0, 64);
	memset(BlockOutput, 0, 64);
	memset(BlockMiddle, 0, 64);
	memset(BlockMiddle, 0, 64);

	//1.3 Setting first block
	BlockInput[0] = D0;  //Domain separation constant
	uint64_t nonce_low = (*((uint64_t*)npub)) << 32;
	uint64_t nonce_high = *((uint64_t*)(npub + 4));
	BlockInput[2] = _mm_set_epi64x(nonce_high, nonce_low);   //Nonce
	__m128i Key = _mm_set_epi64x(*((uint64_t*)(k + 8)), (*((uint64_t*)k)));
	BlockInput[3] = Key;


	unsigned long long decrypted_bytes = 0;//Encrypted bytes counter


	//Encryption part
	if (clen != 0)
	{
		if (c == NULL)
			return -3;

		while ((clen>CRYPTO_ABYTES))
		{
			/* I. First layer */

			if ((clen < (2 * CRYPTO_MBLOCK + CRYPTO_ABYTES)) || (decrypted_bytes == 0))
			{

				//1. Domain-separation constant
				if (clen < CRYPTO_MBLOCK + CRYPTO_ABYTES) //Last incomplete block
					BlockInput[0] = _mm_add_epi64(BlockInput[0], one128);

				//2. Counter incrementing
				BlockInput[0] = _mm_add_epi64(BlockInput[0], counter_one128);

				//3. Permutation call
				FPermAsm(BlockInput, BlockMiddle); //First layer call to F

				/* II. Encryption*/

				//1. Filling ciphertext buffers
				__m128i ciphertext128[3];
				__m128i plaintext_buffer[3];
				__m128i padding[3];
				__m128i boundary[3];
				memset(ciphertext128, 0, sizeof(__m128i) * 3);
				if (clen >= CRYPTO_MBLOCK + CRYPTO_ABYTES)//Full block encryption
				{
					ciphertext128[0] = D2;
					memcpy(((char*)ciphertext128) + 2, c + decrypted_bytes, CRYPTO_MBLOCK);
					memset(boundary, 0, sizeof(__m128i) * 3);
				}
				else
				{
					ciphertext128[0] = D3;
					memcpy(((char*)ciphertext128) + 2, c + decrypted_bytes, clen - CRYPTO_ABYTES);

					padding[0] = padding[1] = padding[2] = _mm_set1_epi8(clen - CRYPTO_ABYTES);
					boundary[0] = boundary[1] = boundary[2] = _mm_set1_epi8(0xff);
					memset(boundary, 0, clen - CRYPTO_ABYTES + 2);
				}


				//3. Getting plaintext
				plaintext_buffer[0] = _mm_xor_si128(BlockMiddle[0], ciphertext128[0]);
				plaintext_buffer[1] = _mm_xor_si128(BlockMiddle[1], ciphertext128[1]);
				plaintext_buffer[2] = _mm_xor_si128(BlockMiddle[2], ciphertext128[2]);

				if (clen >= CRYPTO_MBLOCK + CRYPTO_ABYTES)
					memcpy(m + decrypted_bytes, ((char*)plaintext_buffer) + 2, CRYPTO_MBLOCK);
				else //Last incomplete block
					memcpy(m + decrypted_bytes, ((char*)plaintext_buffer) + 2, (clen - CRYPTO_ABYTES));
				memset(plaintext_buffer, 0, 6 * sizeof(uint64_t));

				//4. Loading ciphertext
				BlockMiddle[0] = _mm_xor_si128(_mm_andnot_si128(boundary[0], ciphertext128[0]), _mm_and_si128(boundary[0], _mm_xor_si128(BlockMiddle[0], padding[0])));
				BlockMiddle[1] = _mm_xor_si128(_mm_andnot_si128(boundary[1], ciphertext128[1]), _mm_and_si128(boundary[1], _mm_xor_si128(BlockMiddle[1], padding[1])));
				BlockMiddle[2] = _mm_xor_si128(_mm_andnot_si128(boundary[2], ciphertext128[2]), _mm_and_si128(boundary[2], _mm_xor_si128(BlockMiddle[2], padding[2])));

				//III. Second permutation call
				//1. Call
				FPermAsm(BlockMiddle, BlockOutput); //Second layer call to F

				//2. Buffer update: Adding the output to tag preparation buffer
				BlockLastInput[0] = _mm_xor_si128(BlockOutput[0], BlockLastInput[0]);
				BlockLastInput[1] = _mm_xor_si128(BlockOutput[1], BlockLastInput[1]);
				BlockLastInput[2] = _mm_xor_si128(BlockOutput[2], BlockLastInput[2]);

				//Counters increment
				if (clen >= CRYPTO_MBLOCK + CRYPTO_ABYTES)
				{
					decrypted_bytes += CRYPTO_MBLOCK;
					clen -= CRYPTO_MBLOCK;
				}
				else
				{
					decrypted_bytes += (clen - CRYPTO_ABYTES);
					clen = CRYPTO_ABYTES;
				}
				(*mlen) = decrypted_bytes;
			}//end of <138 byte condition


			else //More than 137 bytes to encrypt
			{
				BlockExtraInput[0] = _mm_add_epi64(BlockInput[0], counter_one128);
				BlockInput[0] = _mm_add_epi64(BlockExtraInput[0], counter_one128);
				BlockExtraInput[1] = BlockInput[1];
				BlockExtraInput[2] = BlockInput[2];
				BlockExtraInput[3] = BlockInput[3];

				//2. Two-permutation call
				DoubleFPermAsm(BlockExtraInput, BlockInput, BlockExtraMiddle, BlockMiddle); //First layer call to F


				//3. Preparing plaintext buffer
				__m128i plaintext_buffer[6];  //96-byte storage
				plaintext_buffer[0] = BlockExtraMiddle[0];
				plaintext_buffer[1] = BlockExtraMiddle[1];
				plaintext_buffer[2] = BlockExtraMiddle[2];
				plaintext_buffer[3] = BlockMiddle[0];
				plaintext_buffer[4] = BlockMiddle[1];
				plaintext_buffer[5] = BlockMiddle[2];

				//4.Loading ciphertext
				BlockExtraMiddle[0] = _mm_loadu_si128((__m128i*)(c + decrypted_bytes - 2));   //Bytes [0:13]
				BlockExtraMiddle[1] = _mm_loadu_si128((__m128i*)(c + decrypted_bytes + 14));  //Bytes [14:29]
				BlockExtraMiddle[2] = _mm_loadu_si128((__m128i*)(c + decrypted_bytes + 30));  //Bytes [30:45]
				BlockMiddle[0] = _mm_loadu_si128((__m128i*)(c + decrypted_bytes + 44));  //Bytes [0:13]
				BlockMiddle[1] = _mm_loadu_si128((__m128i*)(c + decrypted_bytes + 60));   //Bytes [14:29]
				BlockMiddle[2] = _mm_loadu_si128((__m128i*)(c + decrypted_bytes + 76));  //Bytes [30:45]

				//5. Preparing the middle layer
				BlockMiddle[0] = _mm_and_si128(BlockMiddle[0], Dmask); //Clearing first two bytes
				BlockExtraMiddle[0] = _mm_and_si128(BlockExtraMiddle[0], Dmask);
				BlockMiddle[0] = _mm_xor_si128(BlockMiddle[0], D2);    //Loading D2
				BlockExtraMiddle[0] = _mm_xor_si128(BlockExtraMiddle[0], D2);

				//6. Getting plaintext
				plaintext_buffer[0] = _mm_xor_si128(plaintext_buffer[0], BlockExtraMiddle[0]);
				plaintext_buffer[1] = _mm_xor_si128(plaintext_buffer[1], BlockExtraMiddle[1]);
				plaintext_buffer[2] = _mm_xor_si128(plaintext_buffer[2], BlockExtraMiddle[2]);
				plaintext_buffer[3] = _mm_xor_si128(plaintext_buffer[3], BlockMiddle[0]);
				plaintext_buffer[4] = _mm_xor_si128(plaintext_buffer[4], BlockMiddle[1]);
				plaintext_buffer[5] = _mm_xor_si128(plaintext_buffer[5], BlockMiddle[2]);
				memcpy(m + decrypted_bytes, ((char*)plaintext_buffer) + 2, CRYPTO_MBLOCK);
				memcpy(m + decrypted_bytes + 46, ((char*)plaintext_buffer) + 50, CRYPTO_MBLOCK);

				//7. Second layer permutation
				DoubleFPermAsm(BlockExtraMiddle, BlockMiddle, BlockExtraOutput, BlockOutput); //Second layer call to F

				//8. Buffer update: Adding the output to tag preparation buffer
				BlockLastInput[0] = _mm_xor_si128(BlockOutput[0], BlockLastInput[0]);
				BlockLastInput[1] = _mm_xor_si128(BlockOutput[1], BlockLastInput[1]);
				BlockLastInput[2] = _mm_xor_si128(BlockOutput[2], BlockLastInput[2]);
				BlockLastInput[0] = _mm_xor_si128(BlockExtraOutput[0], BlockLastInput[0]);
				BlockLastInput[1] = _mm_xor_si128(BlockExtraOutput[1], BlockLastInput[1]);
				BlockLastInput[2] = _mm_xor_si128(BlockExtraOutput[2], BlockLastInput[2]);


				//9.Counter update
				decrypted_bytes += 2 * CRYPTO_MBLOCK;
				clen -= 2 * CRYPTO_MBLOCK;
				(*mlen) = decrypted_bytes;
			}


		}//end of encryption loop
	}//end of encryption part

	//Clearing variables
	for (unsigned i = 0; i < 4; ++i)
	{
		BlockInput[i] = _mm_xor_si128(BlockInput[i], BlockInput[i]);
		BlockMiddle[i] = _mm_xor_si128(BlockMiddle[i], BlockMiddle[i]);
		BlockOutput[i] = _mm_xor_si128(BlockOutput[i], BlockOutput[i]);

		BlockExtraInput[i] = _mm_xor_si128(BlockExtraInput[i], BlockExtraInput[i]);
		BlockExtraMiddle[i] = _mm_xor_si128(BlockExtraMiddle[i], BlockExtraMiddle[i]);
		BlockExtraOutput[i] = _mm_xor_si128(BlockExtraOutput[i], BlockExtraOutput[i]);
	}



	//Associated data part	  
	if (adlen != 0)
	{
		if (ad == NULL)
		{
			for (unsigned i = 0; i < 4; ++i)
				BlockLastInput[i] = _mm_xor_si128(BlockLastInput[i], BlockLastInput[i]);
			Key = _mm_xor_si128(Key, Key);
			return -4;
		}

		unsigned long long adblock_counter = 1;   //AD block counter
		unsigned long long auth_bytes = 0;

		//Preparing the block
		BlockInput[0] = _mm_add_epi64(D0, four128);
		BlockInput[3] = Key;
		while (adlen>0)
		{
			if ((adlen <= (2 * CRYPTO_ADBLOCK)) || (auth_bytes == 0))
			{

				//1. Constant
				if (adlen < CRYPTO_ADBLOCK)
					BlockInput[0] = _mm_add_epi64(BlockInput[0], one128);


				//2. Counter
				BlockInput[0] = _mm_add_epi64(BlockInput[0], counter_one128);

				//3. AD block

				//3.1 Filling AD buffers
				uint64_t ad_buffer[4];
				ad_buffer[0] = 0;
				if (adlen >= CRYPTO_ADBLOCK)//Full block encryption
					memcpy(((char*)ad_buffer) + 2, ad + auth_bytes, CRYPTO_ADBLOCK);
				else
				{
					//Filling buffers with adlen
					ad_buffer[0] = ((uint64_t)adlen * 0x01010000) ^ (((uint64_t)adlen * 0x01010101) << 32);
					for (unsigned i = 1; i < 4; ++i)
						ad_buffer[i] = (((uint64_t)adlen * 0x01010101) << 32) ^ ((uint64_t)adlen * 0x01010101);
					memcpy(((char*)ad_buffer) + 2, ad + auth_bytes, adlen);
				}

				//3.2 Working with BlockInput
				BlockInput[1] = _mm_set_epi64x(ad_buffer[1], ad_buffer[0]);
				BlockInput[2] = _mm_set_epi64x(ad_buffer[3], ad_buffer[2]);


				//4.Call to the F permutation
				FPermAsm(BlockInput, BlockOutput);//Call to the F permutation

				//Adding the output to tag preparation buffer
				BlockLastInput[0] = _mm_xor_si128(BlockOutput[0], BlockLastInput[0]);
				BlockLastInput[1] = _mm_xor_si128(BlockOutput[1], BlockLastInput[1]);
				BlockLastInput[2] = _mm_xor_si128(BlockOutput[2], BlockLastInput[2]);


				//Counters increment
				adblock_counter++;
				if (adlen >= CRYPTO_ADBLOCK)
				{
					auth_bytes += CRYPTO_ADBLOCK;
					adlen -= CRYPTO_ADBLOCK;
				}
				else
				{
					auth_bytes += adlen;
					adlen = 0;
				}
			}//end of 60-byte condition
			else //We authenticate 60-byte chunks
			{

				//1.Preparing input
				BlockExtraInput[0] = _mm_add_epi64(BlockInput[0], counter_one128);
				BlockInput[0] = _mm_add_epi64(BlockExtraInput[0], counter_one128);
				BlockExtraInput[3] = BlockInput[3]; //Key is constant

				//2. Loading AD
				BlockExtraInput[1] = _mm_loadu_si128((__m128i*)(ad + auth_bytes - 2));   //Bytes [0:13]
				BlockExtraInput[1] = _mm_and_si128(BlockExtraInput[1], Dmask); //Clearing first two bytes
				BlockExtraInput[2] = _mm_loadu_si128((__m128i*)(ad + auth_bytes + 14));  //Bytes [14:29]
				BlockInput[1] = _mm_loadu_si128((__m128i*)(ad + auth_bytes + 28));  //Bytes [0:13]
				BlockInput[1] = _mm_and_si128(BlockInput[1], Dmask); //Clearing first two bytes
				BlockInput[2] = _mm_loadu_si128((__m128i*)(ad + auth_bytes + 44));  //Bytes [14:29]

				//3. Call to the permutation
				DoubleFPermAsm(BlockExtraInput, BlockInput, BlockExtraOutput, BlockOutput);

				//4. Buffer update: Adding the output to tag preparation buffer
				BlockLastInput[0] = _mm_xor_si128(BlockOutput[0], BlockLastInput[0]);
				BlockLastInput[1] = _mm_xor_si128(BlockOutput[1], BlockLastInput[1]);
				BlockLastInput[2] = _mm_xor_si128(BlockOutput[2], BlockLastInput[2]);
				BlockLastInput[0] = _mm_xor_si128(BlockExtraOutput[0], BlockLastInput[0]);
				BlockLastInput[1] = _mm_xor_si128(BlockExtraOutput[1], BlockLastInput[1]);
				BlockLastInput[2] = _mm_xor_si128(BlockExtraOutput[2], BlockLastInput[2]);

				//5. Counter update
				auth_bytes += 2 * CRYPTO_ADBLOCK;
				adlen -= 2 * CRYPTO_ADBLOCK;
			}
		}//end of AD loop
	}//end of AD part

	// Tag production 
	BlockLastInput[3] = Key;
	BlockLastInput[0] = _mm_and_si128(BlockLastInput[0], Dmask); //Clearing first two bytes
	BlockLastInput[0] = _mm_add_epi64(BlockLastInput[0], six128);
	BlockLastInput[0] = _mm_add_epi64(BlockLastInput[0], D0);

	//1. Permutation call
	FPermAsm(BlockLastInput, Tag);
	//2. Key injection
	Tag[3] = _mm_xor_si128(Tag[3], Key);

	//3. Clearing variables
	for (unsigned i = 0; i < 4; ++i)
	{
		BlockInput[i] = _mm_xor_si128(BlockInput[i], BlockInput[i]);
		BlockMiddle[i] = _mm_xor_si128(BlockMiddle[i], BlockMiddle[i]);
		BlockOutput[i] = _mm_xor_si128(BlockOutput[i], BlockOutput[i]);

		BlockExtraInput[i] = _mm_xor_si128(BlockExtraInput[i], BlockExtraInput[i]);
		BlockExtraMiddle[i] = _mm_xor_si128(BlockExtraMiddle[i], BlockExtraMiddle[i]);
		BlockExtraOutput[i] = _mm_xor_si128(BlockExtraOutput[i], BlockExtraOutput[i]);
		BlockLastInput[i] = _mm_xor_si128(BlockLastInput[i], BlockLastInput[i]);
	}
	Key = _mm_xor_si128(Key, Key);

	//4. Checking tag
	__m128i ciphertext_tag = _mm_loadu_si128((__m128i*)(c + (*mlen)));
	ciphertext_tag = _mm_xor_si128(ciphertext_tag, Tag[0]);
	uint32_t* test = (uint32_t*)(&ciphertext_tag);
	
	if ((test[0] == 0) && (test[1] == 0) && (test[2] == 0) && (test[3] == 0))
		return 0;
	else return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x368, %rsp            # imm = 0x368
movq %r8, 0x8(%rsp)
pushq $-0x1
popq %rax
testq %rsi, %rsi
je 0x20e1
movq %rcx, %r8
movq %rsi, %r10
andq $0x0, (%rsi)
movq %r9, %rcx
orq %r8, %rcx
je 0x1700
cmpq $0x10, %r8
jb 0x20e1
movq 0x3a8(%rsp), %rax
testq %rax, %rax
sete %cl
testq %rdx, %rdx
sete %sil
orb %cl, %sil
je 0x1707
pushq $-0x2
popq %rax
jmp 0x20e1
xorl %eax, %eax
jmp 0x20e1
movq %r9, 0x158(%rsp)
vxorps %xmm0, %xmm0, %xmm0
vmovups %ymm0, 0x2d0(%rsp)
movq 0x3a0(%rsp), %rcx
vmovups %ymm0, 0x2f0(%rsp)
leaq 0x160(%rsp), %r9
vmovups %ymm0, (%r9)
leaq 0xb0(%rsp), %rsi
vmovups %ymm0, (%rsi)
vmovups %ymm0, 0x20(%rsi)
leaq 0xf0(%rsp), %rsi
vmovups %ymm0, (%rsi)
vmovups %ymm0, 0x20(%rsi)
movq (%rcx), %rsi
shlq $0x20, %rsi
vmovq 0x4(%rcx), %xmm0
vmovq %rsi, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
vmovdqa %xmm0, 0x130(%rsp)
vmovdqa %xmm0, 0x20(%r9)
vmovups (%rax), %xmm0
vmovaps %xmm0, 0xa0(%rsp)
vmovaps %xmm0, 0x30(%r9)
vmovss 0x1905(%rip), %xmm0     # 0x30a0
vmovaps %xmm0, 0x10(%rsp)
xorl %r9d, %r9d
vpxor %xmm1, %xmm1, %xmm1
vpxor %xmm4, %xmm4, %xmm4
vpxor %xmm3, %xmm3, %xmm3
movq %rdx, 0x150(%rsp)
movq %rdi, 0x148(%rsp)
leaq (%rdi,%r9), %rbx
leaq (%rdx,%r9), %rax
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
leaq (%r8,%r14), %r13
cmpq $0x10, %r13
jbe 0x1d1d
leaq (%r9,%r15), %rbp
cmpq $0x6c, %r13
vmovdqa %xmm3, 0x50(%rsp)
vmovdqa %xmm1, 0x40(%rsp)
vmovdqa %xmm4, 0x30(%rsp)
jb 0x1a33
testq %rbp, %rbp
je 0x1a33
vmovdqa 0x10(%rsp), %xmm2
vpaddq 0x1828(%rip), %xmm2, %xmm0 # 0x3040
vmovdqa %xmm0, 0x1b0(%rsp)
vpaddq 0x1827(%rip), %xmm2, %xmm2 # 0x3050
vmovdqa %xmm2, 0x10(%rsp)
vmovdqa %xmm2, 0x160(%rsp)
vpxor %xmm0, %xmm0, %xmm0
vmovdqa %xmm0, 0x1c0(%rsp)
vmovaps 0x130(%rsp), %xmm0
vmovaps %xmm0, 0x1d0(%rsp)
vmovaps 0xa0(%rsp), %xmm0
vmovaps %xmm0, 0x1e0(%rsp)
leaq 0x1b0(%rsp), %rdi
leaq 0x160(%rsp), %rsi
leaq 0x260(%rsp), %rdx
leaq 0xf0(%rsp), %rcx
movq %r9, %r12
movq %r8, %r13
movq %r10, %rbp
vzeroupper
callq 0x10b0
movq 0x20(%rsp), %rax
vmovups 0xe(%rax,%r15), %xmm0
vpxor %xmm4, %xmm4, %xmm4
vpblendw $0xfe, -0x2(%rax,%r15), %xmm4, %xmm1 # xmm1 = xmm4[0],mem[1,2,3,4,5,6,7]
vxorps 0x270(%rsp), %xmm0, %xmm2
vmovaps %xmm0, 0x270(%rsp)
vmovups 0x1e(%rax,%r15), %xmm0
vxorps 0x280(%rsp), %xmm0, %xmm3
vmovaps %xmm0, 0x280(%rsp)
vmovdqu 0x3c(%rax,%r15), %xmm0
vpblendw $0xfe, 0x2c(%rax,%r15), %xmm4, %xmm4 # xmm4 = xmm4[0],mem[1,2,3,4,5,6,7]
vpxor 0x100(%rsp), %xmm0, %xmm5
vmovdqa %xmm0, 0x100(%rsp)
vmovdqu 0x4c(%rax,%r15), %xmm0
vpxor 0x110(%rsp), %xmm0, %xmm6
vmovdqa %xmm0, 0x110(%rsp)
vmovd 0x1785(%rip), %xmm7     # 0x30a4
vpxor %xmm7, %xmm4, %xmm0
vpxor 0xf0(%rsp), %xmm0, %xmm4
vmovdqa %xmm0, 0xf0(%rsp)
vpxor %xmm7, %xmm1, %xmm0
vpxor 0x260(%rsp), %xmm0, %xmm1
vmovdqa %xmm0, 0x260(%rsp)
vmovdqa %xmm1, 0x60(%rsp)
vmovdqa %xmm4, 0x2a0(%rsp)
leaq 0x62(%rsp), %rcx
movq (%rcx), %rax
movq 0x6(%rcx), %rcx
movq %rcx, 0x6(%rbx,%r15)
movq %rax, (%rbx,%r15)
vmovups %xmm2, 0xe(%rbx,%r15)
vmovups %xmm3, 0x1e(%rbx,%r15)
leaq 0x2a2(%rsp), %rcx
movq (%rcx), %rax
movq 0x6(%rcx), %rcx
movq %rax, 0x2e(%rbx,%r15)
movq %rcx, 0x34(%rbx,%r15)
vmovdqu %xmm5, 0x3c(%rbx,%r15)
vmovdqu %xmm6, 0x4c(%rbx,%r15)
leaq 0x260(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0x220(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
callq 0x10b0
movq %r12, %r9
movq %rbp, %r10
movq %r13, %r8
vmovdqa 0x30(%rsp), %xmm4
vmovdqa 0x50(%rsp), %xmm3
vmovdqa 0xb0(%rsp), %xmm0
vmovdqa 0xc0(%rsp), %xmm1
vmovdqa 0xd0(%rsp), %xmm2
vpternlogq $0x96, 0x220(%rsp), %xmm0, %xmm3
vpternlogq $0x96, 0x230(%rsp), %xmm1, %xmm4
vmovdqa 0x40(%rsp), %xmm1
vpternlogq $0x96, 0x240(%rsp), %xmm2, %xmm1
leaq (%r12,%r15), %rax
addq $0x5c, %rax
movq %rax, (%rbp)
addq $0x5c, %r15
addq $-0x5c, %r14
jmp 0x17d3
cmpq $0x3e, %r13
movq %r10, 0x140(%rsp)
movq %r8, %r14
jb 0x1a4c
vmovdqa 0x10(%rsp), %xmm0
jmp 0x1a5a
vmovdqa 0x10(%rsp), %xmm0
vpaddq 0x1606(%rip), %xmm0, %xmm0 # 0x3060
vpaddq 0x15de(%rip), %xmm0, %xmm0 # 0x3040
vmovdqa %xmm0, 0x10(%rsp)
vmovdqa %xmm0, 0x160(%rsp)
leaq 0x160(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
vzeroupper
callq 0x10a0
movq 0x20(%rsp), %rsi
addq %r15, %rsi
vxorps %xmm2, %xmm2, %xmm2
vmovups %ymm2, 0x60(%rsp)
vmovups %ymm2, 0x70(%rsp)
cmpq $0x3e, %r13
jb 0x1ae0
vmovss 0x15f5(%rip), %xmm0     # 0x30a4
vmovaps %xmm0, 0x60(%rsp)
vmovdqu (%rsi), %ymm0
vmovdqu 0xe(%rsi), %ymm1
leaq 0x62(%rsp), %rax
vmovdqu %ymm1, 0xe(%rax)
vmovdqu %ymm0, (%rax)
vmovups %ymm2, 0x200(%rsp)
vmovups %ymm2, 0x1f0(%rsp)
jmp 0x1b49
vmovss 0x15c0(%rip), %xmm0     # 0x30a8
vmovaps %xmm0, 0x60(%rsp)
movq %r14, %r12
subq %r15, %r12
leaq -0x10(%r12), %rdx
leaq 0x62(%rsp), %rdi
vzeroupper
callq 0x10c0
leal -0x10(%r12), %eax
vpbroadcastb %eax, %xmm0
vmovdqa %xmm0, 0x1a0(%rsp)
addq $-0xe, %r12
vpcmpeqd %ymm0, %ymm0, %ymm0
vmovdqu %ymm0, 0x1f0(%rsp)
vmovdqu %ymm0, 0x200(%rsp)
leaq 0x1f0(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rdx
vzeroupper
callq 0x1030
addq %r15, %rbx
vmovdqa 0xf0(%rsp), %xmm6
vmovdqa 0x100(%rsp), %xmm4
vmovdqa 0x110(%rsp), %xmm2
vmovdqa 0x60(%rsp), %xmm7
vmovdqa 0x70(%rsp), %xmm5
vmovdqa 0x80(%rsp), %xmm3
vpxor %xmm6, %xmm7, %xmm0
vmovdqa %xmm0, 0x2a0(%rsp)
vpxor %xmm4, %xmm5, %xmm0
vmovdqa %xmm0, 0x2b0(%rsp)
vpxor %xmm2, %xmm3, %xmm0
vmovdqa %xmm0, 0x2c0(%rsp)
cmpq $0x3e, %r13
jb 0x1bcc
leaq 0x2a2(%rsp), %rax
vmovdqu (%rax), %ymm0
vmovdqu 0xe(%rax), %ymm1
vmovdqu %ymm1, 0xe(%rbx)
vmovdqu %ymm0, (%rbx)
pushq $0x2e
popq %r12
jmp 0x1c52
movq %r14, %r12
subq %r15, %r12
addq $-0x10, %r12
movq %rbx, %rdi
leaq 0x2a2(%rsp), %rsi
movq %r12, %rdx
vmovdqa %xmm2, 0x20(%rsp)
vmovdqa %xmm3, 0x350(%rsp)
vmovdqa %xmm4, 0x340(%rsp)
vmovdqa %xmm5, 0x330(%rsp)
vmovdqa %xmm6, 0x320(%rsp)
vmovdqa %xmm7, 0x310(%rsp)
vzeroupper
callq 0x10c0
vmovdqa 0x310(%rsp), %xmm7
vmovdqa 0x320(%rsp), %xmm6
vmovdqa 0x330(%rsp), %xmm5
vmovdqa 0x340(%rsp), %xmm4
vmovdqa 0x350(%rsp), %xmm3
vmovdqa 0x20(%rsp), %xmm2
vmovdqa 0x1a0(%rsp), %xmm1
vpxor %xmm1, %xmm6, %xmm0
vpternlogq $0xd8, 0x1f0(%rsp), %xmm0, %xmm7
vmovdqa %xmm7, 0xf0(%rsp)
vpxor %xmm1, %xmm4, %xmm0
vpternlogq $0xd8, 0x200(%rsp), %xmm0, %xmm5
vmovdqa %xmm5, 0x100(%rsp)
vpxor %xmm1, %xmm2, %xmm0
vpternlogq $0xd8, 0x210(%rsp), %xmm0, %xmm3
vmovdqa %xmm3, 0x110(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
vzeroupper
callq 0x10a0
subq %r15, %r14
addq $-0x2e, %r14
addq %r12, %rbp
cmpq $0x3e, %r13
vmovdqa 0x50(%rsp), %xmm3
vpxor 0xb0(%rsp), %xmm3, %xmm3
vmovdqa 0x30(%rsp), %xmm4
vpxor 0xc0(%rsp), %xmm4, %xmm4
vmovdqa 0x40(%rsp), %xmm1
vpxor 0xd0(%rsp), %xmm1, %xmm1
pushq $0x10
popq %rax
cmovbq %rax, %r14
movq 0x140(%rsp), %r10
movq %rbp, (%r10)
movq %rbp, %r9
movq %r14, %r8
movq 0x150(%rsp), %rdx
movq 0x148(%rsp), %rdi
jmp 0x17c0
vmovdqa %xmm4, 0x2e0(%rsp)
vmovdqa %xmm1, 0x2f0(%rsp)
xorl %eax, %eax
vpxor %xmm0, %xmm0, %xmm0
movq 0x158(%rsp), %r14
cmpq $0x40, %rax
je 0x1d7f
vmovdqa %xmm0, 0x160(%rsp,%rax)
vmovdqa %xmm0, 0xf0(%rsp,%rax)
vmovdqa %xmm0, 0xb0(%rsp,%rax)
vmovdqa %xmm0, 0x1b0(%rsp,%rax)
vmovdqa %xmm0, 0x260(%rsp,%rax)
vmovdqa %xmm0, 0x220(%rsp,%rax)
addq $0x10, %rax
jmp 0x1d3d
testq %r14, %r14
je 0x203a
cmpq $0x0, 0x8(%rsp)
je 0x20f6
movabsq $0x101010101010000, %r12 # imm = 0x101010101010000
leaq 0x160(%rsp), %rbx
vmovdqa 0xa0(%rsp), %xmm0
vmovdqa %xmm0, 0x30(%rbx)
vmovd 0x12f0(%rip), %xmm2     # 0x30ac
leaq 0x101(%r12), %rax
movq %rax, 0x130(%rsp)
xorl %ebp, %ebp
testq %r14, %r14
je 0x2028
cmpq $0x3d, %r14
setb %al
testq %rbp, %rbp
sete %cl
orb %al, %cl
cmpb $0x1, %cl
vmovdqa %xmm3, 0x50(%rsp)
vmovdqa %xmm1, 0x40(%rsp)
vmovdqa %xmm4, 0x30(%rsp)
jne 0x1e59
cmpq $0x1e, %r14
jae 0x1e0b
vpaddq 0x1255(%rip), %xmm2, %xmm2 # 0x3060
vpaddq 0x122d(%rip), %xmm2, %xmm2 # 0x3040
vmovdqa %xmm2, 0x160(%rsp)
andq $0x0, 0x60(%rsp)
cmpq $0x1e, %r14
vmovdqa %xmm2, 0x10(%rsp)
jb 0x1f54
movq 0x8(%rsp), %rax
vmovdqu (%rax,%rbp), %xmm0
vmovdqu 0xe(%rax,%rbp), %xmm1
leaq 0x62(%rsp), %rax
vmovdqu %xmm1, 0xe(%rax)
vmovdqu %xmm0, (%rax)
pushq $0x1e
popq %r13
jmp 0x1f9b
vpaddq 0x11df(%rip), %xmm2, %xmm0 # 0x3040
vmovdqa %xmm0, 0x1b0(%rsp)
vpaddq 0x11de(%rip), %xmm2, %xmm2 # 0x3050
vmovdqa %xmm2, 0x10(%rsp)
vmovdqa %xmm2, 0x160(%rsp)
vmovaps 0xa0(%rsp), %xmm0
vmovaps %xmm0, 0x1e0(%rsp)
movq 0x8(%rsp), %rax
vpxor %xmm2, %xmm2, %xmm2
vpblendw $0xfe, -0x2(%rax,%rbp), %xmm2, %xmm0 # xmm0 = xmm2[0],mem[1,2,3,4,5,6,7]
vmovdqa %xmm0, 0x1c0(%rsp)
vmovups 0xe(%rax,%rbp), %xmm0
vmovaps %xmm0, 0x1d0(%rsp)
vpblendw $0xfe, 0x1c(%rax,%rbp), %xmm2, %xmm0 # xmm0 = xmm2[0],mem[1,2,3,4,5,6,7]
vmovdqa %xmm0, 0x170(%rsp)
vmovups 0x2c(%rax,%rbp), %xmm0
vmovaps %xmm0, 0x180(%rsp)
leaq 0x1b0(%rsp), %rdi
movq %rbx, %rsi
leaq 0x220(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
vzeroupper
callq 0x10b0
vmovdqa 0x30(%rsp), %xmm4
vmovdqa 0x50(%rsp), %xmm3
vmovdqa 0xb0(%rsp), %xmm0
vmovdqa 0xc0(%rsp), %xmm1
vmovdqa 0xd0(%rsp), %xmm2
vpternlogq $0x96, 0x220(%rsp), %xmm0, %xmm3
vpternlogq $0x96, 0x230(%rsp), %xmm1, %xmm4
vmovdqa 0x40(%rsp), %xmm1
vpternlogq $0x96, 0x240(%rsp), %xmm2, %xmm1
addq $-0x3c, %r14
pushq $0x3c
popq %r13
jmp 0x201a
movq %r14, %rax
imulq %r12, %rax
movq %rax, 0x60(%rsp)
movq %r14, %rax
imulq 0x130(%rsp), %rax
pushq $0x1
popq %rcx
cmpq $0x4, %rcx
je 0x1f7f
movq %rax, 0x60(%rsp,%rcx,8)
incq %rcx
jmp 0x1f6f
movq 0x8(%rsp), %rax
leaq (%rax,%rbp), %rsi
leaq 0x62(%rsp), %rdi
movq %r14, %rdx
vzeroupper
callq 0x10c0
movq %r14, %r13
vmovdqa 0x60(%rsp), %xmm0
vmovdqa 0x70(%rsp), %xmm1
vpinsrq $0x1, 0x68(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x170(%rsp)
vpinsrq $0x1, 0x78(%rsp), %xmm1, %xmm0
vmovdqa %xmm0, 0x180(%rsp)
movq %rbx, %rdi
leaq 0xb0(%rsp), %rsi
vzeroupper
callq 0x10a0
cmpq $0x1e, %r14
vmovdqa 0x50(%rsp), %xmm3
vpxor 0xb0(%rsp), %xmm3, %xmm3
leaq -0x1e(%r14), %r14
vmovdqa 0x30(%rsp), %xmm4
vpxor 0xc0(%rsp), %xmm4, %xmm4
vmovdqa 0x40(%rsp), %xmm1
vpxor 0xd0(%rsp), %xmm1, %xmm1
movl $0x0, %ecx
cmovbq %rcx, %r14
addq %r13, %rbp
vmovdqa 0x10(%rsp), %xmm2
jmp 0x1dce
vmovdqa %xmm4, 0x2e0(%rsp)
vmovdqa %xmm1, 0x2f0(%rsp)
leaq 0x2d0(%rsp), %rdi
vmovdqa 0xa0(%rsp), %xmm0
vmovdqa %xmm0, 0x30(%rdi)
vpxor %xmm0, %xmm0, %xmm0
vpblendw $0x1, %xmm0, %xmm3, %xmm0 # xmm0 = xmm0[0],xmm3[1,2,3,4,5,6,7]
vpaddq 0x100e(%rip), %xmm0, %xmm0 # 0x3070
vmovdqa %xmm0, (%rdi)
leaq 0x60(%rsp), %rsi
vzeroupper
callq 0x10a0
vpxor %xmm0, %xmm0, %xmm0
xorl %eax, %eax
movq 0x20(%rsp), %rcx
cmpq $0x40, %rax
je 0x20c9
vmovdqa %xmm0, 0x160(%rsp,%rax)
vmovdqa %xmm0, 0xf0(%rsp,%rax)
vmovdqa %xmm0, 0xb0(%rsp,%rax)
vmovdqa %xmm0, 0x1b0(%rsp,%rax)
vmovdqa %xmm0, 0x260(%rsp,%rax)
vmovdqa %xmm0, 0x220(%rsp,%rax)
vmovdqa %xmm0, 0x2d0(%rsp,%rax)
addq $0x10, %rax
jmp 0x207e
vmovdqa 0x60(%rsp), %xmm0
vpxor (%r15,%rcx), %xmm0, %xmm0
xorl %eax, %eax
vptest %xmm0, %xmm0
setne %al
negl %eax
addq $0x368, %rsp            # imm = 0x368
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
xorl %ecx, %ecx
pushq $-0x4
popq %rax
vpxor %xmm0, %xmm0, %xmm0
cmpq $0x40, %rcx
je 0x20e1
vmovdqa %xmm0, 0x2d0(%rsp,%rcx)
addq $0x10, %rcx
jmp 0x20ff