// File: /workspace/github_c_makefile_star2_O0/opencoff[P]crypto-rand/aes.c
// Function: KeyExpansion
static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key)
{
  unsigned i, j, k;
  uint8_t tempa[4]; // Used for the column/row operations
  
  // The first round key is the key itself.
  for (i = 0; i < Nk; ++i)
  {
    RoundKey[(i * 4) + 0] = Key[(i * 4) + 0];
    RoundKey[(i * 4) + 1] = Key[(i * 4) + 1];
    RoundKey[(i * 4) + 2] = Key[(i * 4) + 2];
    RoundKey[(i * 4) + 3] = Key[(i * 4) + 3];
  }

  // All other round keys are found from the previous round keys.
  for (i = Nk; i < Nb * (Nr + 1); ++i)
  {
    {
      k = (i - 1) * 4;
      tempa[0]=RoundKey[k + 0];
      tempa[1]=RoundKey[k + 1];
      tempa[2]=RoundKey[k + 2];
      tempa[3]=RoundKey[k + 3];

    }

    if (i % Nk == 0)
    {
      // This function shifts the 4 bytes in a word to the left once.
      // [a0,a1,a2,a3] becomes [a1,a2,a3,a0]

      // Function RotWord()
      {
        const uint8_t u8tmp = tempa[0];
        tempa[0] = tempa[1];
        tempa[1] = tempa[2];
        tempa[2] = tempa[3];
        tempa[3] = u8tmp;
      }

      // SubWord() is a function that takes a four-byte input word and 
      // applies the S-box to each of the four bytes to produce an output word.

      // Function Subword()
      {
        tempa[0] = getSBoxValue(tempa[0]);
        tempa[1] = getSBoxValue(tempa[1]);
        tempa[2] = getSBoxValue(tempa[2]);
        tempa[3] = getSBoxValue(tempa[3]);
      }

      tempa[0] = tempa[0] ^ Rcon[i/Nk];
    }
#if defined(AES256) && (AES256 == 1)
    if (i % Nk == 4)
    {
      // Function Subword()
      {
        tempa[0] = getSBoxValue(tempa[0]);
        tempa[1] = getSBoxValue(tempa[1]);
        tempa[2] = getSBoxValue(tempa[2]);
        tempa[3] = getSBoxValue(tempa[3]);
      }
    }
#endif
    j = i * 4; k=(i - Nk) * 4;
    RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0];
    RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1];
    RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2];
    RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3];
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x8, -0x14(%rbp)
jae 0x315b
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
shll $0x2, %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x30b3
movl $0x8, -0x14(%rbp)
cmpl $0x3c, -0x14(%rbp)
jae 0x336d
movl -0x14(%rbp), %eax
subl $0x1, %eax
shll $0x2, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1f(%rbp)
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1e(%rbp)
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x1d(%rbp)
movl -0x14(%rbp), %eax
andl $0x7, %eax
cmpl $0x0, %eax
jne 0x3257
movb -0x20(%rbp), %al
movb %al, -0x21(%rbp)
movb -0x1f(%rbp), %al
movb %al, -0x20(%rbp)
movb -0x1e(%rbp), %al
movb %al, -0x1f(%rbp)
movb -0x1d(%rbp), %al
movb %al, -0x1e(%rbp)
movb -0x21(%rbp), %al
movb %al, -0x1d(%rbp)
movzbl -0x20(%rbp), %eax
movl %eax, %ecx
leaq 0xf16(%rip), %rax       # 0x4110
movb (%rax,%rcx), %al
movb %al, -0x20(%rbp)
movzbl -0x1f(%rbp), %eax
movl %eax, %ecx
leaq 0xf03(%rip), %rax       # 0x4110
movb (%rax,%rcx), %al
movb %al, -0x1f(%rbp)
movzbl -0x1e(%rbp), %eax
movl %eax, %ecx
leaq 0xef0(%rip), %rax       # 0x4110
movb (%rax,%rcx), %al
movb %al, -0x1e(%rbp)
movzbl -0x1d(%rbp), %eax
movl %eax, %ecx
leaq 0xedd(%rip), %rax       # 0x4110
movb (%rax,%rcx), %al
movb %al, -0x1d(%rbp)
movzbl -0x20(%rbp), %eax
movl -0x14(%rbp), %ecx
shrl $0x3, %ecx
movl %ecx, %ecx
movl %ecx, %edx
leaq 0xfc2(%rip), %rcx       # 0x4210
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x20(%rbp)
movl -0x14(%rbp), %eax
andl $0x7, %eax
cmpl $0x4, %eax
jne 0x32ae
movzbl -0x20(%rbp), %eax
movl %eax, %ecx
leaq 0xea1(%rip), %rax       # 0x4110
movb (%rax,%rcx), %al
movb %al, -0x20(%rbp)
movzbl -0x1f(%rbp), %eax
movl %eax, %ecx
leaq 0xe8e(%rip), %rax       # 0x4110
movb (%rax,%rcx), %al
movb %al, -0x1f(%rbp)
movzbl -0x1e(%rbp), %eax
movl %eax, %ecx
leaq 0xe7b(%rip), %rax       # 0x4110
movb (%rax,%rcx), %al
movb %al, -0x1e(%rbp)
movzbl -0x1d(%rbp), %eax
movl %eax, %ecx
leaq 0xe68(%rip), %rax       # 0x4110
movb (%rax,%rcx), %al
movb %al, -0x1d(%rbp)
movl -0x14(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
subl $0x8, %eax
shll $0x2, %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movzbl -0x20(%rbp), %ecx
xorl %ecx, %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movzbl -0x1f(%rbp), %ecx
xorl %ecx, %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movzbl -0x1e(%rbp), %ecx
xorl %ecx, %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movzbl -0x1d(%rbp), %ecx
xorl %ecx, %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x3162
popq %rbp
retq
nop