#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 */

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ printf(char *, int);
int aes_get_num_rounds(int key_len) {
  int num_rounds = 0;
  int num_k = key_len / 4;
  if (num_k == 4) {
    num_rounds = 10;
  } else if (num_k == 6) {
    num_rounds = 12;
  } else if (num_k == 8) {
    num_rounds = 14;
  } else {
    printf("ERROR: key_len = %i not supported\n", key_len);
    return -EINVAL;
  }
  return num_rounds;
}


x86 assembly (clang, -O0):
<aes_get_num_rounds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
cmpl   $0x4,-0x10(%rbp)
jne    1146 <aes_get_num_rounds+0x36>
movl   $0xa,-0xc(%rbp)
jmp    119e <aes_get_num_rounds+0x8e>
cmpl   $0x6,-0x10(%rbp)
jne    115c <aes_get_num_rounds+0x4c>
movl   $0xc,-0xc(%rbp)
jmp    1199 <aes_get_num_rounds+0x89>
cmpl   $0x8,-0x10(%rbp)
jne    1172 <aes_get_num_rounds+0x62>
movl   $0xe,-0xc(%rbp)
jmp    1194 <aes_get_num_rounds+0x84>
mov    -0x8(%rbp),%esi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    0x2e56(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11a4 <aes_get_num_rounds+0x94>
jmp    1199 <aes_get_num_rounds+0x89>
jmp    119e <aes_get_num_rounds+0x8e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_get_num_rounds>:
mov    %edi,%eax
and    $0xfffffffc,%eax
cmp    $0x10,%eax
je     112a <aes_get_num_rounds+0x1a>
cmp    $0x18,%eax
je     1130 <aes_get_num_rounds+0x20>
cmp    $0x20,%eax
jne    1136 <aes_get_num_rounds+0x26>
mov    $0xe,%eax
ret
mov    $0xa,%eax
ret
mov    $0xc,%eax
ret
push   %rax
mov    %edi,%esi
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e94(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"ERROR: key_len = %i not supported\0A\00"
@EINVAL = global i32 0
define i32 @aes_get_num_rounds(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
%6 = load i32, i32* %3
%7 = sdiv i32 %6, 4
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 4
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 10, i32* %4
br label %26
11: ; preds = %1
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 6
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 12, i32* %4
br label %25
15: ; preds = %11
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 8
br i1 %17, label %18, label %19
18: ; preds = %15
store i32 14, i32* %4
br label %24
19: ; preds = %15
%20 = load i32, i32* %3
%21 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @EINVAL
%23 = sub nsw i32 0, %22
store i32 %23, i32* %2
br label %28
24: ; preds = %18
br label %25
25: ; preds = %24, %14
br label %26
26: ; preds = %25, %10
%27 = load i32, i32* %4
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %19
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [35 x i8] c"ERROR: key_len = %i not supported\0A\00"
@EINVAL = global i32 0
define i32 @aes_get_num_rounds(i32 %0) {
%2 = and i32 %0, -4
switch i32 %2, label %3 [
i32 16, label %9
i32 24, label %7
i32 32, label %8
]
3: ; preds = %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = load i32, i32* @EINVAL
%6 = sub nsw i32 0, %5
br label %9
7: ; preds = %1
br label %9
8: ; preds = %1
br label %9
9: ; preds = %1, %8, %7, %3
%10 = phi i32 [ %6, %3 ], [ 10, %1 ], [ 12, %7 ], [ 14, %8 ]
ret i32 %10
}