#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 quot;
  scalar_t__ rem;
};
typedef TYPE_1__ ldiv_t;

/* Variables and functions */
int /*<<< orphan*/ labs(long);
TYPE_1__ ldiv(int /*<<< orphan*/, int);
char *pptcapi_ltoa(long val, char *buf, int base) {
  ldiv_t r;
  if (base > 36 || base < 2) {
    *buf = '\0';
    return buf;
  }
  if (val < 0)
    *buf++ = '-';
  r = ldiv(labs(val), base);
  if (r.quot > 0)
    buf = pptcapi_ltoa(r.quot, buf, base);
  *buf++ = "0123456789abcdefghijklmnopqrstuvwxyz"[(int)r.rem];
  *buf = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<pptcapi_ltoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x24,-0x1c(%rbp)
jg     1157 <pptcapi_ltoa+0x27>
cmpl   $0x2,-0x1c(%rbp)
jge    116b <pptcapi_ltoa+0x3b>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1203 <pptcapi_ltoa+0xd3>
cmpq   $0x0,-0x10(%rbp)
jge    1188 <pptcapi_ltoa+0x58>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <labs@plt>
mov    %eax,%edi
mov    -0x1c(%rbp),%esi
call   1050 <ldiv@plt>
mov    %rax,-0x40(%rbp)
mov    %rdx,-0x38(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
jle    11d2 <pptcapi_ltoa+0xa2>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <pptcapi_ltoa@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
movslq %eax,%rcx
lea    0xe20(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pptcapi_ltoa>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
lea    -0x25(%r14),%eax
cmp    $0xffffffdd,%eax
jb     118b <pptcapi_ltoa+0x5b>
test   %rdi,%rdi
jns    1150 <pptcapi_ltoa+0x20>
movb   $0x2d,(%rbx)
add    $0x1,%rbx
call   1030 <labs@plt>
mov    %eax,%edi
mov    %r14d,%esi
call   1050 <ldiv@plt>
mov    %rdx,%r15
test   %rax,%rax
jle    1178 <pptcapi_ltoa+0x48>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <pptcapi_ltoa@plt>
mov    %rax,%rbx
movslq %r15d,%rax
lea    0xe7e(%rip),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,(%rbx)
add    $0x1,%rbx
movb   $0x0,(%rbx)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [37 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz\00"
define i8* @pptcapi_ltoa(i64 %0, i8* %1, i32 %2) {
%4 = add i32 %2, -37
%5 = icmp ult i32 %4, -35
br i1 %5, label %26, label %6
6: ; preds = %3
%7 = icmp slt i64 %0, 0
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = getelementptr inbounds i8, i8* %1, i64 1
store i8 45, i8* %1
br label %10
10: ; preds = %8, %6
%11 = phi i8* [ %9, %8 ], [ %1, %6 ]
%12 = tail call i32 @labs(i64 %0)
%13 = tail call { i64, i64 } @ldiv(i32 %12, i32 %2)
%14 = extractvalue { i64, i64 } %13, 0
%15 = extractvalue { i64, i64 } %13, 1
%16 = icmp sgt i64 %14, 0
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = tail call i8* @pptcapi_ltoa(i64 %14, i8* %11, i32 %2)
br label %19
19: ; preds = %17, %10
%20 = phi i8* [ %18, %17 ], [ %11, %10 ]
%21 = shl i64 %15, 32
%22 = ashr exact i64 %21, 32
%23 = getelementptr inbounds [37 x i8], [37 x i8]* @.str, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = getelementptr inbounds i8, i8* %20, i64 1
store i8 %24, i8* %20
br label %26
26: ; preds = %3, %19
%27 = phi i8* [ %25, %19 ], [ %1, %3 ]
store i8 0, i8* %27
ret i8* %27
}