// File: /workspace/github_c_makefile_star2_O1/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 %rbx
movl (%rsi), %eax
bswapl %eax
movq %rax, (%rdi)
movl 0x4(%rsi), %eax
bswapl %eax
movq %rax, 0x8(%rdi)
movl 0x8(%rsi), %eax
bswapl %eax
movq %rax, 0x10(%rdi)
movl 0xc(%rsi), %eax
bswapl %eax
movq %rax, 0x18(%rdi)
cmpl $0x80, %edx
jne 0x2657
xorl %eax, %eax
leaq 0x5a5c(%rip), %rcx      # 0x8010
movl $0xff, %edx
leaq 0x6250(%rip), %rsi      # 0x8810
movq 0x18(%rdi,%rax,4), %r8
movl %r8d, %r9d
shrl $0xd, %r9d
andl $0x7f8, %r9d            # imm = 0x7F8
movzbl 0x3(%r9,%rcx), %r9d
shll $0x18, %r9d
xorq (%rdi,%rax,4), %r9
movl %r8d, %r10d
shrl $0x8, %r10d
andl %edx, %r10d
movzbl 0x2(%rcx,%r10,8), %r10d
shll $0x10, %r10d
movl %r8d, %r11d
andl %edx, %r11d
movzbl 0x1(%rcx,%r11,8), %r11d
shll $0x8, %r11d
xorq %r10, %r11
movq %r8, %r10
shrq $0x18, %r10
movzbl (%rcx,%r10,8), %r10d
xorq %r11, %r10
xorq %r9, %r10
xorq (%rax,%rsi), %r10
movq %r10, 0x20(%rdi,%rax,4)
xorq 0x8(%rdi,%rax,4), %r10
movq %r10, 0x28(%rdi,%rax,4)
xorq 0x10(%rdi,%rax,4), %r10
movq %r10, 0x30(%rdi,%rax,4)
xorq %r8, %r10
movq %r10, 0x38(%rdi,%rax,4)
addq $0x8, %rax
cmpq $0x50, %rax
jne 0x25c0
movl $0xa, %eax
jmp 0x2871
movl 0x10(%rsi), %eax
bswapl %eax
movq %rax, 0x20(%rdi)
movl 0x14(%rsi), %eax
bswapl %eax
movq %rax, 0x28(%rdi)
cmpl $0xc0, %edx
jne 0x272c
addq $0x58, %rdi
xorl %eax, %eax
leaq 0x598e(%rip), %rcx      # 0x8010
movl $0xff, %edx
leaq 0x6182(%rip), %rsi      # 0x8810
movq -0x30(%rdi), %r8
movl %r8d, %r9d
shrl $0xd, %r9d
andl $0x7f8, %r9d            # imm = 0x7F8
movzbl 0x3(%r9,%rcx), %r9d
shll $0x18, %r9d
xorq -0x58(%rdi), %r9
movl %r8d, %r10d
shrl $0x8, %r10d
andl %edx, %r10d
movzbl 0x2(%rcx,%r10,8), %r10d
shll $0x10, %r10d
movl %r8d, %r11d
andl %edx, %r11d
movzbl 0x1(%rcx,%r11,8), %r11d
shll $0x8, %r11d
xorq %r10, %r11
movq %r8, %r10
shrq $0x18, %r10
movzbl (%rcx,%r10,8), %r10d
xorq %r11, %r10
xorq %r9, %r10
xorq (%rax,%rsi), %r10
movq %r10, -0x28(%rdi)
xorq -0x50(%rdi), %r10
movq %r10, -0x20(%rdi)
xorq -0x48(%rdi), %r10
movq %r10, -0x18(%rdi)
xorq -0x40(%rdi), %r10
movq %r10, -0x10(%rdi)
cmpq $0x38, %rax
je 0x2865
xorq -0x38(%rdi), %r10
movq %r10, -0x8(%rdi)
xorq %r8, %r10
movq %r10, (%rdi)
addq $0x8, %rax
addq $0x30, %rdi
jmp 0x268e
movl 0x18(%rsi), %eax
bswapl %eax
movq %rax, 0x30(%rdi)
movl 0x1c(%rsi), %eax
bswapl %eax
movq %rax, 0x38(%rdi)
xorl %eax, %eax
cmpl $0x100, %edx            # imm = 0x100
jne 0x2871
xorl %eax, %eax
leaq 0x58bb(%rip), %rcx      # 0x8010
movl $0xff, %edx
leaq 0x60af(%rip), %rsi      # 0x8810
movq 0x38(%rdi,%rax,8), %r8
movl %r8d, %r9d
shrl $0xd, %r9d
andl $0x7f8, %r9d            # imm = 0x7F8
movzbl 0x3(%r9,%rcx), %r10d
shll $0x18, %r10d
xorq (%rdi,%rax,8), %r10
movl %r8d, %r9d
shrl $0x8, %r9d
andl %edx, %r9d
movzbl 0x2(%rcx,%r9,8), %r9d
shll $0x10, %r9d
movl %r8d, %r11d
andl %edx, %r11d
movzbl 0x1(%rcx,%r11,8), %r11d
shll $0x8, %r11d
xorq %r9, %r11
movq %r8, %r9
shrq $0x18, %r9
movzbl (%rcx,%r9,8), %r9d
xorq %r11, %r9
xorq %r10, %r9
xorq (%rax,%rsi), %r9
movq %r9, 0x40(%rdi,%rax,8)
xorq 0x8(%rdi,%rax,8), %r9
movq %r9, 0x48(%rdi,%rax,8)
xorq 0x10(%rdi,%rax,8), %r9
movq %r9, 0x50(%rdi,%rax,8)
xorq 0x18(%rdi,%rax,8), %r9
movq %r9, 0x58(%rdi,%rax,8)
cmpq $0x30, %rax
je 0x286c
movq %r9, %r10
shrq $0x18, %r10
movzbl 0x3(%rcx,%r10,8), %r10d
shll $0x18, %r10d
xorq 0x20(%rdi,%rax,8), %r10
movl %r9d, %r11d
shrl $0xd, %r11d
andl $0x7f8, %r11d           # imm = 0x7F8
movzbl 0x2(%r11,%rcx), %r11d
shll $0x10, %r11d
movl %r9d, %ebx
shrl $0x8, %ebx
andl %edx, %ebx
movzbl 0x1(%rcx,%rbx,8), %ebx
shll $0x8, %ebx
xorq %r11, %rbx
andl %edx, %r9d
movzbl (%rcx,%r9,8), %r9d
xorq %rbx, %r9
xorq %r10, %r9
movq %r9, 0x60(%rdi,%rax,8)
xorq 0x28(%rdi,%rax,8), %r9
movq %r9, 0x68(%rdi,%rax,8)
xorq 0x30(%rdi,%rax,8), %r9
movq %r9, 0x70(%rdi,%rax,8)
xorq %r8, %r9
movq %r9, 0x78(%rdi,%rax,8)
addq $0x8, %rax
jmp 0x2761
movl $0xc, %eax
jmp 0x2871
movl $0xe, %eax
popq %rbx
retq