#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 uint32_t;
typedef int /*<<< orphan*/ EVP_CIPHER;

/* Variables and functions */
int /*<<< orphan*/ const *EVP_aes_128_ctr();
int /*<<< orphan*/ const *EVP_aes_128_ecb();
int /*<<< orphan*/ const *EVP_aes_192_ctr();
int /*<<< orphan*/ const *EVP_aes_192_ecb();
int /*<<< orphan*/ const *EVP_aes_256_ctr();
int /*<<< orphan*/ const *EVP_aes_256_ecb();
int /*<<< orphan*/ const *EVP_aes_256_xts();
const EVP_CIPHER *algid_to_evp(uint32_t alg) {
  switch (alg & (0xf0000000 | 0x000f0000 | 0x00000fff)) {
  case 0x10010000 | 0x00000100:
    return EVP_aes_256_ecb();
  case 0x10010000 | 0x000000c0:
    return EVP_aes_192_ecb();
  case 0x10010000 | 0x00000080:
    return EVP_aes_128_ecb();
  case 0x20000000 | 0x00000100:
    return EVP_aes_256_ctr();
  case 0x20000000 | 0x000000c0:
    return EVP_aes_192_ctr();
  case 0x20000000 | 0x00000080:
    return EVP_aes_128_ctr();
  case 0x30000000 | 0x00000100:
    return EVP_aes_256_xts();
  }
  return NULL;
}


x86 assembly (clang, -O0):
<algid_to_evp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xf00f0fff,%eax
mov    %eax,-0x10(%rbp)
sub    $0x10010080,%eax
je     1228 <algid_to_evp+0xb8>
jmp    1196 <algid_to_evp+0x26>
mov    -0x10(%rbp),%eax
sub    $0x100100c0,%eax
je     1218 <algid_to_evp+0xa8>
jmp    11a9 <algid_to_evp+0x39>
mov    -0x10(%rbp),%eax
sub    $0x10010100,%eax
je     1208 <algid_to_evp+0x98>
jmp    11bc <algid_to_evp+0x4c>
mov    -0x10(%rbp),%eax
sub    $0x20000080,%eax
je     1258 <algid_to_evp+0xe8>
jmp    11cf <algid_to_evp+0x5f>
mov    -0x10(%rbp),%eax
sub    $0x200000c0,%eax
je     1248 <algid_to_evp+0xd8>
jmp    11e2 <algid_to_evp+0x72>
mov    -0x10(%rbp),%eax
sub    $0x20000100,%eax
je     1238 <algid_to_evp+0xc8>
jmp    11f5 <algid_to_evp+0x85>
mov    -0x10(%rbp),%eax
sub    $0x30000100,%eax
je     1268 <algid_to_evp+0xf8>
jmp    1278 <algid_to_evp+0x108>
mov    $0x0,%al
call   1080 <EVP_aes_256_ecb@plt>
mov    %rax,-0x8(%rbp)
jmp    1280 <algid_to_evp+0x110>
mov    $0x0,%al
call   1090 <EVP_aes_192_ecb@plt>
mov    %rax,-0x8(%rbp)
jmp    1280 <algid_to_evp+0x110>
mov    $0x0,%al
call   1060 <EVP_aes_128_ecb@plt>
mov    %rax,-0x8(%rbp)
jmp    1280 <algid_to_evp+0x110>
mov    $0x0,%al
call   1050 <EVP_aes_256_ctr@plt>
mov    %rax,-0x8(%rbp)
jmp    1280 <algid_to_evp+0x110>
mov    $0x0,%al
call   1030 <EVP_aes_192_ctr@plt>
mov    %rax,-0x8(%rbp)
jmp    1280 <algid_to_evp+0x110>
mov    $0x0,%al
call   1040 <EVP_aes_128_ctr@plt>
mov    %rax,-0x8(%rbp)
jmp    1280 <algid_to_evp+0x110>
mov    $0x0,%al
call   1070 <EVP_aes_256_xts@plt>
mov    %rax,-0x8(%rbp)
jmp    1280 <algid_to_evp+0x110>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<algid_to_evp>:
and    $0xf00f0fff,%edi
cmp    $0x2000007f,%edi
jle    119d <algid_to_evp+0x2d>
cmp    $0x200000ff,%edi
jg     11bc <algid_to_evp+0x4c>
cmp    $0x20000080,%edi
je     11d3 <algid_to_evp+0x63>
cmp    $0x200000c0,%edi
jne    11e8 <algid_to_evp+0x78>
xor    %eax,%eax
jmp    1030 <EVP_aes_192_ctr@plt>
cmp    $0x10010080,%edi
je     11da <algid_to_evp+0x6a>
cmp    $0x100100c0,%edi
je     11eb <algid_to_evp+0x7b>
cmp    $0x10010100,%edi
jne    11e8 <algid_to_evp+0x78>
xor    %eax,%eax
jmp    1080 <EVP_aes_256_ecb@plt>
cmp    $0x20000100,%edi
je     11e1 <algid_to_evp+0x71>
cmp    $0x30000100,%edi
jne    11e8 <algid_to_evp+0x78>
xor    %eax,%eax
jmp    1070 <EVP_aes_256_xts@plt>
xor    %eax,%eax
jmp    1040 <EVP_aes_128_ctr@plt>
xor    %eax,%eax
jmp    1060 <EVP_aes_128_ecb@plt>
xor    %eax,%eax
jmp    1050 <EVP_aes_256_ctr@plt>
xor    %eax,%eax
ret
xor    %eax,%eax
jmp    1090 <EVP_aes_192_ecb@plt>

LLVM IR (-O0):
define i32* @algid_to_evp(i32 %0) {
%2 = alloca i32*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = and i32 %4, -267448321
switch i32 %5, label %20 [
i32 268501248, label %6
i32 268501184, label %8
i32 268501120, label %10
i32 536871168, label %12
i32 536871104, label %14
i32 536871040, label %16
i32 805306624, label %18
]
6: ; preds = %1
%7 = call i32* (...) @EVP_aes_256_ecb()
store i32* %7, i32** %2
br label %21
8: ; preds = %1
%9 = call i32* (...) @EVP_aes_192_ecb()
store i32* %9, i32** %2
br label %21
10: ; preds = %1
%11 = call i32* (...) @EVP_aes_128_ecb()
store i32* %11, i32** %2
br label %21
12: ; preds = %1
%13 = call i32* (...) @EVP_aes_256_ctr()
store i32* %13, i32** %2
br label %21
14: ; preds = %1
%15 = call i32* (...) @EVP_aes_192_ctr()
store i32* %15, i32** %2
br label %21
16: ; preds = %1
%17 = call i32* (...) @EVP_aes_128_ctr()
store i32* %17, i32** %2
br label %21
18: ; preds = %1
%19 = call i32* (...) @EVP_aes_256_xts()
store i32* %19, i32** %2
br label %21
20: ; preds = %1
store i32* null, i32** %2
br label %21
21: ; preds = %20, %18, %16, %14, %12, %10, %8, %6
%22 = load i32*, i32** %2
ret i32* %22
}

LLVM IR (-O2):
define i32* @algid_to_evp(i32 %0) {
%2 = and i32 %0, -267448321
switch i32 %2, label %17 [
i32 268501248, label %3
i32 268501184, label %5
i32 268501120, label %7
i32 536871168, label %9
i32 536871104, label %11
i32 536871040, label %13
i32 805306624, label %15
]
3: ; preds = %1
%4 = tail call i32* (...) @EVP_aes_256_ecb()
br label %17
5: ; preds = %1
%6 = tail call i32* (...) @EVP_aes_192_ecb()
br label %17
7: ; preds = %1
%8 = tail call i32* (...) @EVP_aes_128_ecb()
br label %17
9: ; preds = %1
%10 = tail call i32* (...) @EVP_aes_256_ctr()
br label %17
11: ; preds = %1
%12 = tail call i32* (...) @EVP_aes_192_ctr()
br label %17
13: ; preds = %1
%14 = tail call i32* (...) @EVP_aes_128_ctr()
br label %17
15: ; preds = %1
%16 = tail call i32* (...) @EVP_aes_256_xts()
br label %17
17: ; preds = %1, %15, %13, %11, %9, %7, %5, %3
%18 = phi i32* [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ %8, %7 ], [ %6, %5 ], [ %4, %3 ], [ null, %1 ]
ret i32* %18
}