#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*/ itoa2(long, char *, long, long *);
void print(long num, long base, long digits) {
  char *ptr, buffer[128];
  itoa2(num, buffer, base, &digits);
  ptr = buffer;
  while (*ptr) {
    *(volatile unsigned char *)0x20000000 = (unsigned char)(*ptr++);
    if (ptr[-1] == '\n')
      *--ptr = '\r';
  }
}


x86 assembly (clang, -O0):
<print>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1030 <itoa2@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1198 <print+0x88>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    $0x20000000,%eax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0xa,%eax
jne    1193 <print+0x83>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0xd,-0x1(%rax)
jmp    114a <print+0x3a>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print>:
push   %rbx
sub    $0x90,%rsp
mov    %rsi,%rax
mov    %rdx,0x8(%rsp)
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%rcx
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <itoa2@plt>
mov    0x10(%rsp),%al
test   %al,%al
jne    114b <print+0x3b>
jmp    1160 <print+0x50>
nop
add    $0x1,%rbx
movzbl (%rbx),%eax
test   %al,%al
je     1160 <print+0x50>
mov    %al,0x20000000
cmpb   $0xa,(%rbx)
jne    1140 <print+0x30>
movb   $0xd,(%rbx)
mov    $0xd,%al
test   %al,%al
jne    114b <print+0x3b>
add    $0x90,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @print(i64 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca [128 x i8]
store i64 %0, i64* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i64, i64* %4
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%11 = load i64, i64* %5
%12 = call i32 @itoa2(i64 %9, i8* %10, i64 %11, i64* %6)
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
store i8* %13, i8** %7
br label %14
14: ; preds = %30, %3
%15 = load i8*, i8** %7
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %7
%21 = load i8, i8* %19
store volatile i8 %21, i8* inttoptr (i64 536870912 to i8*)
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i64 -1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %30
27: ; preds = %18
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i32 -1
store i8* %29, i8** %7
store i8 13, i8* %29
br label %30
30: ; preds = %27, %18
br label %14
31: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @print(i64 %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca [128 x i8]
store i64 %2, i64* %4
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = call i32 @itoa2(i64 %0, i8* %6, i64 %1, i64* %4)
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %3, %19
%11 = phi i8 [ %20, %19 ], [ %8, %3 ]
%12 = phi i8* [ %21, %19 ], [ %6, %3 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
store volatile i8 %11, i8* inttoptr (i64 536870912 to i8*)
%14 = load i8, i8* %12
%15 = icmp eq i8 %14, 10
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = load i8, i8* %13
br label %19
18: ; preds = %10
store i8 13, i8* %12
br label %19
19: ; preds = %16, %18
%20 = phi i8 [ 13, %18 ], [ %17, %16 ]
%21 = phi i8* [ %12, %18 ], [ %13, %16 ]
%22 = icmp eq i8 %20, 0
br i1 %22, label %23, label %10
23: ; preds = %19, %3
ret void
}