#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 absInt(int);
int countDigits(int);
int /*<<< orphan*/ sysPrintString(char *, int, int, int);
int /*<<< orphan*/ sysWriteChar(char, int, int, int);
void sysPrintInt(int num, int B, int G, int R) {
  int dig = countDigits(num);
  char numbers[20] = {};
  int count = 0;
  int remainder;
  if (num < 0) {
    sysWriteChar('-', B, G, R);
  }
  while (count != dig) {
    remainder = absInt(num % 10);
    numbers[dig - 1 - count++] = remainder + 48;
    num /= 10;
  }
  numbers[dig] = '\0';
  sysPrintString(numbers, B, G, R);
}


x86 assembly (clang, -O0):
<sysPrintInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <countDigits@plt>
mov    %eax,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11a3 <sysPrintInt+0x53>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    $0x2d,%edi
call   1060 <sysWriteChar@plt>
jmp    11a8 <sysPrintInt+0x58>
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11fd <sysPrintInt+0xad>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1070 <absInt@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    -0x34(%rbp),%edx
mov    %edx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
sub    %edx,%eax
cltq
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    11a8 <sysPrintInt+0x58>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
call   1030 <sysPrintString@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysPrintInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%r12d
mov    %edi,%ebp
call   1040 <countDigits@plt>
mov    %eax,%r13d
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
test   %ebp,%ebp
js     117b <sysPrintInt+0x3b>
test   %r13d,%r13d
jne    1193 <sysPrintInt+0x53>
jmp    11d3 <sysPrintInt+0x93>
mov    $0x2d,%edi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1050 <sysWriteChar@plt>
test   %r13d,%r13d
je     11d3 <sysPrintInt+0x93>
mov    %r13d,%ebx
cs nopw 0x0(%rax,%rax,1)
movslq %ebp,%rdi
imul   $0x66666667,%rdi,%rbp
mov    %rbp,%rax
shr    $0x3f,%rax
sar    $0x22,%rbp
add    %eax,%ebp
lea    0x0(%rbp,%rbp,1),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
call   1060 <absInt@plt>
add    $0x30,%al
add    $0xffffffffffffffff,%rbx
movslq %ebx,%rcx
mov    %al,(%rsp,%rcx,1)
jne    11a0 <sysPrintInt+0x60>
movslq %r13d,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1030 <sysPrintString@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @sysPrintInt(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [20 x i8]
%6 = tail call i32 @countDigits(i32 %0)
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%8 = icmp slt i32 %0, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @sysWriteChar(i8 signext 45, i32 %1, i32 %2, i32 %3)
br label %11
11: ; preds = %9, %4
%12 = icmp eq i32 %6, 0
br i1 %12, label %30, label %13
13: ; preds = %11
%14 = zext i32 %6 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %23, %15 ]
%17 = phi i32 [ %0, %13 ], [ %28, %15 ]
%18 = trunc i64 %16 to i32
%19 = srem i32 %17, 10
%20 = tail call i32 @absInt(i32 %19)
%21 = trunc i32 %20 to i8
%22 = add i8 %21, 48
%23 = add nuw nsw i64 %16, 1
%24 = xor i32 %18, -1
%25 = add i32 %6, %24
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %26
store i8 %22, i8* %27
%28 = sdiv i32 %17, 10
%29 = icmp eq i64 %23, %14
br i1 %29, label %30, label %15
30: ; preds = %15, %11
%31 = sext i32 %6 to i64
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %31
store i8 0, i8* %32
%33 = call i32 @sysPrintString(i8* %7, i32 %1, i32 %2, i32 %3)
ret void
}