#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*/ tty_puts(char *);
void tty_put_ui32(unsigned int v) {
  char buff[11];
  int idx = 10;
  buff[idx] = 0;
  while (v >= 10) {
    buff[--idx] = '0' + (v % 10);
    v = v / 10;
  }
  buff[--idx] = '0' + v;
  tty_puts(&buff[idx]);
}


x86 assembly (clang, -O0):
<tty_put_ui32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xa,-0x14(%rbp)
movslq -0x14(%rbp),%rax
movb   $0x0,-0xf(%rbp,%rax,1)
cmpl   $0xa,-0x4(%rbp)
jb     1169 <tty_put_ui32+0x59>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cltq
mov    %cl,-0xf(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x4(%rbp)
jmp    112b <tty_put_ui32+0x1b>
mov    -0x4(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cltq
mov    %cl,-0xf(%rbp,%rax,1)
movslq -0x14(%rbp),%rax
lea    -0xf(%rbp),%rdi
add    %rax,%rdi
call   1030 <tty_puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_put_ui32>:
sub    $0x18,%rsp
movb   $0x0,0x17(%rsp)
mov    $0x9,%ecx
cmp    $0xa,%edi
jb     115a <tty_put_ui32+0x4a>
mov    $0x9,%eax
mov    $0xcccccccd,%r8d
xchg   %ax,%ax
mov    %edi,%ecx
mov    %edi,%edi
imul   %r8,%rdi
shr    $0x23,%rdi
lea    (%rdi,%rdi,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %ecx,%edx
sub    %esi,%edx
or     $0x30,%dl
cltq
mov    %dl,0xd(%rsp,%rax,1)
add    $0xffffffff,%eax
cmp    $0x63,%ecx
ja     1130 <tty_put_ui32+0x20>
movslq %eax,%rcx
add    $0x30,%dil
lea    (%rsp,%rcx,1),%rax
add    $0xd,%rax
mov    %dil,0xd(%rsp,%rcx,1)
mov    %rax,%rdi
call   1030 <tty_puts@plt>
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define void @tty_put_ui32(i32 %0) {
%2 = alloca [11 x i8]
%3 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 10
store i8 0, i8* %4
%5 = icmp ugt i32 %0, 9
br i1 %5, label %6, label %19
6: ; preds = %1, %6
%7 = phi i32 [ %15, %6 ], [ 9, %1 ]
%8 = phi i32 [ %14, %6 ], [ %0, %1 ]
%9 = urem i32 %8, 10
%10 = trunc i32 %9 to i8
%11 = or i8 %10, 48
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 %12
store i8 %11, i8* %13
%14 = udiv i32 %8, 10
%15 = add i32 %7, -1
%16 = icmp ugt i32 %8, 99
br i1 %16, label %6, label %17
17: ; preds = %6
%18 = sext i32 %15 to i64
br label %19
19: ; preds = %17, %1
%20 = phi i32 [ %0, %1 ], [ %14, %17 ]
%21 = phi i64 [ 9, %1 ], [ %18, %17 ]
%22 = trunc i32 %20 to i8
%23 = add nuw nsw i8 %22, 48
%24 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 %21
store i8 %23, i8* %24
%25 = call i32 @tty_puts(i8* %24)
ret void
}