#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__ calloc(int, int);
scalar_t__ realloc(char *, scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *status_format(int status) {
  char *ret = (char *)calloc(1, 50);
  switch (status) {
  case 0:
    strcpy(ret, "uncloacked");
    break;
  case 2:
    strcpy(ret, "cloaked");
    break;
  case 1:
    strcpy(ret, "potentially cloaked");
    break;
  case -1:
    strcpy(ret, "unknown cloaking");
    break;
  default:
    sprintf(ret, "type %d", status);
    break;
  }
  ret = (char *)realloc(ret, strlen(ret) + 1);
  return ret;
}


x86 assembly (clang, -O0):
<status_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x1,%edi
mov    $0x32,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     11eb <status_format+0x9b>
mov    -0x18(%rbp),%rax
lea    0xe72(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11fe <status_format+0xae>
mov    -0x10(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11fe <status_format+0xae>
mov    -0x10(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11fe <status_format+0xae>
mov    -0x10(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11fe <status_format+0xae>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe47(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rsi
add    $0x1,%rsi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<status_format>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x1,%edi
mov    $0x32,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
lea    0x1(%rbx),%eax
cmp    $0x3,%eax
ja     1189 <status_format+0x39>
lea    0xe89(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea8(%rip),%rsi
jmp    11b5 <status_format+0x65>
lea    0xeb0(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1070 <sprintf@plt>
jmp    11bd <status_format+0x6d>
lea    0xe6d(%rip),%rsi
jmp    11b5 <status_format+0x65>
lea    0xe6f(%rip),%rsi
jmp    11b5 <status_format+0x65>
lea    0xe72(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <realloc@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"uncloacked\00"
@.str.1 = [8 x i8] c"cloaked\00"
@.str.2 = [20 x i8] c"potentially cloaked\00"
@.str.3 = [17 x i8] c"unknown cloaking\00"
@.str.4 = [8 x i8] c"type %d\00"
define i8* @status_format(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i64 @calloc(i32 1, i32 50)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = load i32, i32* %2
switch i32 %6, label %19 [
i32 0, label %7
i32 2, label %10
i32 1, label %13
i32 -1, label %16
]
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %23
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %23
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %23
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %23
19: ; preds = %1
%20 = load i8*, i8** %3
%21 = load i32, i32* %2
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %16, %13, %10, %7
%24 = load i8*, i8** %3
%25 = load i8*, i8** %3
%26 = call i64 @strlen(i8* %25)
%27 = add nsw i64 %26, 1
%28 = call i64 @realloc(i8* %24, i64 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %3
%30 = load i8*, i8** %3
ret i8* %30
}

LLVM IR (-O2):
@.str = [11 x i8] c"uncloacked\00"
@.str.1 = [8 x i8] c"cloaked\00"
@.str.2 = [20 x i8] c"potentially cloaked\00"
@.str.3 = [17 x i8] c"unknown cloaking\00"
@.str.4 = [8 x i8] c"type %d\00"
define i8* @status_format(i32 %0) {
%2 = tail call i64 @calloc(i32 1, i32 50)
%3 = inttoptr i64 %2 to i8*
switch i32 %0, label %12 [
i32 0, label %4
i32 2, label %6
i32 1, label %8
i32 -1, label %10
]
4: ; preds = %1
%5 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %14
6: ; preds = %1
%7 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %14
8: ; preds = %1
%9 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %14
10: ; preds = %1
%11 = tail call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %14
12: ; preds = %1
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %14
14: ; preds = %12, %10, %8, %6, %4
%15 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%16 = add nsw i64 %15, 1
%17 = tail call i64 @realloc(i8* %3, i64 %16)
%18 = inttoptr i64 %17 to i8*
ret i8* %18
}