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

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *intToType(int n) {
  char *buf;
  buf = malloc(32);
  switch (n) {
  case 0:
    strncpy(buf, "void", sizeof(buf));
    break;
  case 1:
    strncpy(buf, "int", sizeof(buf));
    break;
  case 2:
    strncpy(buf, "char", sizeof(buf));
    break;
  case 3:
    strncpy(buf, "float", sizeof(buf));
    break;
  case 4:
    strncpy(buf, "double", sizeof(buf));
    break;
  }
  return buf;
}


x86 assembly (clang, -O0):
<intToType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x4,%rax
ja     11db <intToType+0xbb>
mov    -0x18(%rbp),%rax
lea    0xeab(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xeab(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
jmp    11db <intToType+0xbb>
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
jmp    11db <intToType+0xbb>
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
jmp    11db <intToType+0xbb>
mov    -0x10(%rbp),%rdi
lea    0xe6b(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
jmp    11db <intToType+0xbb>
mov    -0x10(%rbp),%rdi
lea    0xe57(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToType>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
cmp    $0x4,%ebp
ja     1155 <intToType+0x35>
movslq %ebp,%rax
lea    0xedb(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"void\00"
@.str.1 = [4 x i8] c"int\00"
@.str.2 = [5 x i8] c"char\00"
@.str.3 = [6 x i8] c"float\00"
@.str.4 = [7 x i8] c"double\00"
define i8* @intToType(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i8* @malloc(i32 32)
store i8* %4, i8** %3
%5 = load i32, i32* %2
switch i32 %5, label %21 [
i32 0, label %6
i32 1, label %9
i32 2, label %12
i32 3, label %15
i32 4, label %18
]
6: ; preds = %1
%7 = load i8*, i8** %3
%8 = call i32 @strncpy(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 8)
br label %21
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strncpy(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 8)
br label %21
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 @strncpy(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 8)
br label %21
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i32 @strncpy(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 8)
br label %21
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = call i32 @strncpy(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 8)
br label %21
21: ; preds = %1, %18, %15, %12, %9, %6
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
@.str = [5 x i8] c"void\00"
@.str.1 = [4 x i8] c"int\00"
@.str.2 = [5 x i8] c"char\00"
@.str.3 = [6 x i8] c"float\00"
@.str.4 = [7 x i8] c"double\00"
@reltable.intToType = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.intToType to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.intToType to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.intToType to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.intToType to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.intToType to i64)) to i32)]
define i8* @intToType(i32 %0) {
%2 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%3 = icmp ult i32 %0, 5
br i1 %3, label %4, label %9
4: ; preds = %1
%5 = sext i32 %0 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.intToType to i8*), i64 %6)
%8 = tail call i32 @strncpy(i8* %2, i8* %7, i32 8)
br label %9
9: ; preds = %1, %4
ret i8* %2
}