#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*/ putchar(int);
void printf_int(int i) {
  if (i < 0) {
    putchar('-');
    i *= -1;
  }
  int f, d;
  f = 1;
  while ((i / f) > 0) {
    f *= 10;
  }
  f = f / 10;
  if (f == 0) {
    f = 1;
  }
  while (f > 0) {
    d = i / f;
    putchar('0' + d);
    i = i - d * f;
    f = f / 10;
  }
}


x86 assembly (clang, -O0):
<printf_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1136 <printf_int+0x26>
mov    $0x2d,%edi
call   1030 <putchar@plt>
imul   $0xffffffff,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
cmp    $0x0,%eax
jle    1159 <printf_int+0x49>
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    113d <printf_int+0x2d>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1178 <printf_int+0x68>
movl   $0x1,-0x8(%rbp)
jmp    117d <printf_int+0x6d>
cmpl   $0x0,-0x8(%rbp)
jle    11be <printf_int+0xae>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x30,%edi
call   1030 <putchar@plt>
mov    -0x4(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0x8(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    117d <printf_int+0x6d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf_int>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
test   %edi,%edi
js     1125 <printf_int+0x15>
jne    1131 <printf_int+0x21>
mov    $0x1,%ebx
xor    %ebp,%ebp
jmp    115c <printf_int+0x4c>
mov    $0x2d,%edi
call   1030 <putchar@plt>
neg    %ebp
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%ebx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
test   %eax,%eax
jg     1140 <printf_int+0x30>
cmp    $0xa,%ecx
mov    $0x1,%eax
cmovb  %eax,%ebx
mov    $0xcccccccd,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%eax
cltd
idiv   %ebx
lea    0x30(%rax),%edi
mov    %edx,%ebp
call   1030 <putchar@plt>
mov    %ebx,%eax
imul   %r14,%rax
shr    $0x23,%rax
cmp    $0x9,%ebx
mov    %eax,%ebx
ja     1170 <printf_int+0x60>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @printf_int(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i32 @putchar(i32 45)
%5 = sub nsw i32 0, %0
br label %8
6: ; preds = %1
%7 = icmp eq i32 %0, 0
br i1 %7, label %18, label %8
8: ; preds = %3, %6
%9 = phi i32 [ %5, %3 ], [ %0, %6 ]
br label %10
10: ; preds = %8, %10
%11 = phi i32 [ %12, %10 ], [ 1, %8 ]
%12 = mul nuw nsw i32 %11, 10
%13 = sdiv i32 %9, %12
%14 = icmp sgt i32 %13, 0
br i1 %14, label %10, label %15
15: ; preds = %10
%16 = icmp ult i32 %12, 10
%17 = select i1 %16, i32 1, i32 %11
br label %18
18: ; preds = %6, %15
%19 = phi i32 [ %9, %15 ], [ 0, %6 ]
%20 = phi i32 [ %17, %15 ], [ 1, %6 ]
br label %21
21: ; preds = %18, %21
%22 = phi i32 [ %28, %21 ], [ %19, %18 ]
%23 = phi i32 [ %29, %21 ], [ %20, %18 ]
%24 = sdiv i32 %22, %23
%25 = add nsw i32 %24, 48
%26 = tail call i32 @putchar(i32 %25)
%27 = mul nsw i32 %24, %23
%28 = srem i32 %22, %23
%29 = udiv i32 %23, 10
%30 = icmp ult i32 %23, 10
br i1 %30, label %31, label %21
31: ; preds = %21
ret void
}