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

/* Variables and functions */
void *d2i_RSAPrivateKey(int /*<<< orphan*/ *, int /*<<< orphan*/ **, size_t);
void *d2i_RSAPublicKey(int /*<<< orphan*/ *, int /*<<< orphan*/ **, size_t);
int /*<<< orphan*/ log_error(char *, ...);
void *strdup(char *);
void *key_internalize(int type, int private, u_int8_t *data, size_t datalen) {
  switch (type) {
  case 1:
    return strdup((char *)data);
  case 2:
    switch (private) {
    case 0:
      return d2i_RSAPublicKey(NULL, &data, datalen);
    case 1:
      return d2i_RSAPrivateKey(NULL, &data, datalen);
    default:
      log_error("key_internalize: not public or private "
                "RSA key passed");
      return 0;
    }
    break;
  default:
    log_error("key_internalize: unknown/unsupported key type %d", type);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<key_internalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     117b <key_internalize+0x3b>
jmp    116a <key_internalize+0x2a>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     118d <key_internalize+0x4d>
jmp    1200 <key_internalize+0xc0>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1219 <key_internalize+0xd9>
mov    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
test   %eax,%eax
je     11b1 <key_internalize+0x71>
jmp    11a0 <key_internalize+0x60>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
je     11cb <key_internalize+0x8b>
jmp    11e5 <key_internalize+0xa5>
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1040 <d2i_RSAPublicKey@plt>
mov    %rax,-0x8(%rbp)
jmp    1219 <key_internalize+0xd9>
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1050 <d2i_RSAPrivateKey@plt>
mov    %rax,-0x8(%rbp)
jmp    1219 <key_internalize+0xd9>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <log_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1219 <key_internalize+0xd9>
mov    -0xc(%rbp),%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <log_error@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<key_internalize>:
push   %rbx
sub    $0x10,%rsp
mov    %rdx,0x8(%rsp)
cmp    $0x2,%edi
je     1163 <key_internalize+0x23>
mov    %edi,%eax
cmp    $0x1,%edi
jne    1180 <key_internalize+0x40>
mov    %rdx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1060 <strdup@plt>
cmp    $0x1,%esi
je     1194 <key_internalize+0x54>
test   %esi,%esi
jne    11a8 <key_internalize+0x68>
lea    0x8(%rsp),%rsi
xor    %edi,%edi
mov    %rcx,%rdx
call   1040 <d2i_RSAPublicKey@plt>
mov    %rax,%rbx
jmp    11b8 <key_internalize+0x78>
lea    0xeaf(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1030 <log_error@plt>
jmp    11b8 <key_internalize+0x78>
lea    0x8(%rsp),%rsi
xor    %edi,%edi
mov    %rcx,%rdx
call   1050 <d2i_RSAPrivateKey@plt>
mov    %rax,%rbx
jmp    11b8 <key_internalize+0x78>
lea    0xe51(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <log_error@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [54 x i8] c"key_internalize: not public or private RSA key passed\00"
@.str.1 = [49 x i8] c"key_internalize: unknown/unsupported key type %d\00"
define i8* @key_internalize(i32 %0, i32 %1, i32* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i64
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i64 %3, i64* %9
%10 = load i32, i32* %6
switch i32 %10, label %25 [
i32 1, label %11
i32 2, label %15
]
11: ; preds = %4
%12 = load i32*, i32** %8
%13 = bitcast i32* %12 to i8*
%14 = call i8* @strdup(i8* %13)
store i8* %14, i8** %5
br label %29
15: ; preds = %4
%16 = load i32, i32* %7
switch i32 %16, label %23 [
i32 0, label %17
i32 1, label %20
]
17: ; preds = %15
%18 = load i64, i64* %9
%19 = call i8* @d2i_RSAPublicKey(i32* null, i32** %8, i64 %18)
store i8* %19, i8** %5
br label %29
20: ; preds = %15
%21 = load i64, i64* %9
%22 = call i8* @d2i_RSAPrivateKey(i32* null, i32** %8, i64 %21)
store i8* %22, i8** %5
br label %29
23: ; preds = %15
%24 = call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %5
br label %29
25: ; preds = %4
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25
store i8* null, i8** %5
br label %29
29: ; preds = %28, %23, %20, %17, %11
%30 = load i8*, i8** %5
ret i8* %30
}

LLVM IR (-O2):
@.str = [54 x i8] c"key_internalize: not public or private RSA key passed\00"
@.str.1 = [49 x i8] c"key_internalize: unknown/unsupported key type %d\00"
define i8* @key_internalize(i32 %0, i32 %1, i32* %2, i64 %3) {
%5 = alloca i32*
store i32* %2, i32** %5
switch i32 %0, label %16 [
i32 1, label %6
i32 2, label %9
]
6: ; preds = %4
%7 = bitcast i32* %2 to i8*
%8 = tail call i8* @strdup(i8* %7)
br label %18
9: ; preds = %4
switch i32 %1, label %14 [
i32 0, label %10
i32 1, label %12
]
10: ; preds = %9
%11 = call i8* @d2i_RSAPublicKey(i32* null, i32** %5, i64 %3)
br label %18
12: ; preds = %9
%13 = call i8* @d2i_RSAPrivateKey(i32* null, i32** %5, i64 %3)
br label %18
14: ; preds = %9
%15 = tail call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
br label %18
16: ; preds = %4
%17 = tail call i32 (i8*, ...) @log_error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %18
18: ; preds = %16, %14, %12, %10, %6
%19 = phi i8* [ null, %16 ], [ null, %14 ], [ %13, %12 ], [ %11, %10 ], [ %8, %6 ]
ret i8* %19
}