#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 */
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
char *type_to_string(int type) {
  char *str_type = malloc(32 * sizeof(char));
  strcpy(str_type, "");
  if (type == 1)
    strcpy(str_type, "A");
  if (type == 15)
    strcpy(str_type, "MX");
  if (type == 2)
    strcpy(str_type, "NS");
  if (type == 5)
    strcpy(str_type, "CNAME");
  if (type == 6)
    strcpy(str_type, "SOA");
  if (type == 16)
    strcpy(str_type, "TXT");
  return str_type;
}


x86 assembly (clang, -O0):
<type_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xecb(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x1,-0x4(%rbp)
jne    1163 <type_to_string+0x43>
mov    -0x10(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0xf,-0x4(%rbp)
jne    117d <type_to_string+0x5d>
mov    -0x10(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x2,-0x4(%rbp)
jne    1197 <type_to_string+0x77>
mov    -0x10(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x5,-0x4(%rbp)
jne    11b1 <type_to_string+0x91>
mov    -0x10(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x6,-0x4(%rbp)
jne    11cb <type_to_string+0xab>
mov    -0x10(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x10,-0x4(%rbp)
jne    11e5 <type_to_string+0xc5>
mov    -0x10(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<type_to_string>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xf15(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
add    $0xffffffff,%ebx
cmp    $0xf,%ebx
ja     1194 <type_to_string+0x74>
lea    0xefd(%rip),%rsi
lea    0xea8(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    0xedb(%rip),%rsi
jmp    118c <type_to_string+0x6c>
lea    0xed5(%rip),%rsi
jmp    118c <type_to_string+0x6c>
lea    0xed2(%rip),%rsi
jmp    118c <type_to_string+0x6c>
lea    0xebd(%rip),%rsi
jmp    118c <type_to_string+0x6c>
lea    0xec4(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"A\00"
@.str.2 = [3 x i8] c"MX\00"
@.str.3 = [3 x i8] c"NS\00"
@.str.4 = [6 x i8] c"CNAME\00"
@.str.5 = [4 x i8] c"SOA\00"
@.str.6 = [4 x i8] c"TXT\00"
define i8* @type_to_string(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 i8*, i8** %3
%6 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %9, %1
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 15
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %15, %12
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* %2
%26 = icmp eq i32 %25, 5
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i8*, i8** %3
%29 = call i32 @strcpy(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %2
%32 = icmp eq i32 %31, 6
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i8*, i8** %3
%35 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %36
36: ; preds = %33, %30
%37 = load i32, i32* %2
%38 = icmp eq i32 %37, 16
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i8*, i8** %3
%41 = call i32 @strcpy(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
br label %42
42: ; preds = %39, %36
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"A\00"
@.str.2 = [3 x i8] c"MX\00"
@.str.3 = [3 x i8] c"NS\00"
@.str.4 = [6 x i8] c"CNAME\00"
@.str.5 = [4 x i8] c"SOA\00"
@.str.6 = [4 x i8] c"TXT\00"
define i8* @type_to_string(i32 %0) {
%2 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%3 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
switch i32 %0, label %12 [
i32 1, label %9
i32 15, label %4
i32 2, label %5
i32 5, label %6
i32 6, label %7
i32 16, label %8
]
4: ; preds = %1
br label %9
5: ; preds = %1
br label %9
6: ; preds = %1
br label %9
7: ; preds = %1
br label %9
8: ; preds = %1
br label %9
9: ; preds = %1, %8, %4, %5, %6, %7
%10 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), %7 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), %6 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %5 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %4 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), %8 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %1 ]
%11 = tail call i32 @strcpy(i8* %2, i8* %10)
br label %12
12: ; preds = %9, %1
ret i8* %2
}