#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
scalar_t__ malloc(int);
int snprintf(char *, int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *intToStr(uint32_t *env) {
  char dummy[1];
  int n = (int)*(int *)(env + 1);
  int siz = snprintf(dummy, sizeof dummy, "%d", n);
  char *s = (char *)malloc(siz * sizeof(char));
  sprintf(s, "%d", n);
  return s;
}


x86 assembly (clang, -O0):
<intToStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x10(%rbp)
lea    -0x9(%rbp),%rdi
mov    -0x10(%rbp),%ecx
mov    $0x1,%esi
lea    0xea7(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe7e(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intToStr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x4(%rdi),%ebp
lea    0xebe(%rip),%r14
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1030 <snprintf@plt>
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i8* @intToStr(i32* %0) {
%2 = alloca i32*
%3 = alloca [1 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32* %0, i32** %2
%7 = load i32*, i32** %2
%8 = getelementptr inbounds i32, i32* %7, i64 1
%9 = load i32, i32* %8
store i32 %9, i32* %4
%10 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%11 = load i32, i32* %4
%12 = call i32 @snprintf(i8* %10, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = load i32, i32* %4
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i8*, i8** %6
ret i8* %22
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i8* @intToStr(i32* nocapture %0) {
%2 = alloca [1 x i8]
%3 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds i32, i32* %0, i64 1
%5 = load i32, i32* %4
%6 = call i32 @snprintf(i8* %3, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %5)
ret i8* %8
}