#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 */
typedef int uint8_t;
typedef int uint16_t;

/* Variables and functions */
char *itoa(uint16_t number, uint8_t base) {
  if (!number) {
    return "0\r\n";
  }
  static char buf[16] = {0};
  register char i = 12;
  buf[14] = '\n';
  buf[13] = '\r';
  char m = 0;
  if (number < 0) {
    number = number * (-1);
    m = 1;
  }
  for (; number && i; --i, number /= base)
    buf[i] = "0123456789ABCDEF"[number % base];
  if (m) {
    buf[i] = '-';
    return &buf[i];
  } else {
    return &buf[i + 1];
  }
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1124 <itoa+0x24>
lea    0xee5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1206 <itoa+0x106>
movb   $0xc,-0x11(%rbp)
movb   $0xa,0x2f0f(%rip)
movb   $0xd,0x2f07(%rip)
movb   $0x0,-0x12(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    114f <itoa+0x4f>
imul   $0xffffffff,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
movb   $0x1,-0x12(%rbp)
jmp    1154 <itoa+0x54>
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x13(%rbp)
je     1170 <itoa+0x70>
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
test   $0x1,%al
jne    1180 <itoa+0x80>
jmp    11bc <itoa+0xbc>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
movslq %edx,%rcx
lea    0xe73(%rip),%rax
mov    (%rax,%rcx,1),%dl
movsbq -0x11(%rbp),%rcx
lea    0x2e90(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x11(%rbp),%al
add    $0xff,%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    1154 <itoa+0x54>
cmpb   $0x0,-0x12(%rbp)
je     11ee <itoa+0xee>
movsbq -0x11(%rbp),%rcx
lea    0x2e5e(%rip),%rax
movb   $0x2d,(%rax,%rcx,1)
movsbq -0x11(%rbp),%rcx
lea    0x2e4e(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    1206 <itoa+0x106>
movsbl -0x11(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2e31(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
test   %edi,%edi
je     1168 <itoa+0x68>
mov    %edi,%eax
neg    %eax
cmovs  %edi,%eax
movw   $0xa0d,0x2f29(%rip)
0d 0a
lea    0x2f21(%rip),%rcx
xor    %r9d,%r9d
lea    0xedf(%rip),%r8
cs nopw 0x0(%rax,%rax,1)
nop
cltd
idiv   %esi
movslq %edx,%rdx
movzbl (%rdx,%r8,1),%edx
mov    %dl,(%rcx)
lea    0x1(%r9),%rdx
add    $0xffffffffffffffff,%rcx
test   %eax,%eax
je     1152 <itoa+0x52>
cmp    $0xb,%r9
mov    %rdx,%r9
jne    1130 <itoa+0x30>
test   %edi,%edi
js     1170 <itoa+0x70>
lea    0x2ed3(%rip),%rcx
sub    %rdx,%rcx
add    $0xd,%rcx
mov    %rcx,%rax
ret
lea    0xe91(%rip),%rax
ret
movb   $0x2d,(%rcx)
mov    %rcx,%rax
ret

LLVM IR (-O0):
@.str = [4 x i8] c"0\0D\0A\00"
@itoa.buf = internal global [16 x i8] zeroinitializer
@.str.1 = [17 x i8] c"0123456789ABCDEF\00"
define i8* @itoa(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %3
br label %59
11: ; preds = %2
store i8 12, i8* %6
store i8 10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @itoa.buf, i64 0, i64 14)
store i8 13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @itoa.buf, i64 0, i64 13)
store i8 0, i8* %7
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %4
%16 = mul nsw i32 %15, -1
store i32 %16, i32* %4
store i8 1, i8* %7
br label %17
17: ; preds = %14, %11
br label %18
18: ; preds = %37, %17
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br label %25
25: ; preds = %21, %18
%26 = phi i1 [ false, %18 ], [ %24, %21 ]
br i1 %26, label %27, label %43
27: ; preds = %25
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = srem i32 %28, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.1, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = load i8, i8* %6
%35 = sext i8 %34 to i64
%36 = getelementptr inbounds [16 x i8], [16 x i8]* @itoa.buf, i64 0, i64 %35
store i8 %33, i8* %36
br label %37
37: ; preds = %27
%38 = load i8, i8* %6
%39 = add i8 %38, -1
store i8 %39, i8* %6
%40 = load i32, i32* %5
%41 = load i32, i32* %4
%42 = sdiv i32 %41, %40
store i32 %42, i32* %4
br label %18
43: ; preds = %25
%44 = load i8, i8* %7
%45 = icmp ne i8 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = load i8, i8* %6
%48 = sext i8 %47 to i64
%49 = getelementptr inbounds [16 x i8], [16 x i8]* @itoa.buf, i64 0, i64 %48
store i8 45, i8* %49
%50 = load i8, i8* %6
%51 = sext i8 %50 to i64
%52 = getelementptr inbounds [16 x i8], [16 x i8]* @itoa.buf, i64 0, i64 %51
store i8* %52, i8** %3
br label %59
53: ; preds = %43
%54 = load i8, i8* %6
%55 = sext i8 %54 to i32
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [16 x i8], [16 x i8]* @itoa.buf, i64 0, i64 %57
store i8* %58, i8** %3
br label %59
59: ; preds = %53, %46, %10
%60 = load i8*, i8** %3
ret i8* %60
}

LLVM IR (-O2):
@.str = [4 x i8] c"0\0D\0A\00"
@itoa.buf = internal global [16 x i8] zeroinitializer
@.str.1 = [17 x i8] c"0123456789ABCDEF\00"
define i8* @itoa(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %26, label %4
4: ; preds = %2
store i8 10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @itoa.buf, i64 0, i64 14)
store i8 13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @itoa.buf, i64 0, i64 13)
%5 = icmp slt i32 %0, 0
%6 = sub nsw i32 0, %0
%7 = select i1 %5, i32 %6, i32 %0
br label %8
8: ; preds = %4, %8
%9 = phi i64 [ 12, %4 ], [ %16, %8 ]
%10 = phi i32 [ %7, %4 ], [ %17, %8 ]
%11 = srem i32 %10, %1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [17 x i8], [17 x i8]* @.str.1, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = getelementptr inbounds [16 x i8], [16 x i8]* @itoa.buf, i64 0, i64 %9
store i8 %14, i8* %15
%16 = add nsw i64 %9, -1
%17 = sdiv i32 %10, %1
%18 = icmp ne i32 %17, 0
%19 = icmp ne i64 %16, 0
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %8, label %21
21: ; preds = %8
br i1 %5, label %22, label %24
22: ; preds = %21
%23 = getelementptr inbounds [16 x i8], [16 x i8]* @itoa.buf, i64 0, i64 %16
store i8 45, i8* %23
br label %26
24: ; preds = %21
%25 = getelementptr inbounds [16 x i8], [16 x i8]* @itoa.buf, i64 0, i64 %9
br label %26
26: ; preds = %22, %24, %2
%27 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %2 ], [ %23, %22 ], [ %25, %24 ]
ret i8* %27
}