#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 /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ write(int, char *, int);
void writeUInt(int fd, unsigned int val) {
  char buffer[32];
  char *ptr = &buffer[sizeof(buffer) - 1];
  do {
    *ptr-- = '0' + ((char)(val % 10));
    val /= 10;
  } while (val != 0);
  ++ptr;
  ;
  assert(ptr <= &buffer[sizeof(buffer)]);
  (void)write(fd, ptr, &buffer[sizeof(buffer)] - ptr);
}


x86 assembly (clang, -O0):
<writeUInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x30(%rbp),%rax
add    $0x1f,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %dl,%al
movsbl %al,%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    113a <writeUInt+0x1a>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
lea    -0x30(%rbp),%rcx
add    $0x20,%rcx
cmp    %rcx,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x4(%rbp),%edi
mov    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rax
add    $0x20,%rax
mov    -0x38(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <write@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeUInt>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
lea    0x20(%rsp),%rbx
xor    %ebp,%ebp
mov    $0xcccccccd,%eax
nopw   0x0(%rax,%rax,1)
mov    %esi,%ecx
imul   %rax,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %esi,%edi
sub    %edx,%edi
or     $0x30,%dil
mov    %dil,-0x1(%rbx)
add    $0xffffffffffffffff,%rbx
add    $0x1,%ebp
cmp    $0x9,%esi
mov    %ecx,%esi
ja     1140 <writeUInt+0x20>
lea    0x20(%rsp),%rax
xor    %edi,%edi
cmp    %rax,%rbx
setbe  %dil
call   1040 <assert@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @writeUInt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [32 x i8]
%6 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 31
store i8* %7, i8** %6
br label %8
8: ; preds = %19, %2
%9 = load i32, i32* %4
%10 = urem i32 %9, 10
%11 = trunc i32 %10 to i8
%12 = sext i8 %11 to i32
%13 = add nsw i32 48, %12
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i32 -1
store i8* %16, i8** %6
store i8 %14, i8* %15
%17 = load i32, i32* %4
%18 = udiv i32 %17, 10
store i32 %18, i32* %4
br label %19
19: ; preds = %8
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %8, label %22
22: ; preds = %19
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 32
%27 = icmp ule i8* %25, %26
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* %3
%31 = load i8*, i8** %6
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 32
%33 = load i8*, i8** %6
%34 = ptrtoint i8* %32 to i64
%35 = ptrtoint i8* %33 to i64
%36 = sub i64 %34, %35
%37 = trunc i64 %36 to i32
%38 = call i32 @write(i32 %30, i8* %31, i32 %37)
ret void
}

LLVM IR (-O2):
define void @writeUInt(i32 %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 31
br label %6
6: ; preds = %6, %2
%7 = phi i32 [ %1, %2 ], [ %13, %6 ]
%8 = phi i8* [ %5, %2 ], [ %12, %6 ]
%9 = urem i32 %7, 10
%10 = trunc i32 %9 to i8
%11 = or i8 %10, 48
%12 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 %11, i8* %8
%13 = udiv i32 %7, 10
%14 = icmp ult i32 %7, 10
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 32
%17 = icmp ule i8* %8, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = ptrtoint i8* %16 to i64
%21 = ptrtoint i8* %8 to i64
%22 = sub i64 %20, %21
%23 = trunc i64 %22 to i32
%24 = call i32 @write(i32 %0, i8* %8, i32 %23)
ret void
}