// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aes128poetv1aes4/ref/aes.c
// Function: AES_set_encrypt_key
int AES_set_encrypt_key (const unsigned char *userKey, const int bits,
                         AES_KEY *key)
{

    u32 *rk;
    int i = 0;
    u32 temp;

    if (!userKey || !key) {
        return -1;
    }
    if (bits != 128 && bits != 192 && bits != 256) {
        return -2;
    }

    rk = key->rd_key;

    if (bits == 128) {
        key->rounds = 10;
    } else if (bits == 192) {
        key->rounds = 12;
    } else{
        key->rounds = 14;
    }

    rk[0] = GETU32(userKey     );
    rk[1] = GETU32(userKey +  4);
    rk[2] = GETU32(userKey +  8);
    rk[3] = GETU32(userKey + 12);
    if (bits == 128) {
        while (1) {
            temp  = rk[3];
            rk[4] = rk[0] ^
                    (Te2[(temp >> 16) & 0xff] & 0xff000000) ^
                    (Te3[(temp >>  8) & 0xff] & 0x00ff0000) ^
                    (Te0[(temp      ) & 0xff] & 0x0000ff00) ^
                    (Te1[(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 0;
            }
            rk += 4;
        }
    }
    rk[4] = GETU32(userKey + 16);
    rk[5] = GETU32(userKey + 20);
    if (bits == 192) {
        while (1) {
            temp = rk[ 5];
            rk[ 6] = rk[ 0] ^
                     (Te2[(temp >> 16) & 0xff] & 0xff000000) ^
                     (Te3[(temp >>  8) & 0xff] & 0x00ff0000) ^
                     (Te0[(temp      ) & 0xff] & 0x0000ff00) ^
                     (Te1[(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 0;
            }
            rk[10] = rk[ 4] ^ rk[ 9];
            rk[11] = rk[ 5] ^ rk[10];
            rk += 6;
        }
    }
    rk[6] = GETU32(userKey + 24);
    rk[7] = GETU32(userKey + 28);
    if (bits == 256) {
        while (1) {
            temp = rk[ 7];
            rk[ 8] = rk[ 0] ^
                     (Te2[(temp >> 16) & 0xff] & 0xff000000) ^
                     (Te3[(temp >>  8) & 0xff] & 0x00ff0000) ^
                     (Te0[(temp      ) & 0xff] & 0x0000ff00) ^
                     (Te1[(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 0;
            }
            temp = rk[11];
            rk[12] = rk[ 4] ^
                     (Te2[(temp >> 24)       ] & 0xff000000) ^
                     (Te3[(temp >> 16) & 0xff] & 0x00ff0000) ^
                     (Te0[(temp >>  8) & 0xff] & 0x0000ff00) ^
                     (Te1[(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:
movq %rdi, -0x10(%rsp)
movl %esi, -0x14(%rsp)
movq %rdx, -0x20(%rsp)
movl $0x0, -0x2c(%rsp)
cmpq $0x0, -0x10(%rsp)
je 0x1236
cmpq $0x0, -0x20(%rsp)
jne 0x1243
movl $0xffffffff, -0x4(%rsp) # imm = 0xFFFFFFFF
jmp 0x1937
cmpl $0x80, -0x14(%rsp)
je 0x126e
cmpl $0xc0, -0x14(%rsp)
je 0x126e
cmpl $0x100, -0x14(%rsp)     # imm = 0x100
je 0x126e
movl $0xfffffffe, -0x4(%rsp) # imm = 0xFFFFFFFE
jmp 0x1937
movq -0x20(%rsp), %rax
movq %rax, -0x28(%rsp)
cmpl $0x80, -0x14(%rsp)
jne 0x1293
movq -0x20(%rsp), %rax
movl $0xa, 0xf0(%rax)
jmp 0x12bf
cmpl $0xc0, -0x14(%rsp)
jne 0x12ae
movq -0x20(%rsp), %rax
movl $0xc, 0xf0(%rax)
jmp 0x12bd
movq -0x20(%rsp), %rax
movl $0xe, 0xf0(%rax)
jmp 0x12bf
movq -0x10(%rsp), %rax
movzbl (%rax), %ecx
shll $0x18, %ecx
movq -0x10(%rsp), %rax
movzbl 0x1(%rax), %eax
shll $0x10, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x2(%rax), %eax
shll $0x8, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x3(%rax), %eax
xorl %eax, %ecx
movq -0x28(%rsp), %rax
movl %ecx, (%rax)
movq -0x10(%rsp), %rax
movzbl 0x4(%rax), %ecx
shll $0x18, %ecx
movq -0x10(%rsp), %rax
movzbl 0x5(%rax), %eax
shll $0x10, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x6(%rax), %eax
shll $0x8, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x7(%rax), %eax
xorl %eax, %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rsp), %rax
movzbl 0x8(%rax), %ecx
shll $0x18, %ecx
movq -0x10(%rsp), %rax
movzbl 0x9(%rax), %eax
shll $0x10, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0xa(%rax), %eax
shll $0x8, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0xb(%rax), %eax
xorl %eax, %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rsp), %rax
movzbl 0xc(%rax), %ecx
shll $0x18, %ecx
movq -0x10(%rsp), %rax
movzbl 0xd(%rax), %eax
shll $0x10, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0xe(%rax), %eax
shll $0x8, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0xf(%rax), %eax
xorl %eax, %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0xc(%rax)
cmpl $0x80, -0x14(%rsp)
jne 0x14d7
jmp 0x13b9
movq -0x28(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x30(%rsp)
movq -0x28(%rsp), %rax
movl (%rax), %ecx
movl -0x30(%rsp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x6c1d(%rip), %rax      # 0x8000
movl (%rax,%rdx,4), %eax
andl $0xff000000, %eax       # imm = 0xFF000000
xorl %eax, %ecx
movl -0x30(%rsp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x6ffc(%rip), %rax      # 0x8400
movl (%rax,%rdx,4), %eax
andl $0xff0000, %eax         # imm = 0xFF0000
xorl %eax, %ecx
movl -0x30(%rsp), %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x73de(%rip), %rax      # 0x8800
movl (%rax,%rdx,4), %eax
andl $0xff00, %eax           # imm = 0xFF00
xorl %eax, %ecx
movl -0x30(%rsp), %eax
shrl $0x18, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x77c2(%rip), %rax      # 0x8c00
movl (%rax,%rdx,4), %eax
andl $0xff, %eax
xorl %eax, %ecx
movslq -0x2c(%rsp), %rdx
leaq 0x7bac(%rip), %rax      # 0x9000
xorl (%rax,%rdx,4), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x10(%rax)
movq -0x28(%rsp), %rax
movl 0x4(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x10(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x14(%rax)
movq -0x28(%rsp), %rax
movl 0x8(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x14(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x18(%rax)
movq -0x28(%rsp), %rax
movl 0xc(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x18(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x1c(%rax)
movl -0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rsp)
cmpl $0xa, %eax
jne 0x14c4
movl $0x0, -0x4(%rsp)
jmp 0x1937
movq -0x28(%rsp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rsp)
jmp 0x13b9
movq -0x10(%rsp), %rax
movzbl 0x10(%rax), %ecx
shll $0x18, %ecx
movq -0x10(%rsp), %rax
movzbl 0x11(%rax), %eax
shll $0x10, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x12(%rax), %eax
shll $0x8, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x13(%rax), %eax
xorl %eax, %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rsp), %rax
movzbl 0x14(%rax), %ecx
shll $0x18, %ecx
movq -0x10(%rsp), %rax
movzbl 0x15(%rax), %eax
shll $0x10, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x16(%rax), %eax
shll $0x8, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x17(%rax), %eax
xorl %eax, %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x14(%rax)
cmpl $0xc0, -0x14(%rsp)
jne 0x16ab
jmp 0x155d
movq -0x28(%rsp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x30(%rsp)
movq -0x28(%rsp), %rax
movl (%rax), %ecx
movl -0x30(%rsp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x6a79(%rip), %rax      # 0x8000
movl (%rax,%rdx,4), %eax
andl $0xff000000, %eax       # imm = 0xFF000000
xorl %eax, %ecx
movl -0x30(%rsp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x6e58(%rip), %rax      # 0x8400
movl (%rax,%rdx,4), %eax
andl $0xff0000, %eax         # imm = 0xFF0000
xorl %eax, %ecx
movl -0x30(%rsp), %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x723a(%rip), %rax      # 0x8800
movl (%rax,%rdx,4), %eax
andl $0xff00, %eax           # imm = 0xFF00
xorl %eax, %ecx
movl -0x30(%rsp), %eax
shrl $0x18, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x761e(%rip), %rax      # 0x8c00
movl (%rax,%rdx,4), %eax
andl $0xff, %eax
xorl %eax, %ecx
movslq -0x2c(%rsp), %rdx
leaq 0x7a08(%rip), %rax      # 0x9000
xorl (%rax,%rdx,4), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x18(%rax)
movq -0x28(%rsp), %rax
movl 0x4(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x18(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x1c(%rax)
movq -0x28(%rsp), %rax
movl 0x8(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x1c(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x20(%rax)
movq -0x28(%rsp), %rax
movl 0xc(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x20(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x24(%rax)
movl -0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rsp)
cmpl $0x8, %eax
jne 0x1668
movl $0x0, -0x4(%rsp)
jmp 0x1937
movq -0x28(%rsp), %rax
movl 0x10(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x24(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x28(%rax)
movq -0x28(%rsp), %rax
movl 0x14(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x28(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x2c(%rax)
movq -0x28(%rsp), %rax
addq $0x18, %rax
movq %rax, -0x28(%rsp)
jmp 0x155d
movq -0x10(%rsp), %rax
movzbl 0x18(%rax), %ecx
shll $0x18, %ecx
movq -0x10(%rsp), %rax
movzbl 0x19(%rax), %eax
shll $0x10, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x1a(%rax), %eax
shll $0x8, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x1b(%rax), %eax
xorl %eax, %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rsp), %rax
movzbl 0x1c(%rax), %ecx
shll $0x18, %ecx
movq -0x10(%rsp), %rax
movzbl 0x1d(%rax), %eax
shll $0x10, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x1e(%rax), %eax
shll $0x8, %eax
xorl %eax, %ecx
movq -0x10(%rsp), %rax
movzbl 0x1f(%rax), %eax
xorl %eax, %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x1c(%rax)
cmpl $0x100, -0x14(%rsp)     # imm = 0x100
jne 0x192f
jmp 0x1731
movq -0x28(%rsp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x30(%rsp)
movq -0x28(%rsp), %rax
movl (%rax), %ecx
movl -0x30(%rsp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x68a5(%rip), %rax      # 0x8000
movl (%rax,%rdx,4), %eax
andl $0xff000000, %eax       # imm = 0xFF000000
xorl %eax, %ecx
movl -0x30(%rsp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x6c84(%rip), %rax      # 0x8400
movl (%rax,%rdx,4), %eax
andl $0xff0000, %eax         # imm = 0xFF0000
xorl %eax, %ecx
movl -0x30(%rsp), %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x7066(%rip), %rax      # 0x8800
movl (%rax,%rdx,4), %eax
andl $0xff00, %eax           # imm = 0xFF00
xorl %eax, %ecx
movl -0x30(%rsp), %eax
shrl $0x18, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x744a(%rip), %rax      # 0x8c00
movl (%rax,%rdx,4), %eax
andl $0xff, %eax
xorl %eax, %ecx
movslq -0x2c(%rsp), %rdx
leaq 0x7834(%rip), %rax      # 0x9000
xorl (%rax,%rdx,4), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x20(%rax)
movq -0x28(%rsp), %rax
movl 0x4(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x20(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x24(%rax)
movq -0x28(%rsp), %rax
movl 0x8(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x24(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x28(%rax)
movq -0x28(%rsp), %rax
movl 0xc(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x28(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x2c(%rax)
movl -0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rsp)
cmpl $0x7, %eax
jne 0x183c
movl $0x0, -0x4(%rsp)
jmp 0x1937
movq -0x28(%rsp), %rax
movl 0x2c(%rax), %eax
movl %eax, -0x30(%rsp)
movq -0x28(%rsp), %rax
movl 0x10(%rax), %ecx
movl -0x30(%rsp), %eax
shrl $0x18, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x679e(%rip), %rax      # 0x8000
movl (%rax,%rdx,4), %eax
andl $0xff000000, %eax       # imm = 0xFF000000
xorl %eax, %ecx
movl -0x30(%rsp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x6b7d(%rip), %rax      # 0x8400
movl (%rax,%rdx,4), %eax
andl $0xff0000, %eax         # imm = 0xFF0000
xorl %eax, %ecx
movl -0x30(%rsp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x6f5c(%rip), %rax      # 0x8800
movl (%rax,%rdx,4), %eax
andl $0xff00, %eax           # imm = 0xFF00
xorl %eax, %ecx
movl -0x30(%rsp), %eax
andl $0xff, %eax
movl %eax, %eax
movl %eax, %edx
leaq 0x733e(%rip), %rax      # 0x8c00
movl (%rax,%rdx,4), %eax
andl $0xff, %eax
xorl %eax, %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x30(%rax)
movq -0x28(%rsp), %rax
movl 0x14(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x30(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x34(%rax)
movq -0x28(%rsp), %rax
movl 0x18(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x34(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x38(%rax)
movq -0x28(%rsp), %rax
movl 0x1c(%rax), %ecx
movq -0x28(%rsp), %rax
xorl 0x38(%rax), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x3c(%rax)
movq -0x28(%rsp), %rax
addq $0x20, %rax
movq %rax, -0x28(%rsp)
jmp 0x1731
movl $0x0, -0x4(%rsp)
movl -0x4(%rsp), %eax
retq
nopl (%rax)