#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 */
int StrLen(char *);
char *StrRealloc(char *, int);
int StrSize(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *StrInt(char *d, int i) {
  int l;
  l = StrLen(d);
  if (l + 8 > StrSize(d) - 1) {
    d = StrRealloc(d, l + 9);
  }
  sprintf(d + l, "%d", i);
  return d;
}


x86 assembly (clang, -O0):
<StrInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <StrLen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <StrSize@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1190 <StrInt+0x50>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
add    $0x9,%esi
call   1030 <StrRealloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0xc(%rbp),%edx
lea    0xe5b(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StrInt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
call   1040 <StrLen@plt>
mov    %eax,%ebp
lea    0x8(%rbp),%r15d
mov    %rbx,%rdi
call   1050 <StrSize@plt>
cmp    %eax,%r15d
jl     1173 <StrInt+0x33>
lea    0x9(%rbp),%esi
mov    %rbx,%rdi
call   1030 <StrRealloc@plt>
mov    %rax,%rbx
movslq %ebp,%rdi
add    %rbx,%rdi
lea    0xe80(%rip),%rsi
mov    %r14d,%edx
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i8* @StrInt(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i32 @StrLen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = add nsw i32 %8, 8
%10 = load i8*, i8** %3
%11 = call i32 @StrSize(i8* %10)
%12 = sub nsw i32 %11, 1
%13 = icmp sgt i32 %9, %12
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 9
%18 = call i8* @StrRealloc(i8* %15, i32 %17)
store i8* %18, i8** %3
br label %19
19: ; preds = %14, %2
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i32, i32* %4
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i8* @StrInt(i8* %0, i32 %1) {
%3 = tail call i32 @StrLen(i8* %0)
%4 = add nsw i32 %3, 8
%5 = tail call i32 @StrSize(i8* %0)
%6 = icmp slt i32 %4, %5
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = add nsw i32 %3, 9
%9 = tail call i8* @StrRealloc(i8* %0, i32 %8)
br label %10
10: ; preds = %7, %2
%11 = phi i8* [ %9, %7 ], [ %0, %2 ]
%12 = sext i32 %3 to i64
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
ret i8* %11
}