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


x86 assembly (clang, -O0):
<print_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0xa,%esi
call   1030 <len@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    118a <print_dec+0x5a>
mov    $0x2d,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11e5 <print_dec+0xb5>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
movsbl %al,%eax
add    $0x30,%eax
movsbl %al,%edi
call   1040 <putchar@plt>
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1191 <print_dec+0x61>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_dec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r12d
mov    $0xa,%esi
call   1030 <len@plt>
mov    %eax,%r14d
lea    -0x1(%r14),%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %eax,%ebx
xor    %r15d,%r15d
test   %r12d,%r12d
js     1167 <print_dec+0x37>
test   %r14d,%r14d
jne    117f <print_dec+0x4f>
jmp    11df <print_dec+0xaf>
mov    $0x2d,%edi
call   1040 <putchar@plt>
neg    %r12d
mov    $0x1,%r15d
test   %r14d,%r14d
je     11df <print_dec+0xaf>
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%eax
cltd
idiv   %ebx
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
add    $0x30,%al
movsbl %al,%edi
call   1040 <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    1190 <print_dec+0x60>
add    %r15d,%r14d
mov    %r14d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @print_dec(i32 %0) {
%2 = tail call i32 @len(i32 %0, i32 10)
%3 = add i32 %2, -1
%4 = tail call i32 @pow(i32 10, i32 %3)
%5 = icmp slt i32 %0, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @putchar(i8 signext 45)
%8 = sub nsw i32 0, %0
br label %9
9: ; preds = %6, %1
%10 = phi i32 [ 1, %6 ], [ 0, %1 ]
%11 = phi i32 [ %8, %6 ], [ %0, %1 ]
%12 = icmp eq i32 %2, 0
br i1 %12, label %26, label %13
13: ; preds = %9, %13
%14 = phi i32 [ %21, %13 ], [ %4, %9 ]
%15 = phi i32 [ %22, %13 ], [ 0, %9 ]
%16 = sdiv i32 %11, %14
%17 = srem i32 %16, 10
%18 = trunc i32 %17 to i8
%19 = add nsw i8 %18, 48
%20 = tail call i32 @putchar(i8 signext %19)
%21 = sdiv i32 %14, 10
%22 = add nuw i32 %15, 1
%23 = icmp eq i32 %22, %2
br i1 %23, label %24, label %13
24: ; preds = %13
%25 = add i32 %2, %10
br label %26
26: ; preds = %24, %9
%27 = phi i32 [ %10, %9 ], [ %25, %24 ]
ret i32 %27
}