#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 */
char *malloc(int);
int /*<<< orphan*/ putchar(char);
void putNumber(int n) {
  char *buffer = malloc(20);
  int size = 0;
  if (n < 0) {
    putchar('-');
    n = -n;
  }
  while (n / 10) {
    *buffer = n % 10 + '0';
    buffer++;
    size++;
    n = n / 10;
  }
  *buffer = n + '0';
  size++;
  while (size != 0) {
    putchar(*buffer);
    buffer--;
    size--;
  }
}


x86 assembly (clang, -O0):
<putNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    115c <putNumber+0x3c>
mov    $0x2d,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1161 <putNumber+0x41>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     11b3 <putNumber+0x93>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1161 <putNumber+0x41>
mov    -0x4(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11fa <putNumber+0xda>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11ca <putNumber+0xaa>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putNumber>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x14,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %r14d,%r14d
js     114d <putNumber+0x2d>
cmp    $0xa,%r14d
jae    1160 <putNumber+0x40>
add    $0x30,%r14b
mov    %r14b,(%rbx)
mov    $0x1,%ebp
jmp    11b5 <putNumber+0x95>
mov    $0x2d,%edi
call   1030 <putchar@plt>
neg    %r14d
cmp    $0xa,%r14d
jb     113f <putNumber+0x1f>
mov    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movslq %r14d,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
lea    (%rcx,%rdx,1),%r14d
lea    (%r14,%r14,1),%esi
lea    (%rsi,%rsi,4),%esi
sub    %esi,%eax
add    $0x30,%al
mov    %al,(%rbx)
add    $0x1,%rbx
lea    (%rcx,%rdx,1),%eax
add    $0x9,%eax
add    $0xffffffff,%ebp
cmp    $0x12,%eax
ja     1170 <putNumber+0x50>
add    $0x30,%r14b
mov    %r14b,(%rbx)
test   %ebp,%ebp
je     11e3 <putNumber+0xc3>
neg    %ebp
movsbl %r14b,%edi
call   1030 <putchar@plt>
cmp    $0x1,%ebp
je     11e3 <putNumber+0xc3>
mov    $0x1,%r14d
sub    %ebp,%r14d
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl -0x1(%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbp
cmp    %ebp,%r14d
jne    11d0 <putNumber+0xb0>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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