#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*/ putch(char);
int /*<<< orphan*/ putsln(char *);
void putnum(int num) {
  int res = num;
  if (res == 0)
    putch('0');
  else {
    if (res < 0) {
      putch('-');
      res = -res;
    }
    char temp[10];
    int i = 0;
    do {
      if (i >= 9) {
        putsln("Error: Number too large - will only be 10 digits");
        break;
      }
      temp[i++] = res % 10 + '0';
      res /= 10;
    } while (res);
    while (--i >= 0) {
      putch(temp[i]);
    }
  }
}


x86 assembly (clang, -O0):
<putnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    114a <putnum+0x2a>
mov    $0x30,%edi
call   1040 <putch@plt>
jmp    11f0 <putnum+0xd0>
cmpl   $0x0,-0x8(%rbp)
jge    1166 <putnum+0x46>
mov    $0x2d,%edi
call   1040 <putch@plt>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x9,-0x18(%rbp)
jl     1188 <putnum+0x68>
lea    0xe82(%rip),%rdi
call   1030 <putsln@plt>
jmp    11c1 <putnum+0xa1>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x18(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
cltq
mov    %cl,-0x12(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    116d <putnum+0x4d>
jmp    11c6 <putnum+0xa6>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jl     11eb <putnum+0xcb>
movslq -0x18(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%edi
call   1040 <putch@plt>
jmp    11c6 <putnum+0xa6>
jmp    11f0 <putnum+0xd0>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putnum>:
test   %edi,%edi
je     133b <putnum+0x21b>
push   %rbp
push   %rbx
lea    -0x18(%rsp),%rsp
mov    %edi,%ebp
jns    113f <putnum+0x1f>
mov    $0x2d,%edi
call   1040 <putch@plt>
neg    %ebp
mov    %ebp,%eax
mov    $0xcccccccd,%edx
mov    %rax,%rcx
imul   %rdx,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %ebp,%edi
sub    %esi,%edi
or     $0x30,%dil
mov    %dil,0xe(%rsp)
mov    $0x1,%ebx
cmp    $0xa,%ebp
jb     1317 <putnum+0x1f7>
mov    %ecx,%esi
imul   %rdx,%rsi
shr    $0x23,%rsi
add    %esi,%esi
lea    (%rsi,%rsi,4),%edx
sub    %edx,%ecx
or     $0x30,%cl
mov    %cl,0xf(%rsp)
mov    $0x2,%ebx
cmp    $0x64,%ebp
jb     1317 <putnum+0x1f7>
imul   $0x51eb851f,%rax,%rdx
shr    $0x25,%rdx
mov    $0xcccccccd,%ecx
mov    %rdx,%rsi
imul   %rcx,%rsi
shr    $0x23,%rsi
add    %esi,%esi
lea    (%rsi,%rsi,4),%esi
sub    %esi,%edx
or     $0x30,%dl
mov    %dl,0x10(%rsp)
mov    $0x3,%ebx
cmp    $0x3e8,%ebp
jb     1317 <putnum+0x1f7>
imul   $0x10624dd3,%rax,%rdx
shr    $0x26,%rdx
mov    %rdx,%rsi
imul   %rcx,%rsi
shr    $0x23,%rsi
add    %esi,%esi
lea    (%rsi,%rsi,4),%ecx
sub    %ecx,%edx
or     $0x30,%dl
mov    %dl,0x11(%rsp)
mov    $0x4,%ebx
cmp    $0x2710,%ebp
jb     1317 <putnum+0x1f7>
mov    $0xd1b71759,%ecx
imul   %rax,%rcx
shr    $0x2d,%rcx
mov    $0xcccccccd,%edx
imul   %rcx,%rdx
shr    $0x23,%rdx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
or     $0x30,%cl
mov    %cl,0x12(%rsp)
mov    $0x5,%ebx
cmp    $0x186a0,%ebp
jb     1317 <putnum+0x1f7>
mov    %ebp,%ecx
shr    $0x5,%ecx
imul   $0xa7c5ac5,%rcx,%rcx
shr    $0x27,%rcx
imul   $0xcccd,%ecx,%edx
shr    $0x12,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
or     $0x30,%cl
mov    %cl,0x13(%rsp)
mov    $0x6,%ebx
cmp    $0xf4240,%ebp
jb     1317 <putnum+0x1f7>
imul   $0x431bde83,%rax,%rcx
shr    $0x32,%rcx
imul   $0xcccd,%ecx,%edx
shr    $0x12,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%ecx
or     $0x30,%cl
mov    %cl,0x14(%rsp)
mov    $0x7,%ebx
cmp    $0x989680,%ebp
jb     1317 <putnum+0x1f7>
imul   $0x6b5fca6b,%rax,%rcx
shr    $0x36,%rcx
movzbl %cl,%edx
imul   $0xcd,%edx,%edx
shr    $0xa,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%edx
sub    %dl,%cl
or     $0x30,%cl
mov    %cl,0x15(%rsp)
mov    $0x8,%ebx
cmp    $0x5f5e100,%ebp
jb     1317 <putnum+0x1f7>
imul   $0x55e63b89,%rax,%rax
shr    $0x39,%rax
imul   $0xcd,%eax,%ecx
shr    $0xa,%ecx
and    $0xfffffffe,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %cl,%al
or     $0x30,%al
mov    %al,0x16(%rsp)
mov    $0x9,%ebx
cmp    $0x3b9ac9ff,%ebp
jbe    1317 <putnum+0x1f7>
lea    0xcee(%rip),%rdi
call   1030 <putsln@plt>
add    $0x1,%rbx
nopl   0x0(%rax,%rax,1)
movsbl 0xc(%rsp,%rbx,1),%edi
call   1040 <putch@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1320 <putnum+0x200>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x30,%edi
jmp    1040 <putch@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"Error: Number too large - will only be 10 digits\00"
define void @putnum(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @putch(i8 signext 48)
br label %50
11: ; preds = %1
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i32 @putch(i8 signext 45)
%16 = load i32, i32* %3
%17 = sub nsw i32 0, %16
store i32 %17, i32* %3
br label %18
18: ; preds = %14, %11
store i32 0, i32* %5
br label %19
19: ; preds = %35, %18
%20 = load i32, i32* %5
%21 = icmp sge i32 %20, 9
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @putsln(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %38
24: ; preds = %19
%25 = load i32, i32* %3
%26 = srem i32 %25, 10
%27 = add nsw i32 %26, 48
%28 = trunc i32 %27 to i8
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %31
store i8 %28, i8* %32
%33 = load i32, i32* %3
%34 = sdiv i32 %33, 10
store i32 %34, i32* %3
br label %35
35: ; preds = %24
%36 = load i32, i32* %3
%37 = icmp ne i32 %36, 0
br i1 %37, label %19, label %38
38: ; preds = %35, %22
br label %39
39: ; preds = %43, %38
%40 = load i32, i32* %5
%41 = add nsw i32 %40, -1
store i32 %41, i32* %5
%42 = icmp sge i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %39
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = call i32 @putch(i8 signext %47)
br label %39
49: ; preds = %39
br label %50
50: ; preds = %49, %9
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"Error: Number too large - will only be 10 digits\00"
define void @putnum(i32 %0) {
%2 = alloca [10 x i8]
%3 = icmp eq i32 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @putch(i8 signext 48)
br label %88
6: ; preds = %1
%7 = icmp slt i32 %0, 0
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = tail call i32 @putch(i8 signext 45)
%10 = sub nsw i32 0, %0
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ %10, %8 ], [ %0, %6 ]
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%14 = urem i32 %12, 10
%15 = udiv i32 %12, 10
%16 = trunc i32 %14 to i8
%17 = or i8 %16, 48
store i8 %17, i8* %13
%18 = icmp ult i32 %12, 10
br i1 %18, label %78, label %21
19: ; preds = %71
%20 = tail call i32 @putsln(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %78
21: ; preds = %11
%22 = urem i32 %15, 10
%23 = trunc i32 %22 to i8
%24 = or i8 %23, 48
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 1
store i8 %24, i8* %25
%26 = icmp ult i32 %12, 100
br i1 %26, label %78, label %27
27: ; preds = %21
%28 = udiv i32 %12, 100
%29 = urem i32 %28, 10
%30 = trunc i32 %29 to i8
%31 = or i8 %30, 48
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 2
store i8 %31, i8* %32
%33 = icmp ult i32 %12, 1000
br i1 %33, label %78, label %34
34: ; preds = %27
%35 = udiv i32 %12, 1000
%36 = urem i32 %35, 10
%37 = trunc i32 %36 to i8
%38 = or i8 %37, 48
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 3
store i8 %38, i8* %39
%40 = icmp ult i32 %12, 10000
br i1 %40, label %78, label %41
41: ; preds = %34
%42 = udiv i32 %12, 10000
%43 = urem i32 %42, 10
%44 = trunc i32 %43 to i8
%45 = or i8 %44, 48
%46 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 4
store i8 %45, i8* %46
%47 = icmp ult i32 %12, 100000
br i1 %47, label %78, label %48
48: ; preds = %41
%49 = udiv i32 %12, 100000
%50 = trunc i32 %49 to i16
%51 = urem i16 %50, 10
%52 = trunc i16 %51 to i8
%53 = or i8 %52, 48
%54 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 5
store i8 %53, i8* %54
%55 = icmp ult i32 %12, 1000000
br i1 %55, label %78, label %56
56: ; preds = %48
%57 = udiv i32 %12, 1000000
%58 = trunc i32 %57 to i16
%59 = urem i16 %58, 10
%60 = trunc i16 %59 to i8
%61 = or i8 %60, 48
%62 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 6
store i8 %61, i8* %62
%63 = icmp ult i32 %12, 10000000
br i1 %63, label %78, label %64
64: ; preds = %56
%65 = udiv i32 %12, 10000000
%66 = trunc i32 %65 to i8
%67 = urem i8 %66, 10
%68 = or i8 %67, 48
%69 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 7
store i8 %68, i8* %69
%70 = icmp ult i32 %12, 100000000
br i1 %70, label %78, label %71
71: ; preds = %64
%72 = udiv i32 %12, 100000000
%73 = trunc i32 %72 to i8
%74 = urem i8 %73, 10
%75 = or i8 %74, 48
%76 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 8
store i8 %75, i8* %76
%77 = icmp ult i32 %12, 1000000000
br i1 %77, label %78, label %19
78: ; preds = %19, %71, %64, %56, %48, %41, %34, %27, %21, %11
%79 = phi i64 [ 9, %71 ], [ 8, %64 ], [ 7, %56 ], [ 6, %48 ], [ 5, %41 ], [ 4, %34 ], [ 3, %27 ], [ 2, %21 ], [ 1, %11 ], [ 9, %19 ]
br label %80
80: ; preds = %78, %80
%81 = phi i64 [ %82, %80 ], [ %79, %78 ]
%82 = add nsw i64 %81, -1
%83 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %82
%84 = load i8, i8* %83
%85 = tail call i32 @putch(i8 signext %84)
%86 = icmp ugt i64 %81, 1
br i1 %86, label %80, label %87
87: ; preds = %80
br label %88
88: ; preds = %87, %4
ret void
}