#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 pow(int, unsigned int const);
int /*<<< orphan*/ putchar(char);
unsigned int ulen(unsigned int const, int);
int print_udec(const unsigned int number) {
  unsigned int i, digit;
  const unsigned int ln = ulen(number, 10);
  int mult = pow(10, ln - 1);
  for (i = 0; i < ln; ++i) {
    digit = (number / mult) % 10;
    putchar((char)digit + 0x30);
    mult /= 10;
  }
  return ln;
}


x86 assembly (clang, -O0):
<print_udec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0xa,%esi
call   1040 <ulen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    11b2 <print_udec+0x82>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x14(%rbp)
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
movsbl %al,%eax
add    $0x30,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1165 <print_udec+0x35>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_udec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r12d
mov    $0xa,%esi
call   1040 <ulen@plt>
mov    %eax,%r14d
lea    -0x1(%r14),%esi
mov    $0xa,%edi
call   1050 <pow@plt>
cmp    $0x1,%r14d
jb     11af <print_udec+0x7f>
mov    %eax,%ebx
mov    $0xcccccccd,%r15d
mov    %r14d,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r12d,%eax
xor    %edx,%edx
div    %ebx
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>
movslq %ebx,%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
add    $0xffffffff,%ebp
jne    1170 <print_udec+0x40>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @print_udec(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @ulen(i32 %7, i32 10)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = sub i32 %9, 1
%11 = call i32 @pow(i32 10, i32 %10)
store i32 %11, i32* %6
store i32 0, i32* %3
br label %12
12: ; preds = %29, %1
%13 = load i32, i32* %3
%14 = load i32, i32* %5
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load i32, i32* %2
%18 = load i32, i32* %6
%19 = udiv i32 %17, %18
%20 = urem i32 %19, 10
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = trunc i32 %21 to i8
%23 = sext i8 %22 to i32
%24 = add nsw i32 %23, 48
%25 = trunc i32 %24 to i8
%26 = call i32 @putchar(i8 signext %25)
%27 = load i32, i32* %6
%28 = sdiv i32 %27, 10
store i32 %28, i32* %6
br label %29
29: ; preds = %16
%30 = load i32, i32* %3
%31 = add i32 %30, 1
store i32 %31, i32* %3
br label %12
32: ; preds = %12
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
define i32 @print_udec(i32 %0) {
%2 = tail call i32 @ulen(i32 %0, i32 10)
%3 = add i32 %2, -1
%4 = tail call i32 @pow(i32 10, i32 %3)
%5 = icmp eq i32 %2, 0
br i1 %5, label %17, label %6
6: ; preds = %1, %6
%7 = phi i32 [ %14, %6 ], [ %4, %1 ]
%8 = phi i32 [ %15, %6 ], [ 0, %1 ]
%9 = udiv i32 %0, %7
%10 = urem i32 %9, 10
%11 = trunc i32 %10 to i8
%12 = or i8 %11, 48
%13 = tail call i32 @putchar(i8 signext %12)
%14 = sdiv i32 %7, 10
%15 = add nuw i32 %8, 1
%16 = icmp eq i32 %15, %2
br i1 %16, label %17, label %6
17: ; preds = %6, %1
ret i32 %2
}