#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 /*<<< orphan*/ reverse_string(char *, char *);
char *_uint2str(unsigned long val, char *out) {
  char *p = out;
  if (val == 0) {
    *p++ = '0';
    *p = 0;
  } else {
    while (val > 0) {
      *p++ = (val % 10) + '0';
      val /= 10;
    }
    *p = 0;
    reverse_string(out, p);
  }
  return p;
}


x86 assembly (clang, -O0):
<_uint2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1151 <_uint2str+0x41>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x30,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11b1 <_uint2str+0xa1>
jmp    1156 <_uint2str+0x46>
cmpq   $0x0,-0x8(%rbp)
jbe    119d <_uint2str+0x8d>
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
add    $0x30,%rdx
mov    %dl,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x8(%rbp)
jmp    1156 <_uint2str+0x46>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <reverse_string@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_uint2str>:
push   %rbx
test   %rdi,%rdi
je     1166 <_uint2str+0x56>
movabs $0xcccccccccccccccd,%r8
cc cc cc
mov    %rsi,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rdi,%rax
mul    %r8
shr    $0x3,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %edi,%ecx
sub    %eax,%ecx
or     $0x30,%cl
mov    %cl,(%rbx)
add    $0x1,%rbx
cmp    $0x9,%rdi
mov    %rdx,%rdi
ja     1130 <_uint2str+0x20>
movb   $0x0,(%rbx)
mov    %rsi,%rdi
mov    %rbx,%rsi
call   1030 <reverse_string@plt>
jmp    1172 <_uint2str+0x62>
movw   $0x30,(%rsi)
add    $0x1,%rsi
mov    %rsi,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @_uint2str(i64 %0, i8* %1) {
%3 = icmp eq i64 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %1, i64 1
store i8 48, i8* %1
store i8 0, i8* %5
br label %17
6: ; preds = %2, %6
%7 = phi i8* [ %12, %6 ], [ %1, %2 ]
%8 = phi i64 [ %13, %6 ], [ %0, %2 ]
%9 = urem i64 %8, 10
%10 = trunc i64 %9 to i8
%11 = or i8 %10, 48
%12 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %11, i8* %7
%13 = udiv i64 %8, 10
%14 = icmp ult i64 %8, 10
br i1 %14, label %15, label %6
15: ; preds = %6
store i8 0, i8* %12
%16 = tail call i32 @reverse_string(i8* %1, i8* %12)
br label %17
17: ; preds = %15, %4
%18 = phi i8* [ %5, %4 ], [ %12, %15 ]
ret i8* %18
}