#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *to_type_string(int type) {
  char *str = (char *)malloc(sizeof(char) * 512);
  if (type == -2) {
    sprintf(str, "%s", "number");
  } else if (type == -1) {
    sprintf(str, "%s", "unit");
  } else {
    sprintf(str, "function with %d arguments", type);
  }
  return str;
}


x86 assembly (clang, -O0):
<to_type_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x200,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpl   $0xfffffffe,-0x4(%rbp)
jne    1161 <to_type_string+0x41>
mov    -0x10(%rbp),%rdi
lea    0xeb2(%rip),%rsi
lea    0xeae(%rip),%rdx
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    11a3 <to_type_string+0x83>
cmpl   $0xffffffff,-0x4(%rbp)
jne    1189 <to_type_string+0x69>
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
lea    0xe8d(%rip),%rdx
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    119e <to_type_string+0x7e>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    11a3 <to_type_string+0x83>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_type_string>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x200,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
cmp    $0xffffffff,%ebp
je     114b <to_type_string+0x2b>
cmp    $0xfffffffe,%ebp
jne    1157 <to_type_string+0x37>
movl   $0x726562,0x3(%rbx)
movl   $0x626d756e,(%rbx)
jmp    116a <to_type_string+0x4a>
movb   $0x0,0x4(%rbx)
movl   $0x74696e75,(%rbx)
jmp    116a <to_type_string+0x4a>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"number\00"
@.str.2 = [5 x i8] c"unit\00"
@.str.3 = [27 x i8] c"function with %d arguments\00"
define i8* @to_type_string(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i64 @malloc(i32 512)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, -2
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %22
11: ; preds = %1
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %21
17: ; preds = %11
%18 = load i8*, i8** %3
%19 = load i32, i32* %2
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %17, %14
br label %22
22: ; preds = %21, %8
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"number\00"
@.str.2 = [5 x i8] c"unit\00"
@.str.3 = [27 x i8] c"function with %d arguments\00"
define i8* @to_type_string(i32 %0) {
%2 = tail call i64 @malloc(i32 512)
%3 = inttoptr i64 %2 to i8*
switch i32 %0, label %6 [
i32 -2, label %4
i32 -1, label %5
]
4: ; preds = %1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(7) %3, i8* align 1 dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 7, i1 false)
br label %8
5: ; preds = %1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %3, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 5, i1 false)
br label %8
6: ; preds = %1
%7 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %8
8: ; preds = %5, %6, %4
ret i8* %3
}