#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  intptr_t quot;
  size_t rem;
};
typedef TYPE_1__ div_t;

/* Variables and functions */
TYPE_1__ div(intptr_t, int);
int /*<<< orphan*/ strreverse(char *, char *);
void itoa(intptr_t value, char *str, int base) {
  static char num[] = "0123456789abcdefghijklmnopqrstuvwxyz";
  char *wstr = str;
  intptr_t sign;
  div_t res;
  if (base < 2 || base > 35) {
    *wstr = '\0';
    return;
  }
  if ((sign = value) < 0)
    value = -value;
  do {
    res = div(value, base);
    *wstr++ = num[res.rem];
  } while ((value = res.quot));
  if (sign < 0)
    *wstr++ = '-';
  *wstr = '\0';
  strreverse(str, wstr - 1);
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x14(%rbp)
jl     114f <itoa+0x2f>
cmpl   $0x23,-0x14(%rbp)
jle    115b <itoa+0x3b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    1206 <itoa+0xe6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jge    1177 <itoa+0x57>
xor    %eax,%eax
sub    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    117c <itoa+0x5c>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <div@plt>
mov    %rax,-0x48(%rbp)
mov    %rdx,-0x40(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
lea    0x2e95(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    117c <itoa+0x5c>
cmpq   $0x0,-0x28(%rbp)
jge    11ee <itoa+0xce>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2d,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <strreverse@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%r14
lea    -0x24(%r15),%eax
cmp    $0xffffffdd,%eax
ja     1146 <itoa+0x26>
movb   $0x0,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %rdi,%r12
mov    %rdi,%rax
neg    %rax
cmovs  %rdi,%rax
lea    0xea6(%rip),%r13
mov    %r14,%rbx
nopl   (%rax)
mov    %rax,%rdi
mov    %r15d,%esi
call   1040 <div@plt>
movzbl (%rdx,%r13,1),%ecx
mov    %cl,(%rbx)
add    $0x1,%rbx
test   %rax,%rax
jne    1160 <itoa+0x40>
test   %r12,%r12
jns    1187 <itoa+0x67>
movb   $0x2d,(%rbx)
add    $0x1,%rbx
movb   $0x0,(%rbx)
add    $0xffffffffffffffff,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <strreverse@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64 }
@itoa.num = internal global [37 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz\00"
define void @itoa(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.TYPE_3__
%10 = alloca %struct.TYPE_3__
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %5
store i8* %11, i8** %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 2
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 35
br i1 %16, label %17, label %19
17: ; preds = %14, %3
%18 = load i8*, i8** %7
store i8 0, i8* %18
br label %59
19: ; preds = %14
%20 = load i64, i64* %4
store i64 %20, i64* %8
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i64, i64* %4
%24 = sub nsw i64 0, %23
store i64 %24, i64* %4
br label %25
25: ; preds = %22, %19
br label %26
26: ; preds = %43, %25
%27 = load i64, i64* %4
%28 = load i32, i32* %6
%29 = call { i64, i64 } @div(i64 %27, i32 %28)
%30 = bitcast %struct.TYPE_3__* %10 to { i64, i64 }*
%31 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %30, i32 0, i32 0
%32 = extractvalue { i64, i64 } %29, 0
store i64 %32, i64* %31
%33 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %30, i32 0, i32 1
%34 = extractvalue { i64, i64 } %29, 1
store i64 %34, i64* %33
%35 = bitcast %struct.TYPE_3__* %9 to i8*
%36 = bitcast %struct.TYPE_3__* %10 to i8*
%37 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 1
%38 = load i64, i64* %37
%39 = getelementptr inbounds [37 x i8], [37 x i8]* @itoa.num, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %7
store i8 %40, i8* %41
br label %43
43: ; preds = %26
%44 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%45 = load i64, i64* %44
store i64 %45, i64* %4
%46 = icmp ne i64 %45, 0
br i1 %46, label %26, label %47
47: ; preds = %43
%48 = load i64, i64* %8
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i8*, i8** %7
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %7
store i8 45, i8* %51
br label %53
53: ; preds = %50, %47
%54 = load i8*, i8** %7
store i8 0, i8* %54
%55 = load i8*, i8** %5
%56 = load i8*, i8** %7
%57 = getelementptr inbounds i8, i8* %56, i64 -1
%58 = call i32 @strreverse(i8* %55, i8* %57)
br label %59
59: ; preds = %53, %17
ret void
}

LLVM IR (-O2):
@itoa.num = internal unnamed_addr constant [37 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz\00"
define void @itoa(i64 %0, i8* %1, i32 %2) {
%4 = add i32 %2, -36
%5 = icmp ult i32 %4, -34
br i1 %5, label %6, label %7
6: ; preds = %3
store i8 0, i8* %1
br label %28
7: ; preds = %3
%8 = icmp slt i64 %0, 0
%9 = sub nsw i64 0, %0
%10 = select i1 %8, i64 %9, i64 %0
br label %11
11: ; preds = %11, %7
%12 = phi i8* [ %1, %7 ], [ %19, %11 ]
%13 = phi i64 [ %10, %7 ], [ %15, %11 ]
%14 = tail call { i64, i64 } @div(i64 %13, i32 %2)
%15 = extractvalue { i64, i64 } %14, 0
%16 = extractvalue { i64, i64 } %14, 1
%17 = getelementptr inbounds [37 x i8], [37 x i8]* @itoa.num, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %18, i8* %12
%20 = icmp eq i64 %15, 0
br i1 %20, label %21, label %11
21: ; preds = %11
br i1 %8, label %22, label %24
22: ; preds = %21
%23 = getelementptr inbounds i8, i8* %12, i64 2
store i8 45, i8* %19
br label %24
24: ; preds = %22, %21
%25 = phi i8* [ %23, %22 ], [ %19, %21 ]
store i8 0, i8* %25
%26 = getelementptr inbounds i8, i8* %25, i64 -1
%27 = tail call i32 @strreverse(i8* %1, i8* %26)
br label %28
28: ; preds = %24, %6
ret void
}