#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 abs(int);
int /*<<< orphan*/ putchar(char);
void printInt(int value) {
  if (value < 0)
    putchar('-');
  value = abs(value);
  if (value > 9999)
    value = 9999;
  int length = 0;
  char buffer[4];
  do {
    buffer[length++] = (value % 10) + '0';
    value /= 10;
  } while (value > 0);
  while (length > 0)
    putchar(buffer[--length]);
}


x86 assembly (clang, -O0):
<printInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    113f <printInt+0x1f>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    -0x4(%rbp),%edi
call   1040 <abs@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x270f,-0x4(%rbp)
jle    115e <printInt+0x3e>
movl   $0x270f,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x8(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
cltq
mov    %cl,-0xc(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1165 <printInt+0x45>
jmp    11a3 <printInt+0x83>
cmpl   $0x0,-0x8(%rbp)
jle    11c7 <printInt+0xa7>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cltq
movsbl -0xc(%rbp,%rax,1),%edi
call   1030 <putchar@plt>
jmp    11a3 <printInt+0x83>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printInt>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
test   %edi,%edi
jns    1124 <printInt+0x14>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    %ebx,%ecx
neg    %ecx
cmovs  %ebx,%ecx
cmp    $0x270f,%ecx
mov    $0x270f,%eax
cmovb  %ecx,%eax
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
lea    (%rax,%rax,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
add    $0x30,%sil
mov    %sil,0x4(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x9,%ecx
jg     1140 <printInt+0x30>
mov    %ebx,%r14d
add    $0xffffffffffffffff,%r14
add    $0x1,%ebx
nopl   (%rax)
mov    %r14d,%eax
movsbl 0x4(%rsp,%rax,1),%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%r14
cmp    $0x1,%ebx
jg     1180 <printInt+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @printInt(i32 %0) {
%2 = alloca [4 x i8]
%3 = icmp slt i32 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @putchar(i8 signext 45)
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%8 = icmp ult i32 %7, 9999
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%10 = select i1 %8, i32 %7, i32 9999
br label %11
11: ; preds = %6, %11
%12 = phi i64 [ %17, %11 ], [ 0, %6 ]
%13 = phi i32 [ %19, %11 ], [ %10, %6 ]
%14 = srem i32 %13, 10
%15 = trunc i32 %14 to i8
%16 = add nsw i8 %15, 48
%17 = add nuw i64 %12, 1
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %12
store i8 %16, i8* %18
%19 = sdiv i32 %13, 10
%20 = icmp sgt i32 %13, 9
br i1 %20, label %11, label %21
21: ; preds = %11
%22 = and i64 %17, 4294967295
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ %22, %21 ], [ %25, %23 ]
%25 = add nsw i64 %24, -1
%26 = and i64 %25, 4294967295
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = tail call i32 @putchar(i8 signext %28)
%30 = trunc i64 %24 to i32
%31 = icmp sgt i32 %30, 1
br i1 %31, label %23, label %32
32: ; preds = %23
ret void
}