// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/paeq160/ref/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;
					//printf("Constant for acc%d: %d\n",r,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 0x1625
movl $0x0, 0x38(%rsp)
cmpl $0x10, 0x38(%rsp)
jae 0x1616
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 0x15ce
jmp 0x1618
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x15bf
movl $0x0, 0x34(%rsp)
cmpl $0xa, 0x34(%rsp)
jae 0x1872
movl $0x0, 0x30(%rsp)
cmpl $0x4, 0x30(%rsp)
jae 0x16f4
movl $0x0, 0x2c(%rsp)
cmpl $0x2, 0x2c(%rsp)
jae 0x16e2
movl 0x30(%rsp), %eax
leaq 0x80(%rsp), %rdi
shlq $0x4, %rax
addq %rax, %rdi
callq 0x10b0
movl $0x0, 0x28(%rsp)
cmpl $0x4, 0x28(%rsp)
jae 0x16d0
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 0x167e
jmp 0x16d2
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x1653
jmp 0x16e4
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x1640
movl $0x0, 0x24(%rsp)
cmpl $0x4, 0x24(%rsp)
jae 0x1763
movl $0x0, 0x20(%rsp)
cmpl $0x10, 0x20(%rsp)
jae 0x1754
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 0x170b
jmp 0x1756
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x16fc
movl $0x0, 0x1c(%rsp)
cmpl $0x4, 0x1c(%rsp)
jae 0x1860
movl $0x0, 0x18(%rsp)
cmpl $0x4, 0x18(%rsp)
jae 0x184e
movl 0x1c(%rsp), %eax
shll $0x2, %eax
addl 0x18(%rsp), %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x4839(%rip), %rax      # 0x5fd8
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 0x4813(%rip), %rax      # 0x5fd8
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 0x183c
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 0x17df
jmp 0x183e
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x177e
jmp 0x1850
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x176b
jmp 0x1862
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x162d
movl $0x0, 0xc(%rsp)
cmpl $0x4, 0xc(%rsp)
jae 0x18e0
movl $0x0, 0x8(%rsp)
cmpl $0x10, 0x8(%rsp)
jae 0x18d1
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 0x1889
jmp 0x18d3
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x187a
addq $0xd8, %rsp
retq
nopl (%rax,%rax)