#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__ {
  long long quot;
  size_t rem;
};
typedef TYPE_1__ lldiv_t;

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


x86 assembly (clang, -O0):
<integer_to_char>:
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 <integer_to_char+0x2f>
cmpl   $0x23,-0x14(%rbp)
jle    115b <integer_to_char+0x3b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    1203 <integer_to_char+0xe3>
mov    -0x8(%rbp),%rax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1175 <integer_to_char+0x55>
xor    %eax,%eax
sub    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    117a <integer_to_char+0x5a>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <lldiv@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    0x2e97(%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    117a <integer_to_char+0x5a>
cmpl   $0x0,-0x24(%rbp)
jge    11eb <integer_to_char+0xcb>
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 <reverse_string@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<integer_to_char>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r14
lea    -0x24(%r12),%eax
cmp    $0xffffffdd,%eax
ja     1147 <integer_to_char+0x27>
movb   $0x0,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %rdi,%r15
mov    %rdi,%rax
neg    %rax
test   $0x80000000,%r15d
cmove  %rdi,%rax
lea    0xe9e(%rip),%r13
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rax,%rdi
mov    %r12d,%esi
call   1040 <lldiv@plt>
movzbl (%rdx,%r13,1),%ecx
mov    %cl,(%rbx)
add    $0x1,%rbx
test   %rax,%rax
jne    1170 <integer_to_char+0x50>
test   $0x80000000,%r15d
je     119b <integer_to_char+0x7b>
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 <reverse_string@plt>

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

LLVM IR (-O2):
@integer_to_char.num = internal unnamed_addr constant [37 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz\00"
define void @integer_to_char(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 %29
7: ; preds = %3
%8 = and i64 %0, 2147483648
%9 = icmp eq i64 %8, 0
%10 = sub nsw i64 0, %0
%11 = select i1 %9, i64 %0, i64 %10
br label %12
12: ; preds = %12, %7
%13 = phi i8* [ %1, %7 ], [ %20, %12 ]
%14 = phi i64 [ %11, %7 ], [ %16, %12 ]
%15 = tail call { i64, i64 } @lldiv(i64 %14, i32 %2)
%16 = extractvalue { i64, i64 } %15, 0
%17 = extractvalue { i64, i64 } %15, 1
%18 = getelementptr inbounds [37 x i8], [37 x i8]* @integer_to_char.num, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %19, i8* %13
%21 = icmp eq i64 %16, 0
br i1 %21, label %22, label %12
22: ; preds = %12
br i1 %9, label %25, label %23
23: ; preds = %22
%24 = getelementptr inbounds i8, i8* %13, i64 2
store i8 45, i8* %20
br label %25
25: ; preds = %23, %22
%26 = phi i8* [ %24, %23 ], [ %20, %22 ]
store i8 0, i8* %26
%27 = getelementptr inbounds i8, i8* %26, i64 -1
%28 = tail call i32 @reverse_string(i8* %1, i8* %27)
br label %29
29: ; preds = %25, %6
ret void
}