#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 *);
void int2str(int n, char str[]) {
  int high = n / 10;
  if (high != 0)
    int2str(high, str);
  else
    str[0] = '\0';
  int low = n % 10;
  int len = strlen(str);
  str[len] = '0' + low;
  str[len + 1] = '\0';
}


x86 assembly (clang, -O0):
<int2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1158 <int2str+0x38>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <int2str@plt>
jmp    115f <int2str+0x3f>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int2str>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0x9(%rdi),%eax
movslq %edi,%rbx
cmp    $0x13,%eax
jae    1138 <int2str+0x18>
movb   $0x0,(%r14)
jmp    1154 <int2str+0x34>
imul   $0x66666667,%rbx,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x22,%rdi
add    %eax,%edi
mov    %r14,%rsi
call   1030 <int2str@plt>
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
add    $0x30,%bl
cltq
mov    %bl,(%r14,%rax,1)
movb   $0x0,0x1(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @int2str(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i32, i32* %3
%9 = sdiv i32 %8, 10
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* %5
%14 = load i8*, i8** %4
br label %18
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 0, i8* %17
br label %18
18: ; preds = %15, %12
%19 = load i32, i32* %3
%20 = srem i32 %19, 10
store i32 %20, i32* %6
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %7
%23 = load i32, i32* %6
%24 = add nsw i32 48, %23
%25 = trunc i32 %24 to i8
%26 = load i8*, i8** %4
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
%30 = load i8*, i8** %4
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 0, i8* %34
ret void
}

LLVM IR (-O2):
define void @int2str(i32 %0, i8* %1) {
%3 = add i32 %0, 9
%4 = icmp ult i32 %3, 19
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = sdiv i32 %0, 10
tail call void @int2str(i32 %6, i8* %1)
br label %8
7: ; preds = %2
store i8 0, i8* %1
br label %8
8: ; preds = %7, %5
%9 = srem i32 %0, 10
%10 = tail call i32 @strlen(i8* %1)
%11 = trunc i32 %9 to i8
%12 = add nsw i8 %11, 48
%13 = sext i32 %10 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %12, i8* %14
%15 = add nsw i32 %10, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 0, i8* %17
ret void
}