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


x86 assembly (clang, -O0):
<uart_print_num>:
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   1040 <itoa2@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a7 <uart_print_num+0x87>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%edi
call   1030 <uart_putchar@plt>
mov    -0x20(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0xa,%eax
jne    11a2 <uart_print_num+0x82>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0xd,-0x1(%rax)
jmp    115a <uart_print_num+0x3a>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_print_num>:
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   1040 <itoa2@plt>
mov    0x10(%rsp),%al
test   %al,%al
jne    115b <uart_print_num+0x3b>
jmp    1171 <uart_print_num+0x51>
nop
add    $0x1,%rbx
movzbl (%rbx),%eax
test   %al,%al
je     1171 <uart_print_num+0x51>
movsbl %al,%edi
call   1030 <uart_putchar@plt>
cmpb   $0xa,(%rbx)
jne    1150 <uart_print_num+0x30>
movb   $0xd,(%rbx)
mov    $0xd,%al
test   %al,%al
jne    115b <uart_print_num+0x3b>
add    $0x90,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @uart_print_num(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 = %32, %3
%15 = load i8*, i8** %7
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %33
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
%22 = sext i8 %21 to i32
%23 = call i32 @uart_putchar(i32 %22)
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i64 -1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 10
br i1 %28, label %29, label %32
29: ; preds = %18
%30 = load i8*, i8** %7
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %7
store i8 13, i8* %31
br label %32
32: ; preds = %29, %18
br label %14
33: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @uart_print_num(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 %25, label %10
10: ; preds = %3, %21
%11 = phi i8 [ %22, %21 ], [ %8, %3 ]
%12 = phi i8* [ %23, %21 ], [ %6, %3 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = sext i8 %11 to i32
%15 = call i32 @uart_putchar(i32 %14)
%16 = load i8, i8* %12
%17 = icmp eq i8 %16, 10
br i1 %17, label %20, label %18
18: ; preds = %10
%19 = load i8, i8* %13
br label %21
20: ; preds = %10
store i8 13, i8* %12
br label %21
21: ; preds = %18, %20
%22 = phi i8 [ 13, %20 ], [ %19, %18 ]
%23 = phi i8* [ %12, %20 ], [ %13, %18 ]
%24 = icmp eq i8 %22, 0
br i1 %24, label %25, label %10
25: ; preds = %21, %3
ret void
}