#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 abs(int);
void user_itoa(int num, char s[]) {
  static int i;
  if (num / 10)
    user_itoa(num / 10, s);
  s[i++] = abs(num % 10) + '0';
  s[i] = '\0';
}


x86 assembly (clang, -O0):
<user_itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     1159 <user_itoa+0x39>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1040 <user_itoa@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <abs@plt>
movsbl %al,%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    0x2eb7(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2eac(%rip)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq 0x2e9b(%rip),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<user_itoa>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0x9(%rdi),%eax
movslq %edi,%rbx
cmp    $0x13,%eax
jb     114e <user_itoa+0x2e>
imul   $0x66666667,%rbx,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x22,%rdi
add    %eax,%edi
mov    %r14,%rsi
call   1040 <user_itoa@plt>
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    %ebx,%edi
call   1030 <abs@plt>
add    $0x30,%al
movslq 0x2ebb(%rip),%rcx
lea    0x1(%rcx),%rdx
mov    %edx,0x2eb1(%rip)
mov    %al,(%r14,%rcx,1)
movb   $0x0,0x1(%r14,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@user_itoa.i = internal unnamed_addr global i32 0
define void @user_itoa(i32 %0, i8* nocapture writeonly %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 @user_itoa(i32 %6, i8* %1)
br label %7
7: ; preds = %5, %2
%8 = srem i32 %0, 10
%9 = tail call signext i8 @abs(i32 %8)
%10 = add i8 %9, 48
%11 = load i32, i32* @user_itoa.i
%12 = add nsw i32 %11, 1
store i32 %12, i32* @user_itoa.i
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %10, i8* %14
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
store i8 0, i8* %16
ret void
}