#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*/ itodec(int, char *);
int /*<<< orphan*/ itohex(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ itooct(int, char *);
char *itoa(int value, char *str, int base) {
  if (base < 2 || base > 36)
    return str;
  if (base == 10)
    itodec(value, str);
  else if (base == 8)
    itooct(value, str);
  else if (base == 0x10)
    itohex(value, str, 0);
  else {
  }
  return str;
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jl     1156 <itoa+0x26>
cmpl   $0x24,-0x1c(%rbp)
jle    1163 <itoa+0x33>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cd <itoa+0x9d>
cmpl   $0xa,-0x1c(%rbp)
jne    117e <itoa+0x4e>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <itodec@plt>
jmp    11c5 <itoa+0x95>
cmpl   $0x8,-0x1c(%rbp)
jne    1199 <itoa+0x69>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <itooct@plt>
jmp    11c0 <itoa+0x90>
cmpl   $0x10,-0x1c(%rbp)
jne    11b6 <itoa+0x86>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <itohex@plt>
jmp    11bb <itoa+0x8b>
jmp    11bb <itoa+0x8b>
jmp    11c0 <itoa+0x90>
jmp    11c5 <itoa+0x95>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %rbx
mov    %rsi,%rbx
lea    -0x25(%rdx),%eax
cmp    $0xffffffdd,%eax
jb     1169 <itoa+0x39>
cmp    $0x8,%edx
je     1155 <itoa+0x25>
cmp    $0x10,%edx
je     115f <itoa+0x2f>
cmp    $0xa,%edx
jne    1169 <itoa+0x39>
mov    %rbx,%rsi
call   1030 <itodec@plt>
jmp    1169 <itoa+0x39>
mov    %rbx,%rsi
call   1050 <itooct@plt>
jmp    1169 <itoa+0x39>
mov    %rbx,%rsi
xor    %edx,%edx
call   1040 <itohex@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @itoa(i32 %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = icmp slt i32 %8, 2
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 36
br i1 %12, label %13, label %15
13: ; preds = %10, %3
%14 = load i8*, i8** %6
store i8* %14, i8** %4
br label %41
15: ; preds = %10
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 10
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* %5
%20 = load i8*, i8** %6
%21 = call i32 @itodec(i32 %19, i8* %20)
br label %39
22: ; preds = %15
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 8
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* %5
%27 = load i8*, i8** %6
%28 = call i32 @itooct(i32 %26, i8* %27)
br label %38
29: ; preds = %22
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 16
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* %5
%34 = load i8*, i8** %6
%35 = call i32 @itohex(i32 %33, i8* %34, i32 0)
br label %37
36: ; preds = %29
br label %37
37: ; preds = %36, %32
br label %38
38: ; preds = %37, %25
br label %39
39: ; preds = %38, %18
%40 = load i8*, i8** %6
store i8* %40, i8** %4
br label %41
41: ; preds = %39, %13
%42 = load i8*, i8** %4
ret i8* %42
}

LLVM IR (-O2):
define i8* @itoa(i32 %0, i8* returned %1, i32 %2) {
%4 = add i32 %2, -37
%5 = icmp ult i32 %4, -35
br i1 %5, label %13, label %6
6: ; preds = %3
switch i32 %2, label %13 [
i32 10, label %7
i32 8, label %9
i32 16, label %11
]
7: ; preds = %6
%8 = tail call i32 @itodec(i32 %0, i8* %1)
br label %13
9: ; preds = %6
%10 = tail call i32 @itooct(i32 %0, i8* %1)
br label %13
11: ; preds = %6
%12 = tail call i32 @itohex(i32 %0, i8* %1, i32 0)
br label %13
13: ; preds = %7, %11, %9, %6, %3
ret i8* %1
}