#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ uint8_t;
typedef void crypto_aes_key;
typedef int /*<<< orphan*/ AES_KEY;

/* Variables and functions */
int /*<<< orphan*/ AES_set_encrypt_key(int /*<<< orphan*/ const *, size_t,
                                       int /*<<< orphan*/ *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ *malloc(int);
struct crypto_aes_key *crypto_aes_key_expand(const uint8_t *key, size_t len) {
  AES_KEY *kexp;
  assert((len == 16) || (len == 32));
  if ((kexp = malloc(sizeof(AES_KEY))) == NULL)
    goto err0;
  AES_set_encrypt_key(key, len * 8, kexp);
  return ((void *)kexp);
err0:
  return (NULL);
}


x86 assembly (clang, -O0):
<crypto_aes_key_expand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x1,%al
cmpq   $0x10,-0x18(%rbp)
mov    %al,-0x21(%rbp)
je     115b <crypto_aes_key_expand+0x2b>
cmpq   $0x20,-0x18(%rbp)
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1185 <crypto_aes_key_expand+0x55>
jmp    11a7 <crypto_aes_key_expand+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
shl    $0x3,%rsi
mov    -0x20(%rbp),%rdx
call   1030 <AES_set_encrypt_key@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11af <crypto_aes_key_expand+0x7f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypto_aes_key_expand>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    -0x10(%rsi),%rax
xor    %edi,%edi
test   $0xffffffffffffffef,%rax
sete   %dil
call   1040 <assert@plt>
mov    $0x4,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1176 <crypto_aes_key_expand+0x46>
mov    %rax,%rbx
shl    $0x3,%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1030 <AES_set_encrypt_key@plt>
jmp    1178 <crypto_aes_key_expand+0x48>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.crypto_aes_key = type opaque
define %struct.crypto_aes_key* @crypto_aes_key_expand(i32* %0, i64 %1) {
%3 = alloca %struct.crypto_aes_key*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32*
store i32* %0, i32** %4
store i64 %1, i64* %5
%7 = load i64, i64* %5
%8 = icmp eq i64 %7, 16
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i64, i64* %5
%11 = icmp eq i64 %10, 32
br label %12
12: ; preds = %9, %2
%13 = phi i1 [ true, %2 ], [ %11, %9 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32* @malloc(i32 4)
store i32* %16, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %12
br label %28
19: ; preds = %12
%20 = load i32*, i32** %4
%21 = load i64, i64* %5
%22 = mul i64 %21, 8
%23 = load i32*, i32** %6
%24 = call i32 @AES_set_encrypt_key(i32* %20, i64 %22, i32* %23)
%25 = load i32*, i32** %6
%26 = bitcast i32* %25 to i8*
%27 = bitcast i8* %26 to %struct.crypto_aes_key*
store %struct.crypto_aes_key* %27, %struct.crypto_aes_key** %3
br label %29
28: ; preds = %18
store %struct.crypto_aes_key* null, %struct.crypto_aes_key** %3
br label %29
29: ; preds = %28, %19
%30 = load %struct.crypto_aes_key*, %struct.crypto_aes_key** %3
ret %struct.crypto_aes_key* %30
}

LLVM IR (-O2):
%struct.crypto_aes_key = type opaque
define %struct.crypto_aes_key* @crypto_aes_key_expand(i32* %0, i64 %1) {
%3 = icmp eq i64 %1, 16
%4 = icmp eq i64 %1, 32
%5 = or i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i32* @malloc(i32 4)
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = shl i64 %1, 3
%12 = tail call i32 @AES_set_encrypt_key(i32* %0, i64 %11, i32* %8)
%13 = bitcast i32* %8 to %struct.crypto_aes_key*
br label %14
14: ; preds = %2, %10
%15 = phi %struct.crypto_aes_key* [ %13, %10 ], [ null, %2 ]
ret %struct.crypto_aes_key* %15
}