// File: FFY00[P]uicc/include/aes.h
// Function: RijndaelKeySchedule(unsigned char const*, unsigned char (*) [4][4])
static inline void RijndaelKeySchedule (const uint8_t key[16], uint8_t roundKeys[11][4][4]) {
  //first round key equals key
  for (int i = 0; i < 16; i++)
    roundKeys[0][i & 0x03][i >> 2] = key[i];

  //now calculate round keys
  uint8_t roundConst = 1;

  for (int i = 0; i < 10; i++) {
    int next=i+1;
    roundKeys[next][0][0] = S[roundKeys[i][1][3]]
                            ^ roundKeys[i][0][0] ^ roundConst;
    roundKeys[next][1][0] = S[roundKeys[i][2][3]]
                            ^ roundKeys[i][1][0];
    roundKeys[next][2][0] = S[roundKeys[i][3][3]]
                            ^ roundKeys[i][2][0];
    roundKeys[next][3][0] = S[roundKeys[i][0][3]]
                            ^ roundKeys[i][3][0];

    for (int j = 0; j < 4; j++) {
      roundKeys[next][j][1] = roundKeys[i][j][1] ^ roundKeys[next][j][0];
      roundKeys[next][j][2] = roundKeys[i][j][2] ^ roundKeys[next][j][1];
      roundKeys[next][j][3] = roundKeys[i][j][3] ^ roundKeys[next][j][2];
    }

    roundConst = Xtime[roundConst];
  }

  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x10, -0x14(%rbp)
jge 0xdb5f
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
andl $0x3, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movl -0x14(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xdb23
movb $0x1, -0x15(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xa, -0x1c(%rbp)
jge 0xddc5
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzbl 0x7(%rax), %eax
movl %eax, %ecx
leaq 0x154c7(%rip), %rax     # 0x23060
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movzbl (%rcx), %ecx
xorl %ecx, %eax
movzbl -0x15(%rbp), %ecx
xorl %ecx, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzbl 0xb(%rax), %eax
movl %eax, %ecx
leaq 0x1547a(%rip), %rax     # 0x23060
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movzbl 0x4(%rcx), %ecx
xorl %ecx, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movb %cl, 0x4(%rax)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzbl 0xf(%rax), %eax
movl %eax, %ecx
leaq 0x15431(%rip), %rax     # 0x23060
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movzbl 0x8(%rcx), %ecx
xorl %ecx, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movb %cl, 0x8(%rax)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movzbl 0x3(%rax), %eax
movl %eax, %ecx
leaq 0x153e8(%rip), %rax     # 0x23060
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movzbl 0xc(%rcx), %ecx
xorl %ecx, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movb %cl, 0xc(%rax)
movl $0x0, -0x24(%rbp)
cmpl $0x4, -0x24(%rbp)
jge 0xdda4
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x24(%rbp), %rcx
movzbl 0x1(%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movslq -0x24(%rbp), %rdx
movzbl (%rcx,%rdx,4), %ecx
xorl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x24(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx,4)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x24(%rbp), %rcx
movzbl 0x2(%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movslq -0x24(%rbp), %rdx
movzbl 0x1(%rcx,%rdx,4), %ecx
xorl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x24(%rbp), %rcx
movb %dl, 0x2(%rax,%rcx,4)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x24(%rbp), %rcx
movzbl 0x3(%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movslq -0x24(%rbp), %rdx
movzbl 0x2(%rcx,%rdx,4), %ecx
xorl %ecx, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x24(%rbp), %rcx
movb %dl, 0x3(%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xdcac
movzbl -0x15(%rbp), %eax
movl %eax, %ecx
leaq 0x153af(%rip), %rax     # 0x23160
movb (%rax,%rcx), %al
movb %al, -0x15(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xdb6a
popq %rbp
retq
nopw (%rax,%rax)