#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 */
typedef int uint64_t;
typedef int uint32_t;

/* Variables and functions */
char *utoa32(int const);
char *utoa64(const uint64_t x) {
  static char buf[32 + 1];
  uint32_t a, b, i;
  if (x > 99999999) {
    a = x / 100000000;
    b = x % 100000000;
    i = 31;
    do {
      buf[i--] = (a % 10) + '0';
      a /= 10;
    } while (a > 0);
    if (b > 0) {
      i = 31 - 16;
      do {
        buf[i--] = (b % 10) + '0';
        b /= 10;
      } while (b > 0);
    }
    return buf + i + 1;
  } else
    return utoa32(x);
}


x86 assembly (clang, -O0):
<utoa64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x5f5e0ff,-0xc(%rbp)
jle    11f8 <utoa64+0xe8>
mov    -0xc(%rbp),%eax
mov    $0x5f5e100,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x5f5e100,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
movl   $0x1f,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
movslq %eax,%rcx
lea    0x2ed2(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jg     114b <utoa64+0x3b>
cmpl   $0x0,-0x14(%rbp)
jle    11dd <utoa64+0xcd>
movl   $0xf,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
movslq %eax,%rcx
lea    0x2e83(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     119a <utoa64+0x8a>
jmp    11dd <utoa64+0xcd>
movslq -0x18(%rbp),%rcx
lea    0x2e58(%rip),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1204 <utoa64+0xf4>
mov    -0xc(%rbp),%edi
call   1030 <utoa32@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utoa64>:
cmp    $0x5f5e100,%edi
jl     11bd <utoa64+0xad>
mov    %edi,%eax
imul   $0x55e63b89,%rax,%rdx
shr    $0x39,%rdx
imul   $0x5f5e100,%edx,%eax
sub    %eax,%edi
mov    $0x1f,%ecx
lea    0x2f03(%rip),%r8
nopl   (%rax)
movslq %edx,%rsi
imul   $0x66666667,%rsi,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x22,%rdx
add    %eax,%edx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%r9d
mov    %esi,%eax
sub    %r9d,%eax
add    $0x30,%al
mov    %al,(%rcx,%r8,1)
add    $0xffffffffffffffff,%rcx
cmp    $0x9,%esi
jg     1140 <utoa64+0x30>
test   %edi,%edi
je     11b2 <utoa64+0xa2>
mov    $0xf,%ecx
nopl   0x0(%rax,%rax,1)
movslq %edi,%rax
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rdi
add    %edx,%edi
lea    (%rdi,%rdi,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %eax,%esi
sub    %edx,%esi
add    $0x30,%sil
mov    %sil,(%rcx,%r8,1)
add    $0xffffffffffffffff,%rcx
cmp    $0x9,%eax
jg     1180 <utoa64+0x70>
movslq %ecx,%rax
add    %r8,%rax
add    $0x1,%rax
ret
jmp    1030 <utoa32@plt>

LLVM IR (-O0):
@utoa64.buf = internal global [33 x i8] zeroinitializer
define i8* @utoa64(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 99999999
br i1 %8, label %9, label %52
9: ; preds = %1
%10 = load i32, i32* %3
%11 = sdiv i32 %10, 100000000
store i32 %11, i32* %4
%12 = load i32, i32* %3
%13 = srem i32 %12, 100000000
store i32 %13, i32* %5
store i32 31, i32* %6
br label %14
14: ; preds = %25, %9
%15 = load i32, i32* %4
%16 = srem i32 %15, 10
%17 = add nsw i32 %16, 48
%18 = trunc i32 %17 to i8
%19 = load i32, i32* %6
%20 = add nsw i32 %19, -1
store i32 %20, i32* %6
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds [33 x i8], [33 x i8]* @utoa64.buf, i64 0, i64 %21
store i8 %18, i8* %22
%23 = load i32, i32* %4
%24 = sdiv i32 %23, 10
store i32 %24, i32* %4
br label %25
25: ; preds = %14
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 0
br i1 %27, label %14, label %28
28: ; preds = %25
%29 = load i32, i32* %5
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %47
31: ; preds = %28
store i32 15, i32* %6
br label %32
32: ; preds = %43, %31
%33 = load i32, i32* %5
%34 = srem i32 %33, 10
%35 = add nsw i32 %34, 48
%36 = trunc i32 %35 to i8
%37 = load i32, i32* %6
%38 = add nsw i32 %37, -1
store i32 %38, i32* %6
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds [33 x i8], [33 x i8]* @utoa64.buf, i64 0, i64 %39
store i8 %36, i8* %40
%41 = load i32, i32* %5
%42 = sdiv i32 %41, 10
store i32 %42, i32* %5
br label %43
43: ; preds = %32
%44 = load i32, i32* %5
%45 = icmp sgt i32 %44, 0
br i1 %45, label %32, label %46
46: ; preds = %43
br label %47
47: ; preds = %46, %28
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @utoa64.buf, i64 0, i64 0), i64 %49
%51 = getelementptr inbounds i8, i8* %50, i64 1
store i8* %51, i8** %2
br label %55
52: ; preds = %1
%53 = load i32, i32* %3
%54 = call i8* @utoa32(i32 %53)
store i8* %54, i8** %2
br label %55
55: ; preds = %52, %47
%56 = load i8*, i8** %2
ret i8* %56
}

LLVM IR (-O2):
@utoa64.buf = internal global [33 x i8] zeroinitializer
define i8* @utoa64(i32 %0) {
%2 = icmp sgt i32 %0, 99999999
br i1 %2, label %3, label %34
3: ; preds = %1
%4 = udiv i32 %0, 100000000
%5 = urem i32 %0, 100000000
br label %6
6: ; preds = %6, %3
%7 = phi i64 [ %12, %6 ], [ 31, %3 ]
%8 = phi i32 [ %14, %6 ], [ %4, %3 ]
%9 = srem i32 %8, 10
%10 = trunc i32 %9 to i8
%11 = add nsw i8 %10, 48
%12 = add i64 %7, -1
%13 = getelementptr inbounds [33 x i8], [33 x i8]* @utoa64.buf, i64 0, i64 %7
store i8 %11, i8* %13
%14 = sdiv i32 %8, 10
%15 = icmp sgt i32 %8, 9
br i1 %15, label %6, label %16
16: ; preds = %6
%17 = icmp eq i32 %5, 0
br i1 %17, label %28, label %18
18: ; preds = %16, %18
%19 = phi i64 [ %24, %18 ], [ 15, %16 ]
%20 = phi i32 [ %26, %18 ], [ %5, %16 ]
%21 = srem i32 %20, 10
%22 = trunc i32 %21 to i8
%23 = add nsw i8 %22, 48
%24 = add i64 %19, -1
%25 = getelementptr inbounds [33 x i8], [33 x i8]* @utoa64.buf, i64 0, i64 %19
store i8 %23, i8* %25
%26 = sdiv i32 %20, 10
%27 = icmp sgt i32 %20, 9
br i1 %27, label %18, label %28
28: ; preds = %18, %16
%29 = phi i64 [ %12, %16 ], [ %24, %18 ]
%30 = shl i64 %29, 32
%31 = ashr exact i64 %30, 32
%32 = getelementptr inbounds [33 x i8], [33 x i8]* @utoa64.buf, i64 0, i64 %31
%33 = getelementptr inbounds i8, i8* %32, i64 1
br label %36
34: ; preds = %1
%35 = tail call i8* @utoa32(i32 %0)
br label %36
36: ; preds = %34, %28
%37 = phi i8* [ %33, %28 ], [ %35, %34 ]
ret i8* %37
}