// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/paeq128/aesni/encrypt.cpp
// Function: PAEQ128_opt_AESNI_encrypt(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_encrypt(
	unsigned char *c, unsigned long long *clen,
	const unsigned char *m, unsigned long long mlen,
	const unsigned char *ad, unsigned long long adlen,
	const unsigned char *npub,
	const unsigned char *k
	)

{

	if (clen == NULL)
		return -1;
	if ((mlen == 0) && (adlen == 0))
	{
		*clen = 0;
		return 0;
	}

	//Assume that we do encryption and/or authentication so we need a key and a ciphertext pointer valid
	if ((k == NULL) || (c == NULL))
		return -2;

	if (npub == NULL)
		return -7;

	//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 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);
	(*clen) = 0;

	//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);  //Also sets counter to 0
	memset(BlockOutput, 0, 64);
	memset(BlockMiddle, 0, 64);
	memset(BlockMiddle, 0, 64);

	//1.3 Setting first block: Constant (bytes 0-1) || Counter (bytes 2-35) || Nonce (bytes 36-47) || Key (bytes 48-63)
	//1.3.1 Domain separation
	BlockInput[0] = D0;  //Domain separation constant

	//1.3.2 Nonce
	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);   

	//1.3.3 Key
	__m128i Key = _mm_set_epi64x(*((uint64_t*)(k + 8)), (*((uint64_t*)k)));
	BlockInput[3] = Key;

	unsigned long long encrypted_bytes = 0;//Encrypted bytes counter

	//Encryption part
	if (mlen != 0)
	{
		if (m == NULL)
			return -3;

		while ((mlen>0))
		{
			// I. First layer 

			if ((mlen < 2 * CRYPTO_MBLOCK) || (encrypted_bytes == 0))
			{

				//1. Domain-separation constant
				if (mlen < CRYPTO_MBLOCK) //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 plaintext buffers
				__m128i plaintext128[3];
				uint64_t plaintext_buffer[6];
				uint64_t ciphertext_buffer[6];
				plaintext_buffer[0] = D_left + 2; //Making D2
				if (mlen >= CRYPTO_MBLOCK)//Full block encryption
					memcpy(((char*)plaintext_buffer) + 2, m + encrypted_bytes, CRYPTO_MBLOCK);
				else
				{
					plaintext_buffer[0]++; //Making D3
					//Filling buffers with mlen
					plaintext_buffer[0] ^= (((uint64_t)mlen * 0x01010101) << 32) ^ ((uint64_t)mlen * 0x01010000);
					for (unsigned i = 1; i < 6; ++i)
						plaintext_buffer[i] = (((uint64_t)mlen * 0x01010101) << 32) ^ ((uint64_t)mlen * 0x01010101);
					memcpy(((char*)plaintext_buffer) + 2, m + encrypted_bytes, mlen);
				}

				//2. Working with BlockMiddle
				plaintext128[0] = _mm_set_epi64x(plaintext_buffer[1], plaintext_buffer[0]);
				plaintext128[1] = _mm_set_epi64x(plaintext_buffer[3], plaintext_buffer[2]);
				plaintext128[2] = _mm_set_epi64x(plaintext_buffer[5], plaintext_buffer[4]);

				BlockMiddle[0] = _mm_and_si128(BlockMiddle[0], Dmask); //Clearing first two bytes
				BlockMiddle[0] = _mm_xor_si128(BlockMiddle[0], plaintext128[0]);
				BlockMiddle[1] = _mm_xor_si128(BlockMiddle[1], plaintext128[1]);
				BlockMiddle[2] = _mm_xor_si128(BlockMiddle[2], plaintext128[2]);

				//Ciphertext extraction
				_mm_storeu_si128((__m128i*)ciphertext_buffer, BlockMiddle[0]);
				_mm_storeu_si128((__m128i*)(ciphertext_buffer+2), BlockMiddle[1]);
				_mm_storeu_si128((__m128i*)(ciphertext_buffer+4), BlockMiddle[2]);

				if (mlen >= CRYPTO_MBLOCK)
					memcpy(c + encrypted_bytes, ((char*)ciphertext_buffer) + 2, CRYPTO_MBLOCK);
				else //Last incomplete block
					memcpy(c + encrypted_bytes, ((char*)ciphertext_buffer) + 2, mlen);
				memset(ciphertext_buffer, 0, 6 * sizeof(uint64_t));

				//Counters increment
				if (mlen >= CRYPTO_MBLOCK)
				{
					encrypted_bytes += CRYPTO_MBLOCK;
					mlen -= CRYPTO_MBLOCK;
				}
				else
				{
					encrypted_bytes += mlen;
					mlen = 0;
				}
				(*clen) = encrypted_bytes;

				//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]);
			}//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. Loading plaintext
				__m128i plaintext_buffer[6];  //96-byte storage
				plaintext_buffer[0] = _mm_loadu_si128((__m128i*)(m + encrypted_bytes - 2));   //Bytes [0:13]
				plaintext_buffer[1] = _mm_loadu_si128((__m128i*)(m + encrypted_bytes + 14));  //Bytes [14:29]
				plaintext_buffer[2] = _mm_loadu_si128((__m128i*)(m + encrypted_bytes + 30));  //Bytes [30:45]
				plaintext_buffer[3] = _mm_loadu_si128((__m128i*)(m + encrypted_bytes + 44));  //Bytes [0:13]
				plaintext_buffer[4] = _mm_loadu_si128((__m128i*)(m + encrypted_bytes + 60));   //Bytes [14:29]
				plaintext_buffer[5] = _mm_loadu_si128((__m128i*)(m + encrypted_bytes + 76));  //Bytes [30:45]

				//4. 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);

				//5. Xoring plaintext
				plaintext_buffer[0] = _mm_and_si128(plaintext_buffer[0], Dmask); //Clearing first two bytes
				plaintext_buffer[3] = _mm_and_si128(plaintext_buffer[3], Dmask); //Clearing first two bytes
				BlockExtraMiddle[0] = _mm_xor_si128(BlockExtraMiddle[0], plaintext_buffer[0]);
				BlockExtraMiddle[1] = _mm_xor_si128(BlockExtraMiddle[1], plaintext_buffer[1]);
				BlockExtraMiddle[2] = _mm_xor_si128(BlockExtraMiddle[2], plaintext_buffer[2]);
				BlockMiddle[0] = _mm_xor_si128(BlockMiddle[0], plaintext_buffer[3]);
				BlockMiddle[1] = _mm_xor_si128(BlockMiddle[1], plaintext_buffer[4]);
				BlockMiddle[2] = _mm_xor_si128(BlockMiddle[2], plaintext_buffer[5]);

				//6. Extracting ciphertext
				memcpy(c + encrypted_bytes, ((char*)BlockExtraMiddle) + 2, CRYPTO_MBLOCK);
				memcpy(c + encrypted_bytes + 46, ((char*)BlockMiddle) + 2, 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
				encrypted_bytes += 2 * CRYPTO_MBLOCK;
				mlen -= 2 * CRYPTO_MBLOCK;
				(*clen) = encrypted_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. Truncation
	memcpy(c + (*clen), Tag, CRYPTO_ABYTES);
	*clen += CRYPTO_ABYTES;


	//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);



	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
movq %r8, 0x10(%rsp)
movq %rdi, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
testq %rsi, %rsi
je 0x2169
movq %r9, %r15
movq %rcx, %rbp
movq %r9, %rax
orq %rcx, %rax
je 0x216e
movq %rdx, %r13
movq 0x308(%rsp), %rax
testq %rax, %rax
sete %cl
cmpq $0x0, 0x18(%rsp)
sete %dl
orb %cl, %dl
je 0x218e
pushq $-0x2
jmp 0x216b
pushq $-0x1
popq %rax
jmp 0x2179
movq 0x8(%rsp), %rax
andq $0x0, (%rax)
xorl %eax, %eax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
movq 0x300(%rsp), %rcx
testq %rcx, %rcx
je 0x26bc
movq 0x8(%rsp), %rdx
andq $0x0, (%rdx)
vxorps %xmm0, %xmm0, %xmm0
vmovups %ymm0, 0x250(%rsp)
vmovups %ymm0, 0x270(%rsp)
vmovups %ymm0, 0x140(%rsp)
vmovups %ymm0, 0xf0(%rsp)
vmovups %ymm0, 0x110(%rsp)
vmovups %ymm0, 0xb0(%rsp)
vmovups %ymm0, 0xd0(%rsp)
movq (%rcx), %rdx
shlq $0x20, %rdx
vmovq 0x4(%rcx), %xmm0
vmovq %rdx, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
vmovdqa %xmm0, 0x130(%rsp)
vmovdqa %xmm0, 0x160(%rsp)
vmovdqu (%rax), %xmm0
vmovdqa %xmm0, 0xa0(%rsp)
vmovdqa %xmm0, 0x170(%rsp)
vpxor %xmm0, %xmm0, %xmm0
testq %rbp, %rbp
je 0x26df
testq %r13, %r13
je 0x2aa3
movq %r15, 0x180(%rsp)
vmovd 0xe52(%rip), %xmm1      # 0x30a0
vmovdqa %xmm1, 0x20(%rsp)
leaq 0x140(%rsp), %r12
leaq 0xf0(%rsp), %r14
movabsq $0x101010101010000, %rax # imm = 0x101010101010000
addq $0x101, %rax            # imm = 0x101
movq %rax, 0x188(%rsp)
vpxor %xmm1, %xmm1, %xmm1
vpxor %xmm4, %xmm4, %xmm4
vpxor %xmm3, %xmm3, %xmm3
xorl %ebx, %ebx
testq %rbp, %rbp
je 0x26c3
cmpq $0x5c, %rbp
setb %al
testq %rbx, %rbx
sete %cl
orb %al, %cl
cmpb $0x1, %cl
vmovdqa %xmm3, 0x50(%rsp)
vmovdqa %xmm1, 0x40(%rsp)
vmovdqa %xmm4, 0x30(%rsp)
jne 0x22ce
cmpq $0x2e, %rbp
jb 0x24cc
vmovdqa 0x20(%rsp), %xmm0
jmp 0x24da
vmovdqa 0x20(%rsp), %xmm2
vpaddq 0xd64(%rip), %xmm2, %xmm0 # 0x3040
vmovdqa %xmm0, 0x190(%rsp)
vpaddq 0xd63(%rip), %xmm2, %xmm2 # 0x3050
vmovdqa %xmm2, 0x20(%rsp)
vmovdqa %xmm2, 0x140(%rsp)
vpxor %xmm0, %xmm0, %xmm0
vmovdqa %xmm0, 0x1a0(%rsp)
vmovaps 0x130(%rsp), %xmm0
vmovaps %xmm0, 0x1b0(%rsp)
vmovaps 0xa0(%rsp), %xmm0
vmovaps %xmm0, 0x1c0(%rsp)
leaq 0x190(%rsp), %rdi
movq %r12, %rsi
leaq 0x1d0(%rsp), %rdx
movq %r14, %r15
leaq 0xb0(%rsp), %r14
movq %r14, %rcx
vzeroupper
callq 0x10b0
vmovdqa 0x1d0(%rsp), %xmm0
vmovaps 0x1e0(%rsp), %xmm1
vmovaps 0x1f0(%rsp), %xmm2
vpxor -0x2(%r13,%rbx), %xmm0, %xmm0
vpxor %xmm7, %xmm7, %xmm7
vpblendw $0x1, %xmm7, %xmm0, %xmm0 # xmm0 = xmm7[0],xmm0[1,2,3,4,5,6,7]
vmovd 0xd1a(%rip), %xmm6      # 0x30a4
vpxor %xmm6, %xmm0, %xmm0
vxorps 0xe(%r13,%rbx), %xmm1, %xmm1
vxorps 0x1e(%r13,%rbx), %xmm2, %xmm2
vmovdqa 0xb0(%rsp), %xmm3
vmovaps 0xc0(%rsp), %xmm4
vmovaps 0xd0(%rsp), %xmm5
vpxor 0x2c(%r13,%rbx), %xmm3, %xmm3
vxorps 0x3c(%r13,%rbx), %xmm4, %xmm4
vxorps 0x4c(%r13,%rbx), %xmm5, %xmm5
vmovdqa %xmm0, 0x1d0(%rsp)
vmovaps %xmm1, 0x1e0(%rsp)
vmovaps %xmm2, 0x1f0(%rsp)
vpblendw $0x1, %xmm7, %xmm3, %xmm0 # xmm0 = xmm7[0],xmm3[1,2,3,4,5,6,7]
vpxor %xmm6, %xmm0, %xmm0
vmovdqa %xmm0, 0xb0(%rsp)
vmovaps %xmm4, 0xc0(%rsp)
vmovaps %xmm5, 0xd0(%rsp)
leaq 0x1d2(%rsp), %rax
vmovups (%rax), %ymm0
vmovups 0xe(%rax), %ymm1
movq 0x18(%rsp), %rcx
vmovups %ymm1, 0xe(%rcx,%rbx)
vmovups %ymm0, (%rcx,%rbx)
leaq 0xb2(%rsp), %rax
vmovups (%rax), %ymm0
vmovups 0xe(%rax), %ymm1
vmovups %ymm0, 0x2e(%rcx,%rbx)
vmovups %ymm1, 0x3c(%rcx,%rbx)
leaq 0x1d0(%rsp), %rdi
movq %r14, %rsi
movq %r15, %r14
leaq 0x210(%rsp), %rdx
movq %r15, %rcx
vzeroupper
callq 0x10b0
vmovdqa 0x30(%rsp), %xmm4
vmovdqa 0x50(%rsp), %xmm3
vmovdqa 0xf0(%rsp), %xmm0
vmovdqa 0x100(%rsp), %xmm1
vmovdqa 0x110(%rsp), %xmm2
vpternlogq $0x96, 0x210(%rsp), %xmm0, %xmm3
vpxor %xmm0, %xmm0, %xmm0
vpternlogq $0x96, 0x220(%rsp), %xmm1, %xmm4
vmovdqa 0x40(%rsp), %xmm1
vpternlogq $0x96, 0x230(%rsp), %xmm2, %xmm1
addq $0x5c, %rbx
addq $-0x5c, %rbp
movq 0x8(%rsp), %rax
movq %rbx, (%rax)
jmp 0x228a
vmovdqa 0x20(%rsp), %xmm0
vpaddq 0xb86(%rip), %xmm0, %xmm0 # 0x3060
vpaddq 0xb5e(%rip), %xmm0, %xmm0 # 0x3040
vmovdqa %xmm0, 0x20(%rsp)
vmovdqa %xmm0, 0x140(%rsp)
movq %r12, %rdi
leaq 0xb0(%rsp), %rsi
vzeroupper
callq 0x10a0
movq $0x8062, 0x60(%rsp)     # imm = 0x8062
cmpq $0x2e, %rbp
jb 0x2531
vmovdqu (%r13,%rbx), %ymm0
vmovdqu 0xe(%r13,%rbx), %ymm1
leaq 0x62(%rsp), %rax
vmovdqu %ymm1, 0xe(%rax)
vmovdqu %ymm0, (%rax)
jmp 0x257d
movq %rbp, %rax
movabsq $0x101010101010000, %rcx # imm = 0x101010101010000
imulq %rcx, %rax
orq $0x8063, %rax           # imm = 0x8063
movq %rax, 0x60(%rsp)
movq %rbp, %rax
imulq 0x188(%rsp), %rax
pushq $0x1
popq %rcx
cmpq $0x6, %rcx
je 0x256c
movq %rax, 0x60(%rsp,%rcx,8)
incq %rcx
jmp 0x255c
leaq (%rbx,%r13), %rsi
leaq 0x62(%rsp), %rdi
movq %rbp, %rdx
callq 0x10c0
vmovdqa 0x60(%rsp), %xmm0
vmovdqa 0x70(%rsp), %xmm1
vmovdqa 0x80(%rsp), %xmm2
vpinsrq $0x1, 0x68(%rsp), %xmm0, %xmm0
vpinsrq $0x1, 0x78(%rsp), %xmm1, %xmm1
vpinsrq $0x1, 0x88(%rsp), %xmm2, %xmm2
vpxor %xmm3, %xmm3, %xmm3
vpblendw $0xfe, 0xb0(%rsp), %xmm3, %xmm3 # xmm3 = xmm3[0],mem[1,2,3,4,5,6,7]
vpxor %xmm0, %xmm3, %xmm0
vmovdqa %xmm0, 0xb0(%rsp)
vpxor 0xc0(%rsp), %xmm1, %xmm1
vmovdqa %xmm1, 0xc0(%rsp)
vpxor 0xd0(%rsp), %xmm2, %xmm2
vmovdqa %xmm2, 0xd0(%rsp)
vmovdqa %xmm0, 0x290(%rsp)
movq 0x18(%rsp), %rax
leaq (%rax,%rbx), %rdi
vmovdqa %xmm1, 0x2a0(%rsp)
vmovdqa %xmm2, 0x2b0(%rsp)
cmpq $0x2e, %rbp
jb 0x2636
leaq 0x292(%rsp), %rax
vmovdqu (%rax), %ymm0
vmovdqu 0xe(%rax), %ymm1
vmovdqu %ymm1, 0xe(%rdi)
vmovdqu %ymm0, (%rdi)
pushq $0x2e
popq %rax
jmp 0x264c
leaq 0x292(%rsp), %rsi
movq %rbp, %rdx
vzeroupper
callq 0x10c0
movq %rbp, %rax
leaq -0x2e(%rbp), %r12
addq %rax, %rbx
cmpq $0x2e, %rbp
movl $0x0, %eax
cmovbq %rax, %r12
movq 0x8(%rsp), %rax
movq %rbx, (%rax)
leaq 0xb0(%rsp), %rdi
movq %r14, %rsi
vzeroupper
callq 0x10a0
vmovdqa 0x50(%rsp), %xmm3
vpxor 0xf0(%rsp), %xmm3, %xmm3
vmovdqa 0x30(%rsp), %xmm4
vpxor 0x100(%rsp), %xmm4, %xmm4
vmovdqa 0x40(%rsp), %xmm1
vpxor 0x110(%rsp), %xmm1, %xmm1
movq %r12, %rbp
vpxor %xmm0, %xmm0, %xmm0
leaq 0x140(%rsp), %r12
jmp 0x228a
pushq $-0x7
jmp 0x216b
vmovdqa %xmm4, 0x260(%rsp)
vmovdqa %xmm1, 0x270(%rsp)
movq 0x180(%rsp), %r15
jmp 0x26ed
xorl %ebx, %ebx
vpxor %xmm1, %xmm1, %xmm1
vpxor %xmm4, %xmm4, %xmm4
vpxor %xmm3, %xmm3, %xmm3
xorl %eax, %eax
cmpq $0x40, %rax
je 0x2731
vmovdqa %xmm0, 0x140(%rsp,%rax)
vmovdqa %xmm0, 0xb0(%rsp,%rax)
vmovdqa %xmm0, 0xf0(%rsp,%rax)
vmovdqa %xmm0, 0x190(%rsp,%rax)
vmovdqa %xmm0, 0x1d0(%rsp,%rax)
vmovdqa %xmm0, 0x210(%rsp,%rax)
addq $0x10, %rax
jmp 0x26ef
testq %r15, %r15
je 0x29f8
cmpq $0x0, 0x10(%rsp)
je 0x2aaa
leaq 0x140(%rsp), %r14
vmovdqa 0xa0(%rsp), %xmm0
vmovdqa %xmm0, 0x30(%r14)
vmovd 0x947(%rip), %xmm2      # 0x30ac
leaq 0xf0(%rsp), %rbp
movabsq $0x101010101010000, %rax # imm = 0x101010101010000
addq $0x101, %rax            # imm = 0x101
movq %rax, 0x130(%rsp)
xorl %r13d, %r13d
testq %r15, %r15
je 0x29e6
cmpq $0x3d, %r15
setb %al
testq %r13, %r13
sete %cl
orb %al, %cl
cmpb $0x1, %cl
vmovdqa %xmm3, 0x50(%rsp)
vmovdqa %xmm1, 0x40(%rsp)
vmovdqa %xmm4, 0x30(%rsp)
jne 0x2815
cmpq $0x1e, %r15
jae 0x27c5
vpaddq 0x89b(%rip), %xmm2, %xmm2 # 0x3060
vpaddq 0x873(%rip), %xmm2, %xmm2 # 0x3040
vmovdqa %xmm2, 0x140(%rsp)
andq $0x0, 0x60(%rsp)
cmpq $0x1e, %r15
vmovdqa %xmm2, 0x20(%rsp)
jb 0x290d
movq 0x10(%rsp), %rax
vmovdqu (%rax,%r13), %xmm0
vmovdqu 0xe(%rax,%r13), %xmm1
leaq 0x62(%rsp), %rax
vmovdqu %xmm1, 0xe(%rax)
vmovdqu %xmm0, (%rax)
pushq $0x1e
popq %r12
jmp 0x295e
vpaddq 0x823(%rip), %xmm2, %xmm0 # 0x3040
vmovdqa %xmm0, 0x190(%rsp)
vpaddq 0x822(%rip), %xmm2, %xmm2 # 0x3050
vmovdqa %xmm2, 0x20(%rsp)
vmovdqa %xmm2, 0x140(%rsp)
vmovaps 0xa0(%rsp), %xmm0
vmovaps %xmm0, 0x1c0(%rsp)
movq 0x10(%rsp), %rax
vpxor %xmm2, %xmm2, %xmm2
vpblendw $0xfe, -0x2(%rax,%r13), %xmm2, %xmm0 # xmm0 = xmm2[0],mem[1,2,3,4,5,6,7]
vmovdqa %xmm0, 0x1a0(%rsp)
vmovups 0xe(%rax,%r13), %xmm0
vmovaps %xmm0, 0x1b0(%rsp)
vpblendw $0xfe, 0x1c(%rax,%r13), %xmm2, %xmm0 # xmm0 = xmm2[0],mem[1,2,3,4,5,6,7]
vmovdqa %xmm0, 0x150(%rsp)
vmovups 0x2c(%rax,%r13), %xmm0
vmovaps %xmm0, 0x160(%rsp)
leaq 0x190(%rsp), %rdi
movq %r14, %rsi
leaq 0x210(%rsp), %rdx
movq %rbp, %rcx
vzeroupper
callq 0x10b0
vmovdqa 0x30(%rsp), %xmm4
vmovdqa 0x50(%rsp), %xmm3
vmovdqa 0xf0(%rsp), %xmm0
vmovdqa 0x100(%rsp), %xmm1
vmovdqa 0x110(%rsp), %xmm2
vpternlogq $0x96, 0x210(%rsp), %xmm0, %xmm3
vpternlogq $0x96, 0x220(%rsp), %xmm1, %xmm4
vmovdqa 0x40(%rsp), %xmm1
vpternlogq $0x96, 0x230(%rsp), %xmm2, %xmm1
addq $-0x3c, %r15
pushq $0x3c
popq %r12
jmp 0x29d8
movq %r15, %rax
movabsq $0x101010101010000, %rcx # imm = 0x101010101010000
imulq %rcx, %rax
movq %rax, 0x60(%rsp)
movq %r15, %rax
imulq 0x130(%rsp), %rax
pushq $0x1
popq %rcx
cmpq $0x4, %rcx
je 0x2942
movq %rax, 0x60(%rsp,%rcx,8)
incq %rcx
jmp 0x2932
movq 0x10(%rsp), %rax
leaq (%rax,%r13), %rsi
leaq 0x62(%rsp), %rdi
movq %r15, %rdx
vzeroupper
callq 0x10c0
movq %r15, %r12
vmovdqa 0x60(%rsp), %xmm0
vmovdqa 0x70(%rsp), %xmm1
vpinsrq $0x1, 0x68(%rsp), %xmm0, %xmm0
vmovdqa %xmm0, 0x150(%rsp)
vpinsrq $0x1, 0x78(%rsp), %xmm1, %xmm0
vmovdqa %xmm0, 0x160(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
vzeroupper
callq 0x10a0
cmpq $0x1e, %r15
vmovdqa 0x50(%rsp), %xmm3
vpxor 0xf0(%rsp), %xmm3, %xmm3
leaq -0x1e(%r15), %r15
vmovdqa 0x30(%rsp), %xmm4
vpxor 0x100(%rsp), %xmm4, %xmm4
vmovdqa 0x40(%rsp), %xmm1
vpxor 0x110(%rsp), %xmm1, %xmm1
movl $0x0, %eax
cmovbq %rax, %r15
addq %r12, %r13
vmovdqa 0x20(%rsp), %xmm2
jmp 0x2788
vmovdqa %xmm4, 0x260(%rsp)
vmovdqa %xmm1, 0x270(%rsp)
leaq 0x250(%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 0x650(%rip), %xmm0, %xmm0 # 0x3070
vmovdqa %xmm0, (%rdi)
leaq 0x60(%rsp), %r15
movq %r15, %rsi
vzeroupper
callq 0x10a0
vmovdqa (%r15), %xmm0
movq 0x18(%rsp), %rax
vmovdqu %xmm0, (%rax,%rbx)
vpxor %xmm0, %xmm0, %xmm0
movq 0x8(%rsp), %rax
addq $0x10, (%rax)
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0x40, %rcx
je 0x2179
vmovdqa %xmm0, 0x140(%rsp,%rcx)
vmovdqa %xmm0, 0xb0(%rsp,%rcx)
vmovdqa %xmm0, 0xf0(%rsp,%rcx)
vmovdqa %xmm0, 0x190(%rsp,%rcx)
vmovdqa %xmm0, 0x1d0(%rsp,%rcx)
vmovdqa %xmm0, 0x210(%rsp,%rcx)
vmovdqa %xmm0, 0x250(%rsp,%rcx)
addq $0x10, %rcx
jmp 0x2a54
pushq $-0x3
jmp 0x216b
xorl %ecx, %ecx
pushq $-0x4
popq %rax
vpxor %xmm0, %xmm0, %xmm0
cmpq $0x40, %rcx
je 0x2179
vmovdqa %xmm0, 0x250(%rsp,%rcx)
addq $0x10, %rcx
jmp 0x2ab3