// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/paeq128/aesni/encrypt.cpp
// Function: FPerm(unsigned char const*, unsigned char*)
void FPerm(const unsigned char* input, unsigned char* output)//AESQ permutation
{

	unsigned char Registers[4][16];  //AES state registers
	unsigned char Registers_tmp[4][16];  //AES state registers

	for (unsigned i = 0; i<4; ++i)//Filling registers
	{
		for (unsigned j = 0; j<16; ++j)
			Registers[i][j] = input[16 * i + j];
	}

	//Main permutation
	for (unsigned i = 0; i<AES_GROUPS; ++i)//Group loop
	{
		//AES rounds
		for (unsigned r = 0; r<4; ++r)//Register loop
		{
			for (unsigned j = 0; j<AES_GROUP_ROUNDS; ++j)//Middle rounds
			{
				AES_Round(Registers[r]); //SB-SR-MC
				for (unsigned k = 0; k<4; ++k)  //Round constants
				{
					Registers[r][4 * k] ^= 8 * i + 4 * j + r + 1;
				}
			}
		}
		//Permutation
		for (unsigned r = 0; r<4; ++r)//Register loop
			for (unsigned j = 0; j<16; ++j)
				Registers_tmp[r][j] = Registers[r][j];

		for (unsigned r = 0; r<4; ++r)//Register loop
		{
			for (unsigned i = 0; i<4; ++i)//Column loop
			{
				unsigned char r_out = Shuffle[4 * r + i] / 4;  //Register index
				unsigned char c_out = Shuffle[4 * r + i] % 4;  //Column index
				for (unsigned j = 0; j<4; ++j)
					Registers[r_out][4 * c_out + j] = Registers_tmp[r][4 * i + j];
			}
		}


	}
	for (unsigned i = 0; i<4; ++i)//Filling registers
	{
		for (unsigned j = 0; j<16; ++j)
			output[16 * i + j] = Registers[i][j];
	}

}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
movl $0x0, 0x3c(%rsp)
cmpl $0x4, 0x3c(%rsp)
jae 0x1645
movl $0x0, 0x38(%rsp)
cmpl $0x10, 0x38(%rsp)
jae 0x1636
movq 0xd0(%rsp), %rax
movl 0x3c(%rsp), %ecx
shll $0x4, %ecx
addl 0x38(%rsp), %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movl 0x3c(%rsp), %eax
movl %eax, %ecx
leaq 0x80(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x38(%rsp), %ecx
movb %dl, (%rax,%rcx)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x15ee
jmp 0x1638
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x15df
movl $0x0, 0x34(%rsp)
cmpl $0xa, 0x34(%rsp)
jae 0x1892
movl $0x0, 0x30(%rsp)
cmpl $0x4, 0x30(%rsp)
jae 0x1714
movl $0x0, 0x2c(%rsp)
cmpl $0x2, 0x2c(%rsp)
jae 0x1702
movl 0x30(%rsp), %eax
leaq 0x80(%rsp), %rdi
shlq $0x4, %rax
addq %rax, %rdi
callq 0x10d0
movl $0x0, 0x28(%rsp)
cmpl $0x4, 0x28(%rsp)
jae 0x16f0
movl 0x34(%rsp), %esi
shll $0x3, %esi
movl 0x2c(%rsp), %eax
shll $0x2, %eax
addl %eax, %esi
addl 0x30(%rsp), %esi
addl $0x1, %esi
movl 0x30(%rsp), %eax
movl %eax, %ecx
leaq 0x80(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x28(%rsp), %ecx
shll $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x169e
jmp 0x16f2
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x1673
jmp 0x1704
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x1660
movl $0x0, 0x24(%rsp)
cmpl $0x4, 0x24(%rsp)
jae 0x1783
movl $0x0, 0x20(%rsp)
cmpl $0x10, 0x20(%rsp)
jae 0x1774
movl 0x24(%rsp), %eax
movl %eax, %ecx
leaq 0x80(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x20(%rsp), %ecx
movb (%rax,%rcx), %dl
movl 0x24(%rsp), %eax
movl %eax, %ecx
leaq 0x40(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x20(%rsp), %ecx
movb %dl, (%rax,%rcx)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x172b
jmp 0x1776
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x171c
movl $0x0, 0x1c(%rsp)
cmpl $0x4, 0x1c(%rsp)
jae 0x1880
movl $0x0, 0x18(%rsp)
cmpl $0x4, 0x18(%rsp)
jae 0x186e
movl 0x1c(%rsp), %eax
shll $0x2, %eax
addl 0x18(%rsp), %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x8819(%rip), %rax      # 0x9fd8
movzbl (%rax,%rcx), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movb %al, 0x17(%rsp)
movl 0x1c(%rsp), %eax
shll $0x2, %eax
addl 0x18(%rsp), %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x87f3(%rip), %rax      # 0x9fd8
movzbl (%rax,%rcx), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movb %dl, %al
movb %al, 0x16(%rsp)
movl $0x0, 0x10(%rsp)
cmpl $0x4, 0x10(%rsp)
jae 0x185c
movl 0x1c(%rsp), %eax
movl %eax, %ecx
leaq 0x40(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x18(%rsp), %ecx
shll $0x2, %ecx
addl 0x10(%rsp), %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movzbl 0x17(%rsp), %eax
movl %eax, %ecx
leaq 0x80(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movzbl 0x16(%rsp), %ecx
shll $0x2, %ecx
addl 0x10(%rsp), %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x17ff
jmp 0x185e
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x179e
jmp 0x1870
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x178b
jmp 0x1882
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x164d
movl $0x0, 0xc(%rsp)
cmpl $0x4, 0xc(%rsp)
jae 0x1900
movl $0x0, 0x8(%rsp)
cmpl $0x10, 0x8(%rsp)
jae 0x18f1
movl 0xc(%rsp), %eax
movl %eax, %ecx
leaq 0x80(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rsp), %ecx
movb (%rax,%rcx), %dl
movq 0xc8(%rsp), %rax
movl 0xc(%rsp), %ecx
shll $0x4, %ecx
addl 0x8(%rsp), %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x18a9
jmp 0x18f3
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x189a
addq $0xd8, %rsp
retq
nopl (%rax,%rax)