// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/aezv3/ref/rijndael-alg-fst.c
// Function: rijndaelKeySetupEnc
int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits) {
   	int i = 0;
	u32 temp;

	rk[0] = GETU32(cipherKey     );
	rk[1] = GETU32(cipherKey +  4);
	rk[2] = GETU32(cipherKey +  8);
	rk[3] = GETU32(cipherKey + 12);
	if (keyBits == 128) {
		for (;;) {
			temp  = rk[3];
			rk[4] = rk[0] ^
				(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
				(Te4[(temp >>  8) & 0xff] & 0x00ff0000) ^
				(Te4[(temp      ) & 0xff] & 0x0000ff00) ^
				(Te4[(temp >> 24)       ] & 0x000000ff) ^
				rcon[i];
			rk[5] = rk[1] ^ rk[4];
			rk[6] = rk[2] ^ rk[5];
			rk[7] = rk[3] ^ rk[6];
			if (++i == 10) {
				return 10;
			}
			rk += 4;
		}
	}
	rk[4] = GETU32(cipherKey + 16);
	rk[5] = GETU32(cipherKey + 20);
	if (keyBits == 192) {
		for (;;) {
			temp = rk[ 5];
			rk[ 6] = rk[ 0] ^
				(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
				(Te4[(temp >>  8) & 0xff] & 0x00ff0000) ^
				(Te4[(temp      ) & 0xff] & 0x0000ff00) ^
				(Te4[(temp >> 24)       ] & 0x000000ff) ^
				rcon[i];
			rk[ 7] = rk[ 1] ^ rk[ 6];
			rk[ 8] = rk[ 2] ^ rk[ 7];
			rk[ 9] = rk[ 3] ^ rk[ 8];
			if (++i == 8) {
				return 12;
			}
			rk[10] = rk[ 4] ^ rk[ 9];
			rk[11] = rk[ 5] ^ rk[10];
			rk += 6;
		}
	}
	rk[6] = GETU32(cipherKey + 24);
	rk[7] = GETU32(cipherKey + 28);
	if (keyBits == 256) {
        for (;;) {
        	temp = rk[ 7];
        	rk[ 8] = rk[ 0] ^
        		(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
        		(Te4[(temp >>  8) & 0xff] & 0x00ff0000) ^
        		(Te4[(temp      ) & 0xff] & 0x0000ff00) ^
        		(Te4[(temp >> 24)       ] & 0x000000ff) ^
        		rcon[i];
        	rk[ 9] = rk[ 1] ^ rk[ 8];
        	rk[10] = rk[ 2] ^ rk[ 9];
        	rk[11] = rk[ 3] ^ rk[10];
			if (++i == 7) {
				return 14;
			}
        	temp = rk[11];
        	rk[12] = rk[ 4] ^
        		(Te4[(temp >> 24)       ] & 0xff000000) ^
        		(Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
        		(Te4[(temp >>  8) & 0xff] & 0x0000ff00) ^
        		(Te4[(temp      ) & 0xff] & 0x000000ff);
        	rk[13] = rk[ 5] ^ rk[12];
        	rk[14] = rk[ 6] ^ rk[13];
        	rk[15] = rk[ 7] ^ rk[14];

			rk += 8;
        }
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl (%rsi), %ecx
movbel %ecx, (%rdi)
movl 0x4(%rsi), %r8d
movbel %r8d, 0x4(%rdi)
movl 0x8(%rsi), %r9d
movbel %r9d, 0x8(%rdi)
bswapl %ecx
movl 0xc(%rsi), %r10d
movbel %r10d, 0xc(%rdi)
cmpl $0x80, %edx
jne 0x29c7
xorl %edx, %edx
leaq 0x1779(%rip), %rsi      # 0x40a0
movl $0xff, %r8d
leaq 0x1b6c(%rip), %r9       # 0x44a0
movl $0xa, %eax
movl 0xc(%rdi,%rdx,4), %r10d
movl %r10d, %r11d
shrl $0xe, %r11d
andl $0x3fc, %r11d           # imm = 0x3FC
movzbl 0x3(%r11,%rsi), %r11d
shll $0x18, %r11d
xorl %ecx, %r11d
movl %r10d, %ecx
shrl $0x8, %ecx
andl %r8d, %ecx
movzbl 0x2(%rsi,%rcx,4), %ecx
shll $0x10, %ecx
movl %r10d, %ebx
andl %r8d, %ebx
movzbl 0x1(%rsi,%rbx,4), %ebx
shll $0x8, %ebx
xorl %ecx, %ebx
xorl %r11d, %ebx
movl %r10d, %ecx
shrl $0x18, %ecx
movzbl (%rsi,%rcx,4), %ecx
xorl %ebx, %ecx
xorl (%rdx,%r9), %ecx
movl %ecx, 0x10(%rdi,%rdx,4)
movl 0x4(%rdi,%rdx,4), %r11d
xorl %ecx, %r11d
movl %r11d, 0x14(%rdi,%rdx,4)
xorl 0x8(%rdi,%rdx,4), %r11d
movl %r11d, 0x18(%rdi,%rdx,4)
xorl %r10d, %r11d
movl %r11d, 0x1c(%rdi,%rdx,4)
addq $0x4, %rdx
cmpq $0x28, %rdx
jne 0x2939
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
bswapl %r8d
bswapl %r9d
movl 0x10(%rsi), %eax
movbel %eax, 0x10(%rdi)
bswapl %r10d
movl 0x14(%rsi), %r11d
movbel %r11d, 0x14(%rdi)
cmpl $0xc0, %edx
jne 0x2a9d
bswapl %r11d
addq $0x2c, %rdi
xorl %edx, %edx
leaq 0x16a2(%rip), %rsi      # 0x40a0
movl $0xff, %ebx
leaq 0x1a96(%rip), %r14      # 0x44a0
movl $0xc, %eax
movl %r11d, %r15d
shrl $0xe, %r15d
andl $0x3fc, %r15d           # imm = 0x3FC
movzbl 0x3(%r15,%rsi), %ebp
shll $0x18, %ebp
xorl %ecx, %ebp
movl %r11d, %ecx
shrl $0x8, %ecx
andl %ebx, %ecx
movzbl 0x2(%rsi,%rcx,4), %ecx
shll $0x10, %ecx
movl %r11d, %r15d
andl %ebx, %r15d
movzbl 0x1(%rsi,%r15,4), %r15d
shll $0x8, %r15d
xorl %ecx, %r15d
xorl %ebp, %r15d
movl %r11d, %ecx
shrl $0x18, %ecx
movzbl (%rsi,%rcx,4), %ecx
xorl %r15d, %ecx
xorl (%rdx,%r14), %ecx
movl %ecx, -0x14(%rdi)
xorl %ecx, %r8d
movl %r8d, -0x10(%rdi)
xorl %r8d, %r9d
movl %r9d, -0xc(%rdi)
xorl %r9d, %r10d
movl %r10d, -0x8(%rdi)
cmpq $0x1c, %rdx
je 0x29be
movl -0x1c(%rdi), %ebp
xorl %r10d, %ebp
movl %ebp, -0x4(%rdi)
xorl %ebp, %r11d
movl %r11d, (%rdi)
addq $0x4, %rdx
addq $0x18, %rdi
jmp 0x2a0f
movl 0x18(%rsi), %eax
movbel %eax, 0x18(%rdi)
movl 0x1c(%rsi), %esi
movbel %esi, 0x1c(%rdi)
xorl %eax, %eax
cmpl $0x100, %edx            # imm = 0x100
jne 0x29be
bswapl %esi
xorl %edx, %edx
leaq 0x15da(%rip), %r11      # 0x40a0
movl $0xff, %ebx
leaq 0x19ce(%rip), %r14      # 0x44a0
movl $0xe, %eax
movl %esi, %r15d
shrl $0xe, %r15d
andl $0x3fc, %r15d           # imm = 0x3FC
movzbl 0x3(%r15,%r11), %ebp
shll $0x18, %ebp
xorl %ecx, %ebp
movl %esi, %ecx
shrl $0x8, %ecx
andl %ebx, %ecx
movzbl 0x2(%r11,%rcx,4), %ecx
shll $0x10, %ecx
movl %esi, %r15d
andl %ebx, %r15d
movzbl 0x1(%r11,%r15,4), %r15d
shll $0x8, %r15d
xorl %ecx, %r15d
xorl %ebp, %r15d
movl %esi, %ecx
shrl $0x18, %ecx
movzbl (%r11,%rcx,4), %ecx
xorl %r15d, %ecx
xorl (%rdx,%r14), %ecx
movl %ecx, 0x20(%rdi,%rdx,8)
xorl %ecx, %r8d
movl %r8d, 0x24(%rdi,%rdx,8)
xorl %r8d, %r9d
movl %r9d, 0x28(%rdi,%rdx,8)
xorl %r9d, %r10d
movl %r10d, 0x2c(%rdi,%rdx,8)
cmpq $0x18, %rdx
je 0x29be
movl %r10d, %r15d
shrl $0x18, %r15d
movzbl 0x3(%r11,%r15,4), %ebp
shll $0x18, %ebp
xorl 0x10(%rdi,%rdx,8), %ebp
movl %r10d, %r15d
shrl $0xe, %r15d
andl $0x3fc, %r15d           # imm = 0x3FC
movzbl 0x2(%r15,%r11), %r15d
shll $0x10, %r15d
movl %r10d, %r12d
shrl $0x8, %r12d
andl %ebx, %r12d
movzbl 0x1(%r11,%r12,4), %r12d
shll $0x8, %r12d
xorl %r15d, %r12d
movl %r10d, %r15d
andl %ebx, %r15d
movzbl (%r11,%r15,4), %r15d
xorl %r12d, %r15d
xorl %ebp, %r15d
movl %r15d, 0x30(%rdi,%rdx,8)
xorl 0x14(%rdi,%rdx,8), %r15d
movl %r15d, 0x34(%rdi,%rdx,8)
xorl 0x18(%rdi,%rdx,8), %r15d
movl %r15d, 0x38(%rdi,%rdx,8)
xorl %r15d, %esi
movl %esi, 0x3c(%rdi,%rdx,8)
addq $0x4, %rdx
jmp 0x2ad7