// File: /workspace/github_c_makefile_star2_O3/MartinDrab[P]netpipe/aes.c
// Function: rijndaelSetupEncrypt
int rijndaelSetupEncrypt(u32 *rk, const u8 *key, int keybits)
{
  int i = 0;
  u32 temp;

  rk[0] = GETU32(key     );
  rk[1] = GETU32(key +  4);
  rk[2] = GETU32(key +  8);
  rk[3] = GETU32(key + 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(key + 16);
  rk[5] = GETU32(key + 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(key + 24);
  rk[7] = GETU32(key + 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 %r15
pushq %r14
pushq %r12
pushq %rbx
movl (%rsi), %ecx
bswapl %ecx
movq %rcx, (%rdi)
movl 0x4(%rsi), %r8d
bswapl %r8d
movq %r8, 0x8(%rdi)
movl 0x8(%rsi), %r9d
bswapl %r9d
movq %r9, 0x10(%rdi)
movl 0xc(%rsi), %r10d
bswapl %r10d
movq %r10, 0x18(%rdi)
cmpl $0x80, %edx
jne 0x2670
xorl %eax, %eax
leaq 0x5a40(%rip), %rdx      # 0x8010
movl $0xff, %esi
leaq 0x6234(%rip), %r8       # 0x8810
movq 0x18(%rdi,%rax,4), %r9
movl %r9d, %r10d
shrl $0xd, %r10d
andl $0x7f8, %r10d           # imm = 0x7F8
movzbl 0x3(%r10,%rdx), %r10d
shll $0x18, %r10d
xorq %rcx, %r10
movl %r9d, %ecx
shrl $0x8, %ecx
andl %esi, %ecx
movzbl 0x2(%rdx,%rcx,8), %ecx
shll $0x10, %ecx
movl %r9d, %r11d
andl %esi, %r11d
movzbl 0x1(%rdx,%r11,8), %r11d
shll $0x8, %r11d
xorq %rcx, %r11
xorq %r10, %r11
movq %r9, %rcx
shrq $0x18, %rcx
movzbl (%rdx,%rcx,8), %ecx
xorq %r11, %rcx
xorq (%rax,%r8), %rcx
movq %rcx, 0x20(%rdi,%rax,4)
movq 0x8(%rdi,%rax,4), %r10
xorq %rcx, %r10
movq %r10, 0x28(%rdi,%rax,4)
xorq 0x10(%rdi,%rax,4), %r10
movq %r10, 0x30(%rdi,%rax,4)
xorq %r9, %r10
movq %r10, 0x38(%rdi,%rax,4)
addq $0x8, %rax
cmpq $0x50, %rax
jne 0x25dc
movl $0xa, %eax
jmp 0x2878
movl 0x10(%rsi), %eax
bswapl %eax
movq %rax, 0x20(%rdi)
movl 0x14(%rsi), %eax
bswapl %eax
movq %rax, 0x28(%rdi)
cmpl $0xc0, %edx
jne 0x273c
addq $0x58, %rdi
xorl %edx, %edx
leaq 0x5975(%rip), %rsi      # 0x8010
movl $0xff, %r11d
leaq 0x6168(%rip), %rbx      # 0x8810
movl %eax, %r14d
shrl $0xd, %r14d
andl $0x7f8, %r14d           # imm = 0x7F8
movzbl 0x3(%r14,%rsi), %r14d
shll $0x18, %r14d
xorq %rcx, %r14
movl %eax, %ecx
shrl $0x8, %ecx
andl %r11d, %ecx
movzbl 0x2(%rsi,%rcx,8), %ecx
shll $0x10, %ecx
movl %eax, %r15d
andl %r11d, %r15d
movzbl 0x1(%rsi,%r15,8), %r15d
shll $0x8, %r15d
xorq %rcx, %r15
xorq %r14, %r15
movq %rax, %rcx
shrq $0x18, %rcx
movzbl (%rsi,%rcx,8), %ecx
xorq %r15, %rcx
xorq (%rdx,%rbx), %rcx
movq %rcx, -0x28(%rdi)
xorq %rcx, %r8
movq %r8, -0x20(%rdi)
xorq %r8, %r9
movq %r9, -0x18(%rdi)
xorq %r9, %r10
movq %r10, -0x10(%rdi)
cmpq $0x38, %rdx
je 0x286c
movq -0x38(%rdi), %r14
xorq %r10, %r14
movq %r14, -0x8(%rdi)
xorq %r14, %rax
movq %rax, (%rdi)
addq $0x8, %rdx
addq $0x30, %rdi
jmp 0x26a8
movl 0x18(%rsi), %eax
bswapl %eax
movq %rax, 0x30(%rdi)
movl 0x1c(%rsi), %esi
bswapl %esi
movq %rsi, 0x38(%rdi)
xorl %eax, %eax
cmpl $0x100, %edx            # imm = 0x100
jne 0x2878
xorl %eax, %eax
leaq 0x58ab(%rip), %rdx      # 0x8010
movl $0xff, %r11d
leaq 0x609e(%rip), %rbx      # 0x8810
movl %esi, %r14d
shrl $0xd, %r14d
andl $0x7f8, %r14d           # imm = 0x7F8
movzbl 0x3(%r14,%rdx), %r14d
shll $0x18, %r14d
xorq %rcx, %r14
movl %esi, %ecx
shrl $0x8, %ecx
andl %r11d, %ecx
movzbl 0x2(%rdx,%rcx,8), %ecx
shll $0x10, %ecx
movl %esi, %r15d
andl %r11d, %r15d
movzbl 0x1(%rdx,%r15,8), %r15d
shll $0x8, %r15d
xorq %rcx, %r15
xorq %r14, %r15
movq %rsi, %rcx
shrq $0x18, %rcx
movzbl (%rdx,%rcx,8), %ecx
xorq %r15, %rcx
xorq (%rax,%rbx), %rcx
movq %rcx, 0x40(%rdi,%rax,8)
xorq %rcx, %r8
movq %r8, 0x48(%rdi,%rax,8)
xorq %r8, %r9
movq %r9, 0x50(%rdi,%rax,8)
xorq %r9, %r10
movq %r10, 0x58(%rdi,%rax,8)
cmpq $0x30, %rax
je 0x2873
movq %r10, %r14
shrq $0x18, %r14
movzbl 0x3(%rdx,%r14,8), %r14d
shll $0x18, %r14d
xorq 0x20(%rdi,%rax,8), %r14
movl %r10d, %r15d
shrl $0xd, %r15d
andl $0x7f8, %r15d           # imm = 0x7F8
movzbl 0x2(%r15,%rdx), %r15d
shll $0x10, %r15d
movl %r10d, %r12d
shrl $0x8, %r12d
andl %r11d, %r12d
movzbl 0x1(%rdx,%r12,8), %r12d
shll $0x8, %r12d
xorq %r15, %r12
movl %r10d, %r15d
andl %r11d, %r15d
movzbl (%rdx,%r15,8), %r15d
xorq %r12, %r15
xorq %r14, %r15
movq %r15, 0x60(%rdi,%rax,8)
xorq 0x28(%rdi,%rax,8), %r15
movq %r15, 0x68(%rdi,%rax,8)
xorq 0x30(%rdi,%rax,8), %r15
movq %r15, 0x70(%rdi,%rax,8)
xorq %r15, %rsi
movq %rsi, 0x78(%rdi,%rax,8)
addq $0x8, %rax
jmp 0x2772
movl $0xc, %eax
jmp 0x2878
movl $0xe, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
retq