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

/* Variables and functions */
int /*<<< orphan*/ putchar(char);
int print_uint(uint32_t u) {
  int char_count = 0;
  unsigned int divisor = 10E+8;
  while (u / divisor == 0) {
    divisor /= 10;
    if (divisor == 0) {
      divisor = 1;
      break;
    }
  }
  while (divisor != 0) {
    char digit = (u / divisor) % 10;
    putchar(digit + '0');
    ++char_count;
    if (divisor == 1) {
      divisor = 0;
      continue;
    }
    divisor /= 10;
    if (divisor == 0)
      divisor = 1;
  }
  return char_count;
}


x86 assembly (clang, -O0):
<print_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x3b9aca00,-0xc(%rbp)
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
cmp    $0x0,%eax
jne    1164 <print_uint+0x54>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    115f <print_uint+0x4f>
movl   $0x1,-0xc(%rbp)
jmp    1164 <print_uint+0x54>
jmp    1129 <print_uint+0x19>
jmp    1169 <print_uint+0x59>
cmpl   $0x0,-0xc(%rbp)
je     11dc <print_uint+0xcc>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %dl,%al
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11b7 <print_uint+0xa7>
movl   $0x0,-0xc(%rbp)
jmp    1169 <print_uint+0x59>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11d7 <print_uint+0xc7>
movl   $0x1,-0xc(%rbp)
jmp    1169 <print_uint+0x59>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_uint>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x3b9aca00,%ebp
cmp    $0x3b9ac9ff,%edi
ja     1195 <print_uint+0x85>
mov    $0x5f5e100,%ebp
cmp    $0x5f5e0ff,%r14d
ja     1195 <print_uint+0x85>
mov    $0x989680,%ebp
cmp    $0x98967f,%r14d
ja     1195 <print_uint+0x85>
mov    $0xf4240,%ebp
cmp    $0xf423f,%r14d
ja     1195 <print_uint+0x85>
mov    $0x186a0,%ebp
cmp    $0x1869f,%r14d
ja     1195 <print_uint+0x85>
mov    $0x2710,%ebp
cmp    $0x270f,%r14d
ja     1195 <print_uint+0x85>
mov    $0x3e8,%ebp
cmp    $0x3e7,%r14d
ja     1195 <print_uint+0x85>
mov    $0x64,%ebp
cmp    $0x63,%r14d
ja     1195 <print_uint+0x85>
xor    %eax,%eax
cmp    $0xa,%r14d
setae  %al
lea    (%rax,%rax,8),%ebp
add    $0x1,%ebp
mov    $0x1,%ecx
mov    $0xcccccccd,%r15d
jmp    11b9 <print_uint+0xa9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rbx),%ecx
mov    %eax,%ebp
test   %eax,%eax
je     11f9 <print_uint+0xe9>
mov    %ecx,%ebx
mov    %r14d,%eax
xor    %edx,%edx
div    %ebp
mov    %rax,%rcx
imul   %r15,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
or     $0x30,%al
movzbl %al,%edi
call   1030 <putchar@plt>
cmp    $0x1,%ebp
je     11f9 <print_uint+0xe9>
mov    $0x1,%eax
cmp    $0xa,%ebp
jb     11b0 <print_uint+0xa0>
mov    %ebp,%eax
imul   %r15,%rax
shr    $0x23,%rax
jmp    11b0 <print_uint+0xa0>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @print_uint(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 1000000000, i32* %4
br label %6
6: ; preds = %17, %1
%7 = load i32, i32* %2
%8 = load i32, i32* %4
%9 = udiv i32 %7, %8
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %6
%12 = load i32, i32* %4
%13 = udiv i32 %12, 10
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 1, i32* %4
br label %18
17: ; preds = %11
br label %6
18: ; preds = %16, %6
br label %19
19: ; preds = %44, %37, %18
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %45
22: ; preds = %19
%23 = load i32, i32* %2
%24 = load i32, i32* %4
%25 = udiv i32 %23, %24
%26 = urem i32 %25, 10
%27 = trunc i32 %26 to i8
store i8 %27, i8* %5
%28 = load i8, i8* %5
%29 = sext i8 %28 to i32
%30 = add nsw i32 %29, 48
%31 = trunc i32 %30 to i8
%32 = call i32 @putchar(i8 signext %31)
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %38
37: ; preds = %22
store i32 0, i32* %4
br label %19
38: ; preds = %22
%39 = load i32, i32* %4
%40 = udiv i32 %39, 10
store i32 %40, i32* %4
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %38
store i32 1, i32* %4
br label %44
44: ; preds = %43, %38
br label %19
45: ; preds = %19
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
define i32 @print_uint(i32 %0) {
%2 = icmp ult i32 %0, 1000000000
br i1 %2, label %3, label %20
3: ; preds = %1
%4 = icmp ult i32 %0, 100000000
br i1 %4, label %5, label %20
5: ; preds = %3
%6 = icmp ult i32 %0, 10000000
br i1 %6, label %7, label %20
7: ; preds = %5
%8 = icmp ult i32 %0, 1000000
br i1 %8, label %9, label %20
9: ; preds = %7
%10 = icmp ult i32 %0, 100000
br i1 %10, label %11, label %20
11: ; preds = %9
%12 = icmp ult i32 %0, 10000
br i1 %12, label %13, label %20
13: ; preds = %11
%14 = icmp ult i32 %0, 1000
br i1 %14, label %15, label %20
15: ; preds = %13
%16 = icmp ult i32 %0, 100
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = icmp ult i32 %0, 10
%19 = select i1 %18, i32 1, i32 10
br label %20
20: ; preds = %17, %1, %3, %5, %7, %9, %11, %13, %15
%21 = phi i32 [ 100, %15 ], [ 1000, %13 ], [ 10000, %11 ], [ 100000, %9 ], [ 1000000, %7 ], [ 10000000, %5 ], [ 100000000, %3 ], [ 1000000000, %1 ], [ %19, %17 ]
br label %22
22: ; preds = %20, %32
%23 = phi i32 [ %30, %32 ], [ 0, %20 ]
%24 = phi i32 [ %35, %32 ], [ %21, %20 ]
%25 = udiv i32 %0, %24
%26 = urem i32 %25, 10
%27 = trunc i32 %26 to i8
%28 = or i8 %27, 48
%29 = tail call i32 @putchar(i8 signext %28)
%30 = add nuw nsw i32 %23, 1
%31 = icmp eq i32 %24, 1
br i1 %31, label %37, label %32
32: ; preds = %22
%33 = udiv i32 %24, 10
%34 = icmp ult i32 %24, 10
%35 = select i1 %34, i32 1, i32 %33
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %22
37: ; preds = %22, %32
ret i32 %30
}