#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*/ sprintf(char *, char *, int);
char *intToDisplay(int inputNumber) {
  char *returnString = malloc(4 * sizeof(char *));
  returnString[0] = ' ';
  returnString[1] = ' ';
  returnString[2] = ' ';
  returnString[3] = ' ';
  if (inputNumber != 0) {
    char str[4];
    sprintf(str, "%d", inputNumber);
    int length = 1;
    if (inputNumber > 9) {
      length++;
    }
    if (inputNumber > 99) {
      length++;
    }
    if (inputNumber > 999) {
      length++;
    }
    switch (length) {
    case 4:
      returnString[0] = str[0];
      returnString[1] = str[1];
      returnString[2] = str[2];
      returnString[3] = str[3];
      break;
    case 3:
      returnString[3] = str[2];
    case 2:
      returnString[2] = str[1];
    case 1:
      returnString[1] = str[0];
      break;
    default:
      break;
    }
  }
  return returnString;
}


x86 assembly (clang, -O0):
<intToDisplay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x20,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x20,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x20,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0x20,0x3(%rax)
cmpl   $0x0,-0x4(%rbp)
je     123a <intToDisplay+0x11a>
lea    -0x14(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea0(%rip),%rsi
call   1040 <sprintf@plt>
movl   $0x1,-0x18(%rbp)
cmpl   $0x9,-0x4(%rbp)
jle    118f <intToDisplay+0x6f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x63,-0x4(%rbp)
jle    11a2 <intToDisplay+0x82>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x3e7,-0x4(%rbp)
jle    11b8 <intToDisplay+0x98>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     1230 <intToDisplay+0x110>
mov    -0x20(%rbp),%rax
lea    0xe28(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x13(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x12(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x11(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
jmp    1235 <intToDisplay+0x115>
mov    -0x12(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x13(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x14(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
jmp    1235 <intToDisplay+0x115>
jmp    1235 <intToDisplay+0x115>
jmp    123a <intToDisplay+0x11a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToDisplay>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x20,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
movl   $0x20202020,(%rax)
test   %ebp,%ebp
je     11b5 <intToDisplay+0x95>
lea    0xecd(%rip),%rsi
lea    0x4(%rsp),%rdi
mov    %ebp,%edx
call   1040 <sprintf@plt>
xor    %eax,%eax
cmp    $0xa,%ebp
setge  %al
xor    %ecx,%ecx
cmp    $0x64,%ebp
setge  %cl
add    %eax,%ecx
xor    %eax,%eax
cmp    $0x3e8,%ebp
setge  %al
add    %ecx,%eax
cmp    $0x3,%eax
ja     11b5 <intToDisplay+0x95>
lea    0xe86(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x6(%rsp),%al
mov    %al,0x3(%rbx)
mov    0x5(%rsp),%al
mov    %al,0x2(%rbx)
mov    0x4(%rsp),%al
mov    %al,0x1(%rbx)
jmp    11b5 <intToDisplay+0x95>
mov    0x4(%rsp),%al
mov    %al,(%rbx)
mov    0x5(%rsp),%al
mov    %al,0x1(%rbx)
mov    0x6(%rsp),%al
mov    %al,0x2(%rbx)
mov    0x7(%rsp),%al
mov    %al,0x3(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i8* @intToDisplay(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i8]
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i8* @malloc(i32 32)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
store i8 32, i8* %8
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8 32, i8* %10
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 2
store i8 32, i8* %12
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 3
store i8 32, i8* %14
%15 = load i32, i32* %2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %74
17: ; preds = %1
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%19 = load i32, i32* %2
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 1, i32* %5
%21 = load i32, i32* %2
%22 = icmp sgt i32 %21, 9
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %26
26: ; preds = %23, %17
%27 = load i32, i32* %2
%28 = icmp sgt i32 %27, 99
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %29, %26
%33 = load i32, i32* %2
%34 = icmp sgt i32 %33, 999
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %38
38: ; preds = %35, %32
%39 = load i32, i32* %5
switch i32 %39, label %72 [
i32 4, label %40
i32 3, label %57
i32 2, label %62
i32 1, label %67
]
40: ; preds = %38
%41 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%42 = load i8, i8* %41
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 0
store i8 %42, i8* %44
%45 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%46 = load i8, i8* %45
%47 = load i8*, i8** %3
%48 = getelementptr inbounds i8, i8* %47, i64 1
store i8 %46, i8* %48
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%50 = load i8, i8* %49
%51 = load i8*, i8** %3
%52 = getelementptr inbounds i8, i8* %51, i64 2
store i8 %50, i8* %52
%53 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
%54 = load i8, i8* %53
%55 = load i8*, i8** %3
%56 = getelementptr inbounds i8, i8* %55, i64 3
store i8 %54, i8* %56
br label %73
57: ; preds = %38
%58 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%59 = load i8, i8* %58
%60 = load i8*, i8** %3
%61 = getelementptr inbounds i8, i8* %60, i64 3
store i8 %59, i8* %61
br label %62
62: ; preds = %38, %57
%63 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%64 = load i8, i8* %63
%65 = load i8*, i8** %3
%66 = getelementptr inbounds i8, i8* %65, i64 2
store i8 %64, i8* %66
br label %67
67: ; preds = %38, %62
%68 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%69 = load i8, i8* %68
%70 = load i8*, i8** %3
%71 = getelementptr inbounds i8, i8* %70, i64 1
store i8 %69, i8* %71
br label %73
72: ; preds = %38
br label %73
73: ; preds = %72, %67, %40
br label %74
74: ; preds = %73, %1
%75 = load i8*, i8** %3
ret i8* %75
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define noalias i8* @intToDisplay(i32 %0) {
%2 = alloca [4 x i8]
%3 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%4 = getelementptr inbounds i8, i8* %3, i64 1
%5 = getelementptr inbounds i8, i8* %3, i64 2
%6 = getelementptr inbounds i8, i8* %3, i64 3
%7 = icmp eq i32 %0, 0
%8 = bitcast i8* %3 to i32*
store i32 538976288, i32* %8
br i1 %7, label %37, label %9
9: ; preds = %1
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%11 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%12 = icmp sgt i32 %0, 9
%13 = select i1 %12, i32 2, i32 1
%14 = icmp sgt i32 %0, 99
%15 = zext i1 %14 to i32
%16 = add nuw nsw i32 %13, %15
%17 = icmp sgt i32 %0, 999
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %16, %18
switch i32 %19, label %36 [
i32 4, label %20
i32 3, label %28
i32 2, label %31
i32 1, label %34
]
20: ; preds = %9
%21 = load i8, i8* %10
store i8 %21, i8* %3
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
%23 = load i8, i8* %22
store i8 %23, i8* %4
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
%25 = load i8, i8* %24
store i8 %25, i8* %5
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
%27 = load i8, i8* %26
store i8 %27, i8* %6
br label %36
28: ; preds = %9
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
%30 = load i8, i8* %29
store i8 %30, i8* %6
br label %31
31: ; preds = %9, %28
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
%33 = load i8, i8* %32
store i8 %33, i8* %5
br label %34
34: ; preds = %9, %31
%35 = load i8, i8* %10
store i8 %35, i8* %4
br label %36
36: ; preds = %9, %34, %20
br label %37
37: ; preds = %36, %1
ret i8* %3
}