#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 snprintf(char *, int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *make_intstr(int x) {
  static char scrap[128];
  char *str;
  int sz = snprintf(scrap, sizeof scrap, "%d", x);
  if (!(str = malloc(sz + 1)))
    return 0;
  sprintf(str, "%d", x);
  return str;
}


x86 assembly (clang, -O0):
<make_intstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
lea    0x2f0b(%rip),%rdi
mov    $0x80,%esi
lea    0xeaf(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    117f <make_intstr+0x4f>
movq   $0x0,-0x8(%rbp)
jmp    119a <make_intstr+0x6a>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe73(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_intstr>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0x2f14(%rip),%rdi
lea    0xebd(%rip),%rdx
mov    $0x80,%esi
mov    %ebp,%ecx
call   1030 <snprintf@plt>
lea    0x1(%rax),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1170 <make_intstr+0x40>
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@make_intstr.scrap = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @make_intstr(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @make_intstr.scrap, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = add nsw i32 %8, 1
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %1
store i8* null, i8** %2
br label %18
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = load i32, i32* %3
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i8*, i8** %4
store i8* %17, i8** %2
br label %18
18: ; preds = %13, %12
%19 = load i8*, i8** %2
ret i8* %19
}

LLVM IR (-O2):
@make_intstr.scrap = internal global [128 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define noalias i8* @make_intstr(i32 %0) {
%2 = tail call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @make_intstr.scrap, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = add nsw i32 %2, 1
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %8
8: ; preds = %1, %6
ret i8* %4
}