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

/* Variables and functions */
int /*<<< orphan*/ putstr(char *);
void putuint(unsigned int n) {
  char buf[8 * sizeof(unsigned int) + 1];
  char *ptr = &buf[sizeof(buf) - 1];
  *ptr = '\0';
  do {
    char c = '0' + (n % 10u);
    --ptr;
    *ptr = c;
    n /= 10u;
  } while (n != 0u);
  putstr(ptr);
}


x86 assembly (clang, -O0):
<putuint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x39(%rbp)
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
mov    -0x39(%rbp),%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    112e <putuint+0x1e>
mov    -0x38(%rbp),%rdi
call   1030 <putstr@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putuint>:
sub    $0x28,%rsp
mov    %edi,%ecx
lea    0x20(%rsp),%rdi
movb   $0x0,0x20(%rsp)
mov    $0xcccccccd,%r8d
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%edx
imul   %r8,%rdx
shr    $0x23,%rdx
lea    (%rdx,%rdx,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %ecx,%eax
sub    %esi,%eax
or     $0x30,%al
mov    %al,-0x1(%rdi)
add    $0xffffffffffffffff,%rdi
cmp    $0x9,%ecx
mov    %edx,%ecx
ja     1130 <putuint+0x20>
call   1030 <putstr@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
define void @putuint(i32 %0) {
%2 = alloca i32
%3 = alloca [33 x i8]
%4 = alloca i8*
%5 = alloca i8
store i32 %0, i32* %2
%6 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 32
store i8* %6, i8** %4
%7 = load i8*, i8** %4
store i8 0, i8* %7
br label %8
8: ; preds = %19, %1
%9 = load i32, i32* %2
%10 = urem i32 %9, 10
%11 = add i32 48, %10
%12 = trunc i32 %11 to i8
store i8 %12, i8* %5
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i32 -1
store i8* %14, i8** %4
%15 = load i8, i8* %5
%16 = load i8*, i8** %4
store i8 %15, i8* %16
%17 = load i32, i32* %2
%18 = udiv i32 %17, 10
store i32 %18, i32* %2
br label %19
19: ; preds = %8
%20 = load i32, i32* %2
%21 = icmp ne i32 %20, 0
br i1 %21, label %8, label %22
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i32 @putstr(i8* %23)
ret void
}

LLVM IR (-O2):
define void @putuint(i32 %0) {
%2 = alloca [33 x i8]
%3 = getelementptr inbounds [33 x i8], [33 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [33 x i8], [33 x i8]* %2, i64 0, i64 32
store i8 0, i8* %4
br label %5
5: ; preds = %5, %1
%6 = phi i8* [ %4, %1 ], [ %11, %5 ]
%7 = phi i32 [ %0, %1 ], [ %12, %5 ]
%8 = urem i32 %7, 10
%9 = trunc i32 %8 to i8
%10 = or i8 %9, 48
%11 = getelementptr inbounds i8, i8* %6, i64 -1
store i8 %10, i8* %11
%12 = udiv i32 %7, 10
%13 = icmp ult i32 %7, 10
br i1 %13, label %14, label %5
14: ; preds = %5
%15 = call i32 @putstr(i8* %11)
ret void
}