#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 putnumln(int num) {
  int res = num;
  if (res == 0)
    putch('0');
  else {
    if (res < 0) {
      putch('-');
      res = -res;
    }
    char temp[10];
    int i = 0;
    do {
      temp[i++] = res % 10 + '0';
      res /= 10;
    } while (res);
    while (--i >= 0) {
      putch(temp[i]);
    }
  }
  putsln("");
}


x86 assembly (clang, -O0):
<putnumln>:
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 <putnumln+0x2a>
mov    $0x30,%edi
call   1040 <putch@plt>
jmp    11d5 <putnumln+0xb5>
cmpl   $0x0,-0x8(%rbp)
jge    1166 <putnumln+0x46>
mov    $0x2d,%edi
call   1040 <putch@plt>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
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 <putnumln+0x4d>
jmp    11ab <putnumln+0x8b>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jl     11d0 <putnumln+0xb0>
movslq -0x18(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%edi
call   1040 <putch@plt>
jmp    11ab <putnumln+0x8b>
jmp    11d5 <putnumln+0xb5>
lea    0xe24(%rip),%rdi
call   1030 <putsln@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putnumln>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
je     11aa <putnumln+0x8a>
mov    %edi,%ebx
jns    113d <putnumln+0x1d>
mov    $0x2d,%edi
call   1040 <putch@plt>
neg    %ebx
xor    %r14d,%r14d
movslq %ebx,%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rbx
add    %ecx,%ebx
lea    (%rbx,%rbx,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
add    $0x30,%dl
mov    %dl,0x6(%rsp,%r14,1)
add    $0x1,%r14
add    $0x9,%eax
cmp    $0x12,%eax
ja     1140 <putnumln+0x20>
add    $0xffffffffffffffff,%r14
mov    %r14d,%eax
lea    (%rsp,%rax,1),%r15
add    $0x6,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1040 <putch@plt>
lea    -0x1(%rbx),%rax
add    %r14d,%ebx
test   %ebx,%ebx
mov    %rax,%rbx
jg     1190 <putnumln+0x70>
jmp    11b4 <putnumln+0x94>
mov    $0x30,%edi
call   1040 <putch@plt>
lea    0xe45(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putsln@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @putnumln(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 %45
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 = %30, %18
%20 = load i32, i32* %3
%21 = srem i32 %20, 10
%22 = add nsw i32 %21, 48
%23 = trunc i32 %22 to i8
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %26
store i8 %23, i8* %27
%28 = load i32, i32* %3
%29 = sdiv i32 %28, 10
store i32 %29, i32* %3
br label %30
30: ; preds = %19
%31 = load i32, i32* %3
%32 = icmp ne i32 %31, 0
br i1 %32, label %19, label %33
33: ; preds = %30
br label %34
34: ; preds = %38, %33
%35 = load i32, i32* %5
%36 = add nsw i32 %35, -1
store i32 %36, i32* %5
%37 = icmp sge i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = call i32 @putch(i8 signext %42)
br label %34
44: ; preds = %34
br label %45
45: ; preds = %44, %9
%46 = call i32 @putsln(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @putnumln(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 %36
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
br label %14
14: ; preds = %14, %11
%15 = phi i64 [ %20, %14 ], [ 0, %11 ]
%16 = phi i32 [ %22, %14 ], [ %12, %11 ]
%17 = srem i32 %16, 10
%18 = trunc i32 %17 to i8
%19 = add nsw i8 %18, 48
%20 = add nuw i64 %15, 1
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %15
store i8 %19, i8* %21
%22 = sdiv i32 %16, 10
%23 = add i32 %16, 9
%24 = icmp ult i32 %23, 19
br i1 %24, label %25, label %14
25: ; preds = %14
%26 = and i64 %15, 4294967295
br label %27
27: ; preds = %25, %27
%28 = phi i64 [ %26, %25 ], [ %32, %27 ]
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = tail call i32 @putch(i8 signext %30)
%32 = add nsw i64 %28, -1
%33 = trunc i64 %28 to i32
%34 = icmp sgt i32 %33, 0
br i1 %34, label %27, label %35
35: ; preds = %27
br label %36
36: ; preds = %35, %4
%37 = tail call i32 @putsln(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
ret void
}