#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 size_t uint8_t;
typedef size_t uint64_t;

/* Variables and functions */
char *_geohex_itoa_with_base(register char *p, const size_t len,
                             const uint8_t base, const uint64_t n) {
  if (p == NULL || len < 2L)
    return NULL;
  if (n < base) {
    const static char chr[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    *p++ = chr[n];
    *p = '\0';
    return p;
  } else {
    return _geohex_itoa_with_base(
        _geohex_itoa_with_base(p, len - 1L, base, n / (uint64_t)base), 2L, base,
        n % (uint64_t)base);
  }
}


x86 assembly (clang, -O0):
<_geohex_itoa_with_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     113e <_geohex_itoa_with_base+0x2e>
cmpq   $0x2,-0x18(%rbp)
jae    114b <_geohex_itoa_with_base+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <_geohex_itoa_with_base+0xd4>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    118c <_geohex_itoa_with_base+0x7c>
mov    -0x28(%rbp),%rcx
lea    0xe9c(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e4 <_geohex_itoa_with_base+0xd4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
call   1030 <_geohex_itoa_with_base@plt>
mov    %rax,%rdi
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    %rdx,%rcx
mov    -0x30(%rbp),%rdx
mov    $0x2,%esi
call   1030 <_geohex_itoa_with_base@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_geohex_itoa_with_base>:
push   %r15
push   %r14
push   %rbx
xor    %r14d,%r14d
test   %rdi,%rdi
je     1195 <_geohex_itoa_with_base+0x85>
cmp    $0x2,%rsi
jb     1195 <_geohex_itoa_with_base+0x85>
mov    %rcx,%rbx
mov    %rdx,%r15
add    $0xffffffffffffffff,%rsi
xor    %r14d,%r14d
jmp    1163 <_geohex_itoa_with_base+0x53>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rax
xor    %edx,%edx
div    %r15
mov    %rax,%rcx
mov    %rdx,%rbx
mov    %r15,%rdx
call   1030 <_geohex_itoa_with_base@plt>
mov    %rax,%rdi
mov    $0x1,%esi
test   %rax,%rax
je     1195 <_geohex_itoa_with_base+0x85>
cmp    %r15,%rbx
jb     1181 <_geohex_itoa_with_base+0x71>
mov    %rbx,%rax
or     %r15,%rax
shr    $0x20,%rax
jne    1140 <_geohex_itoa_with_base+0x30>
mov    %ebx,%eax
xor    %edx,%edx
div    %r15d
mov    %eax,%ecx
mov    %edx,%ebx
jmp    114e <_geohex_itoa_with_base+0x3e>
lea    0xe78(%rip),%rax
mov    (%rbx,%rax,1),%al
lea    0x1(%rdi),%r14
mov    %al,(%rdi)
movb   $0x0,0x1(%rdi)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@_geohex_itoa_with_base.chr = internal constant [37 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i8* @_geohex_itoa_with_base(i8* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %4
%13 = load i64, i64* %7
%14 = icmp ult i64 %13, 2
br i1 %14, label %15, label %16
15: ; preds = %12, %4
store i8* null, i8** %5
br label %42
16: ; preds = %12
%17 = load i64, i64* %9
%18 = load i64, i64* %8
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i64, i64* %9
%22 = getelementptr inbounds [37 x i8], [37 x i8]* @_geohex_itoa_with_base.chr, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
store i8 %23, i8* %24
%26 = load i8*, i8** %6
store i8 0, i8* %26
%27 = load i8*, i8** %6
store i8* %27, i8** %5
br label %42
28: ; preds = %16
%29 = load i8*, i8** %6
%30 = load i64, i64* %7
%31 = sub i64 %30, 1
%32 = load i64, i64* %8
%33 = load i64, i64* %9
%34 = load i64, i64* %8
%35 = udiv i64 %33, %34
%36 = call i8* @_geohex_itoa_with_base(i8* %29, i64 %31, i64 %32, i64 %35)
%37 = load i64, i64* %8
%38 = load i64, i64* %9
%39 = load i64, i64* %8
%40 = urem i64 %38, %39
%41 = call i8* @_geohex_itoa_with_base(i8* %36, i64 2, i64 %37, i64 %40)
store i8* %41, i8** %5
br label %42
42: ; preds = %28, %20, %15
%43 = load i8*, i8** %5
ret i8* %43
}

LLVM IR (-O2):
@_geohex_itoa_with_base.chr = internal unnamed_addr constant [37 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i8* @_geohex_itoa_with_base(i8* %0, i64 %1, i64 %2, i64 %3) {
%5 = icmp eq i8* %0, null
%6 = icmp ult i64 %1, 2
%7 = or i1 %5, %6
br i1 %7, label %24, label %8
8: ; preds = %4
%9 = add i64 %1, -1
br label %10
10: ; preds = %8, %19
%11 = phi i64 [ %22, %19 ], [ %3, %8 ]
%12 = phi i64 [ 1, %19 ], [ %9, %8 ]
%13 = phi i8* [ %21, %19 ], [ %0, %8 ]
%14 = icmp ult i64 %11, %2
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = getelementptr inbounds [37 x i8], [37 x i8]* @_geohex_itoa_with_base.chr, i64 0, i64 %11
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %17, i8* %13
store i8 0, i8* %18
br label %24
19: ; preds = %10
%20 = udiv i64 %11, %2
%21 = tail call i8* @_geohex_itoa_with_base(i8* %13, i64 %12, i64 %2, i64 %20)
%22 = urem i64 %11, %2
%23 = icmp eq i8* %21, null
br i1 %23, label %24, label %10
24: ; preds = %19, %4, %15
%25 = phi i8* [ %18, %15 ], [ null, %4 ], [ null, %19 ]
ret i8* %25
}