#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*/ strrev(char *);
char *itoa(unsigned long long int x, char *buffer) {
  if (!x)
    return "0";
  char *c = buffer;
  while (x) {
    *c = x % 10 + '0';
    x = x / 10;
    c++;
  }
  *c = 0;
  strrev(buffer);
  return buffer;
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113b <itoa+0x2b>
lea    0xece(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <itoa+0x93>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118b <itoa+0x7b>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
add    $0x30,%rdx
mov    %dl,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1143 <itoa+0x33>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <strrev@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1163 <itoa+0x53>
mov    %rsi,%r14
movabs $0xcccccccccccccccd,%rsi
cc cc cc
mov    %r14,%rcx
nopl   0x0(%rax)
mov    %rdi,%rax
mul    %rsi
shr    $0x3,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %edi,%ebx
sub    %eax,%ebx
or     $0x30,%bl
mov    %bl,(%rcx)
add    $0x1,%rcx
cmp    $0x9,%rdi
mov    %rdx,%rdi
ja     1130 <itoa+0x20>
movb   $0x0,(%rcx)
mov    %r14,%rdi
call   1030 <strrev@plt>
jmp    116a <itoa+0x5a>
lea    0xe96(%rip),%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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