// File: /workspace/github_c_makefile_star2_O3/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 %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 0x2d33
xorl %eax, %eax
leaq 0x262b(%rip), %rdx      # 0x52c0
movl $0xff, %esi
leaq 0x2a1f(%rip), %r8       # 0x56c0
movl 0xc(%rdi,%rax,4), %r9d
movl %r9d, %r10d
shrl $0xe, %r10d
andl $0x3fc, %r10d           # imm = 0x3FC
movzbl 0x3(%r10,%rdx), %r10d
shll $0x18, %r10d
xorl %ecx, %r10d
movl %r9d, %ecx
shrl $0x8, %ecx
andl %esi, %ecx
movzbl 0x2(%rdx,%rcx,4), %ecx
shll $0x10, %ecx
movl %r9d, %r11d
andl %esi, %r11d
movzbl 0x1(%rdx,%r11,4), %r11d
shll $0x8, %r11d
xorl %ecx, %r11d
xorl %r10d, %r11d
movl %r9d, %ecx
shrl $0x18, %ecx
movzbl (%rdx,%rcx,4), %ecx
xorl %r11d, %ecx
xorl (%rax,%r8), %ecx
movl %ecx, 0x10(%rdi,%rax,4)
movl 0x4(%rdi,%rax,4), %r10d
xorl %ecx, %r10d
movl %r10d, 0x14(%rdi,%rax,4)
xorl 0x8(%rdi,%rax,4), %r10d
movl %r10d, 0x18(%rdi,%rax,4)
xorl %r9d, %r10d
movl %r10d, 0x1c(%rdi,%rax,4)
addq $0x4, %rax
cmpq $0x28, %rax
jne 0x2ca1
movl $0xa, %eax
jmp 0x2f31
bswapl %r8d
bswapl %r9d
movl 0x10(%rsi), %eax
movbel %eax, 0x10(%rdi)
bswapl %r10d
movl 0x14(%rsi), %eax
movbel %eax, 0x14(%rdi)
cmpl $0xc0, %edx
jne 0x2dfe
bswapl %eax
addq $0x2c, %rdi
xorl %edx, %edx
leaq 0x2559(%rip), %rsi      # 0x52c0
movl $0xff, %r11d
leaq 0x294c(%rip), %rbx      # 0x56c0
movl %eax, %r14d
shrl $0xe, %r14d
andl $0x3fc, %r14d           # imm = 0x3FC
movzbl 0x3(%r14,%rsi), %ebp
shll $0x18, %ebp
xorl %ecx, %ebp
movl %eax, %ecx
shrl $0x8, %ecx
andl %r11d, %ecx
movzbl 0x2(%rsi,%rcx,4), %ecx
shll $0x10, %ecx
movl %eax, %r14d
andl %r11d, %r14d
movzbl 0x1(%rsi,%r14,4), %r14d
shll $0x8, %r14d
xorl %ecx, %r14d
xorl %ebp, %r14d
movl %eax, %ecx
shrl $0x18, %ecx
movzbl (%rsi,%rcx,4), %ecx
xorl %r14d, %ecx
xorl (%rdx,%rbx), %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 0x2f25
movl -0x1c(%rdi), %ebp
xorl %r10d, %ebp
movl %ebp, -0x4(%rdi)
xorl %ebp, %eax
movl %eax, (%rdi)
addq $0x4, %rdx
addq $0x18, %rdi
jmp 0x2d74
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 0x2f31
bswapl %esi
xorl %eax, %eax
leaq 0x2499(%rip), %rdx      # 0x52c0
movl $0xff, %r11d
leaq 0x288c(%rip), %rbx      # 0x56c0
movl %esi, %r14d
shrl $0xe, %r14d
andl $0x3fc, %r14d           # imm = 0x3FC
movzbl 0x3(%r14,%rdx), %ebp
shll $0x18, %ebp
xorl %ecx, %ebp
movl %esi, %ecx
shrl $0x8, %ecx
andl %r11d, %ecx
movzbl 0x2(%rdx,%rcx,4), %ecx
shll $0x10, %ecx
movl %esi, %r14d
andl %r11d, %r14d
movzbl 0x1(%rdx,%r14,4), %r14d
shll $0x8, %r14d
xorl %ecx, %r14d
xorl %ebp, %r14d
movl %esi, %ecx
shrl $0x18, %ecx
movzbl (%rdx,%rcx,4), %ecx
xorl %r14d, %ecx
xorl (%rax,%rbx), %ecx
movl %ecx, 0x20(%rdi,%rax,8)
xorl %ecx, %r8d
movl %r8d, 0x24(%rdi,%rax,8)
xorl %r8d, %r9d
movl %r9d, 0x28(%rdi,%rax,8)
xorl %r9d, %r10d
movl %r10d, 0x2c(%rdi,%rax,8)
cmpq $0x18, %rax
je 0x2f2c
movl %r10d, %r14d
shrl $0x18, %r14d
movzbl 0x3(%rdx,%r14,4), %ebp
shll $0x18, %ebp
xorl 0x10(%rdi,%rax,8), %ebp
movl %r10d, %r14d
shrl $0xe, %r14d
andl $0x3fc, %r14d           # imm = 0x3FC
movzbl 0x2(%r14,%rdx), %r14d
shll $0x10, %r14d
movl %r10d, %r15d
shrl $0x8, %r15d
andl %r11d, %r15d
movzbl 0x1(%rdx,%r15,4), %r15d
shll $0x8, %r15d
xorl %r14d, %r15d
movl %r10d, %r14d
andl %r11d, %r14d
movzbl (%rdx,%r14,4), %r14d
xorl %r15d, %r14d
xorl %ebp, %r14d
movl %r14d, 0x30(%rdi,%rax,8)
xorl 0x14(%rdi,%rax,8), %r14d
movl %r14d, 0x34(%rdi,%rax,8)
xorl 0x18(%rdi,%rax,8), %r14d
movl %r14d, 0x38(%rdi,%rax,8)
xorl %r14d, %esi
movl %esi, 0x3c(%rdi,%rax,8)
addq $0x4, %rax
jmp 0x2e34
movl $0xc, %eax
jmp 0x2f31
movl $0xe, %eax
popq %rbx
popq %r14
popq %r15
popq %rbp
retq