#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 *allocateMemory(int const);
int /*<<< orphan*/ assert(int);
int snprintf(char *, int const, char *, int const);
char *getStringFromInt(const int number) {
  const int intLength = snprintf(NULL, 0, "%d", number);
  assert(intLength > 0);
  char *intString = allocateMemory(intLength + 1);
  const int stringLength = snprintf(intString, intLength + 1, "%d", number);
  assert(intString[intLength] == '\0');
  assert(stringLength == intLength);
  return intString;
}


x86 assembly (clang, -O0):
<getStringFromInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xeb5(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1050 <allocateMemory@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
mov    -0x4(%rbp),%ecx
lea    0xe79(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getStringFromInt>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r15d
lea    0xebe(%rip),%r14
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1030 <snprintf@plt>
mov    %eax,%ebx
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1040 <assert@plt>
lea    0x1(%rbx),%ebp
mov    %ebp,%edi
call   1050 <allocateMemory@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1030 <snprintf@plt>
mov    %eax,%ebp
movslq %ebx,%rbx
xor    %edi,%edi
cmpb   $0x0,(%r12,%rbx,1)
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmp    %ebx,%ebp
sete   %dil
call   1040 <assert@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i8* @getStringFromInt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
%14 = call i8* @allocateMemory(i32 %13)
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
%18 = load i32, i32* %2
%19 = call i32 @snprintf(i8* %15, i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 %19, i32* %5
%20 = load i8*, i8** %4
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i32, i32* %5
%30 = load i32, i32* %3
%31 = icmp eq i32 %29, %30
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i8*, i8** %4
ret i8* %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i8* @getStringFromInt(i32 %0) {
%2 = tail call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = icmp sgt i32 %2, 0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = add nsw i32 %2, 1
%7 = tail call i8* @allocateMemory(i32 %6)
%8 = tail call i32 @snprintf(i8* %7, i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = sext i32 %2 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = icmp eq i32 %8, %2
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
ret i8* %7
}