#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 uint32_t;

/* Variables and functions */
char *utoa32(uint32_t x) {
  static char buf[17];
  uint32_t i = 15;
  do {
    buf[i--] = (x % 10) + '0';
    x /= 10;
  } while (x > 0);
  return buf + i + 1;
}


x86 assembly (clang, -O0):
<utoa32>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0xf,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
movslq %eax,%rcx
lea    0x2eff(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     110e <utoa32+0xe>
movslq -0x8(%rbp),%rcx
lea    0x2ed9(%rip),%rax
add    %rcx,%rax
add    $0x1,%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<utoa32>:
lea    0x2f38(%rip),%rcx
movabs $0xf00000000,%rax
movabs $0xffffffff00000000,%r8
ff ff ff
nopl   0x0(%rax,%rax,1)
add    %r8,%rax
movslq %edi,%rsi
imul   $0x66666667,%rsi,%rdi
mov    %rdi,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rdi
add    %edx,%edi
lea    (%rdi,%rdi,1),%edx
lea    (%rdx,%rdx,4),%r9d
mov    %esi,%edx
sub    %r9d,%edx
add    $0x30,%dl
mov    %dl,(%rcx)
add    $0xffffffffffffffff,%rcx
cmp    $0x9,%esi
jg     1120 <utoa32+0x20>
sar    $0x20,%rax
lea    0x2ed1(%rip),%rcx
add    %rcx,%rax
add    $0x1,%rax
ret

LLVM IR (-O0):
@utoa32.buf = internal global [17 x i8] zeroinitializer
define i8* @utoa32(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 15, i32* %3
br label %4
4: ; preds = %15, %1
%5 = load i32, i32* %2
%6 = srem i32 %5, 10
%7 = add nsw i32 %6, 48
%8 = trunc i32 %7 to i8
%9 = load i32, i32* %3
%10 = add nsw i32 %9, -1
store i32 %10, i32* %3
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds [17 x i8], [17 x i8]* @utoa32.buf, i64 0, i64 %11
store i8 %8, i8* %12
%13 = load i32, i32* %2
%14 = sdiv i32 %13, 10
store i32 %14, i32* %2
br label %15
15: ; preds = %4
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 0
br i1 %17, label %4, label %18
18: ; preds = %15
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @utoa32.buf, i64 0, i64 0), i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
ret i8* %22
}

LLVM IR (-O2):
@utoa32.buf = internal global [17 x i8] zeroinitializer
define i8* @utoa32(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %8, %2 ], [ 15, %1 ]
%4 = phi i32 [ %10, %2 ], [ %0, %1 ]
%5 = srem i32 %4, 10
%6 = trunc i32 %5 to i8
%7 = add nsw i8 %6, 48
%8 = add i64 %3, -1
%9 = getelementptr inbounds [17 x i8], [17 x i8]* @utoa32.buf, i64 0, i64 %3
store i8 %7, i8* %9
%10 = sdiv i32 %4, 10
%11 = icmp sgt i32 %4, 9
br i1 %11, label %2, label %12
12: ; preds = %2
%13 = shl i64 %8, 32
%14 = ashr exact i64 %13, 32
%15 = getelementptr inbounds [17 x i8], [17 x i8]* @utoa32.buf, i64 0, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 1
ret i8* %16
}