// File: /workspace/github_c_makefile_star2_O2/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 %r13
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 0x2457
xorl %edx, %edx
leaq 0x5c5e(%rip), %rsi      # 0x8010
movl $0xff, %r8d
leaq 0x6451(%rip), %r9       # 0x8810
movl $0xa, %eax
movq 0x18(%rdi,%rdx,4), %r10
movl %r10d, %r11d
shrl $0xd, %r11d
andl $0x7f8, %r11d           # imm = 0x7F8
movzbl 0x3(%r11,%rsi), %r11d
shll $0x18, %r11d
xorq %rcx, %r11
movl %r10d, %ecx
shrl $0x8, %ecx
andl %r8d, %ecx
movzbl 0x2(%rsi,%rcx,8), %ecx
shll $0x10, %ecx
movl %r10d, %ebx
andl %r8d, %ebx
movzbl 0x1(%rsi,%rbx,8), %ebx
shll $0x8, %ebx
xorq %rcx, %rbx
xorq %r11, %rbx
movq %r10, %rcx
shrq $0x18, %rcx
movzbl (%rsi,%rcx,8), %ecx
xorq %rbx, %rcx
xorq (%rdx,%r9), %rcx
movq %rcx, 0x20(%rdi,%rdx,4)
movq 0x8(%rdi,%rdx,4), %r11
xorq %rcx, %r11
movq %r11, 0x28(%rdi,%rdx,4)
xorq 0x10(%rdi,%rdx,4), %r11
movq %r11, 0x30(%rdi,%rdx,4)
xorq %r10, %r11
movq %r11, 0x38(%rdi,%rdx,4)
addq $0x8, %rdx
cmpq $0x50, %rdx
jne 0x23c4
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movl 0x10(%rsi), %eax
bswapl %eax
movq %rax, 0x20(%rdi)
movl 0x14(%rsi), %r11d
bswapl %r11d
movq %r11, 0x28(%rdi)
cmpl $0xc0, %edx
jne 0x2529
addq $0x58, %rdi
xorl %edx, %edx
leaq 0x5b8c(%rip), %rsi      # 0x8010
movl $0xff, %ebx
leaq 0x6380(%rip), %r14      # 0x8810
movl $0xc, %eax
movl %r11d, %r15d
shrl $0xd, %r15d
andl $0x7f8, %r15d           # imm = 0x7F8
movzbl 0x3(%r15,%rsi), %r15d
shll $0x18, %r15d
xorq %rcx, %r15
movl %r11d, %ecx
shrl $0x8, %ecx
andl %ebx, %ecx
movzbl 0x2(%rsi,%rcx,8), %ecx
shll $0x10, %ecx
movl %r11d, %r12d
andl %ebx, %r12d
movzbl 0x1(%rsi,%r12,8), %r12d
shll $0x8, %r12d
xorq %rcx, %r12
xorq %r15, %r12
movq %r11, %rcx
shrq $0x18, %rcx
movzbl (%rsi,%rcx,8), %ecx
xorq %r12, %rcx
xorq (%rdx,%r14), %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 0x244d
movq -0x38(%rdi), %r15
xorq %r10, %r15
movq %r15, -0x8(%rdi)
xorq %r15, %r11
movq %r11, (%rdi)
addq $0x8, %rdx
addq $0x30, %rdi
jmp 0x2495
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 0x244d
xorl %edx, %edx
leaq 0x5abe(%rip), %r11      # 0x8010
movl $0xff, %ebx
leaq 0x62b2(%rip), %r14      # 0x8810
movl $0xe, %eax
movl %esi, %r15d
shrl $0xd, %r15d
andl $0x7f8, %r15d           # imm = 0x7F8
movzbl 0x3(%r15,%r11), %r15d
shll $0x18, %r15d
xorq %rcx, %r15
movl %esi, %ecx
shrl $0x8, %ecx
andl %ebx, %ecx
movzbl 0x2(%r11,%rcx,8), %ecx
shll $0x10, %ecx
movl %esi, %r12d
andl %ebx, %r12d
movzbl 0x1(%r11,%r12,8), %r12d
shll $0x8, %r12d
xorq %rcx, %r12
xorq %r15, %r12
movq %rsi, %rcx
shrq $0x18, %rcx
movzbl (%r11,%rcx,8), %ecx
xorq %r12, %rcx
xorq (%rdx,%r14), %rcx
movq %rcx, 0x40(%rdi,%rdx,8)
xorq %rcx, %r8
movq %r8, 0x48(%rdi,%rdx,8)
xorq %r8, %r9
movq %r9, 0x50(%rdi,%rdx,8)
xorq %r9, %r10
movq %r10, 0x58(%rdi,%rdx,8)
cmpq $0x30, %rdx
je 0x244d
movq %r10, %r15
shrq $0x18, %r15
movzbl 0x3(%r11,%r15,8), %r15d
shll $0x18, %r15d
xorq 0x20(%rdi,%rdx,8), %r15
movl %r10d, %r12d
shrl $0xd, %r12d
andl $0x7f8, %r12d           # imm = 0x7F8
movzbl 0x2(%r12,%r11), %r12d
shll $0x10, %r12d
movl %r10d, %r13d
shrl $0x8, %r13d
andl %ebx, %r13d
movzbl 0x1(%r11,%r13,8), %r13d
shll $0x8, %r13d
xorq %r12, %r13
movl %r10d, %r12d
andl %ebx, %r12d
movzbl (%r11,%r12,8), %r12d
xorq %r13, %r12
xorq %r15, %r12
movq %r12, 0x60(%rdi,%rdx,8)
xorq 0x28(%rdi,%rdx,8), %r12
movq %r12, 0x68(%rdi,%rdx,8)
xorq 0x30(%rdi,%rdx,8), %r12
movq %r12, 0x70(%rdi,%rdx,8)
xorq %r12, %rsi
movq %rsi, 0x78(%rdi,%rdx,8)
addq $0x8, %rdx
jmp 0x2563