#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 */
int /*<<< orphan*/ log_error(char *, int);
char *raw2hex(int /*<<< orphan*/ *, size_t);
char *strdup(char *);
char *key_printable(int type, int private, u_int8_t *data, size_t datalen) {
  switch (type) {
  case 1:
    return strdup((char *)data);
  case 2:
    return raw2hex(data, datalen);
  default:
    log_error("key_printable: unknown/unsupported key type %d", type);
    return 0;
  }
}


x86 assembly (clang, -O0):
<key_printable>:
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     116b <key_printable+0x3b>
jmp    115a <key_printable+0x2a>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     117d <key_printable+0x4d>
jmp    1193 <key_printable+0x63>
mov    -0x18(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11aa <key_printable+0x7a>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <raw2hex@plt>
mov    %rax,-0x8(%rbp)
jmp    11aa <key_printable+0x7a>
mov    -0xc(%rbp),%esi
lea    0xe63(%rip),%rdi
call   1040 <log_error@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<key_printable>:
cmp    $0x2,%edi
je     1144 <key_printable+0x14>
mov    %edi,%esi
cmp    $0x1,%edi
jne    114f <key_printable+0x1f>
mov    %rdx,%rdi
jmp    1050 <strdup@plt>
mov    %rdx,%rdi
mov    %rcx,%rsi
jmp    1030 <raw2hex@plt>
push   %rax
lea    0xea9(%rip),%rdi
call   1040 <log_error@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [47 x i8] c"key_printable: unknown/unsupported key type %d\00"
define i8* @key_printable(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 %19 [
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 %22
15: ; preds = %4
%16 = load i32*, i32** %8
%17 = load i64, i64* %9
%18 = call i8* @raw2hex(i32* %16, i64 %17)
store i8* %18, i8** %5
br label %22
19: ; preds = %4
%20 = load i32, i32* %6
%21 = call i32 @log_error(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %20)
store i8* null, i8** %5
br label %22
22: ; preds = %19, %15, %11
%23 = load i8*, i8** %5
ret i8* %23
}

LLVM IR (-O2):
@.str = [47 x i8] c"key_printable: unknown/unsupported key type %d\00"
define i8* @key_printable(i32 %0, i32 %1, i32* %2, i64 %3) {
switch i32 %0, label %10 [
i32 1, label %5
i32 2, label %8
]
5: ; preds = %4
%6 = bitcast i32* %2 to i8*
%7 = tail call i8* @strdup(i8* %6)
br label %12
8: ; preds = %4
%9 = tail call i8* @raw2hex(i32* %2, i64 %3)
br label %12
10: ; preds = %4
%11 = tail call i32 @log_error(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %12
12: ; preds = %10, %8, %5
%13 = phi i8* [ null, %10 ], [ %9, %8 ], [ %7, %5 ]
ret i8* %13
}