#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 long uint64_t;

/* Variables and functions */
char *_geohex_itoa_with_base(char *, size_t, unsigned int, long const);
char *_geohex_generate_hdec3_f(register char *p, size_t len, const uint64_t n) {
  if (p == NULL || len < 3L)
    return NULL;
  if (n < 10L) {
    if (n < 3L) {
      *p++ = '0';
      len--;
    }
    return _geohex_itoa_with_base(p, len, 3U, n);
  } else {
    return _geohex_generate_hdec3_f(
        _geohex_generate_hdec3_f(p, len - 2L, n / 10ULL), 4L, n % 10ULL);
  }
}


x86 assembly (clang, -O0):
<_geohex_generate_hdec3_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     114a <_geohex_generate_hdec3_f+0x2a>
cmpq   $0x3,-0x18(%rbp)
jae    1157 <_geohex_generate_hdec3_f+0x37>
movq   $0x0,-0x8(%rbp)
jmp    11eb <_geohex_generate_hdec3_f+0xcb>
cmpq   $0xa,-0x20(%rbp)
jge    11aa <_geohex_generate_hdec3_f+0x8a>
cmpq   $0x3,-0x20(%rbp)
jge    118b <_geohex_generate_hdec3_f+0x6b>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x30,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x3,%edx
call   1030 <_geohex_itoa_with_base@plt>
mov    %rax,-0x8(%rbp)
jmp    11eb <_geohex_generate_hdec3_f+0xcb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x2,%rsi
mov    -0x20(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
call   1040 <_geohex_generate_hdec3_f@plt>
mov    %rax,%rdi
mov    -0x20(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    $0x4,%esi
call   1040 <_geohex_generate_hdec3_f@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_geohex_generate_hdec3_f>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1176 <_geohex_generate_hdec3_f+0x56>
cmp    $0x3,%rsi
jb     1176 <_geohex_generate_hdec3_f+0x56>
mov    %rdx,%r14
movabs $0xcccccccccccccccd,%r15
cc cc cc
nopl   (%rax)
cmp    $0x9,%r14
jle    117e <_geohex_generate_hdec3_f+0x5e>
add    $0xfffffffffffffffe,%rsi
mov    %r14,%rax
mul    %r15
mov    %rdx,%rbx
shr    $0x3,%rbx
mov    %rbx,%rdx
call   1040 <_geohex_generate_hdec3_f@plt>
mov    %rax,%rdi
add    %rbx,%rbx
lea    (%rbx,%rbx,4),%rax
sub    %rax,%r14
mov    $0x4,%esi
test   %rdi,%rdi
jne    1140 <_geohex_generate_hdec3_f+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
cmp    $0x2,%r14
jg     118f <_geohex_generate_hdec3_f+0x6f>
movb   $0x30,(%rdi)
add    $0x1,%rdi
add    $0xffffffffffffffff,%rsi
mov    $0x3,%edx
mov    %r14,%rcx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <_geohex_itoa_with_base@plt>

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

LLVM IR (-O2):
define i8* @_geohex_generate_hdec3_f(i8* %0, i64 %1, i64 %2) {
%4 = icmp eq i8* %0, null
%5 = icmp ult i64 %1, 3
%6 = or i1 %4, %5
br i1 %6, label %27, label %7
7: ; preds = %3, %21
%8 = phi i64 [ %25, %21 ], [ %2, %3 ]
%9 = phi i64 [ 4, %21 ], [ %1, %3 ]
%10 = phi i8* [ %24, %21 ], [ %0, %3 ]
%11 = icmp slt i64 %8, 10
br i1 %11, label %12, label %21
12: ; preds = %7
%13 = icmp slt i64 %8, 3
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = getelementptr inbounds i8, i8* %10, i64 1
store i8 48, i8* %10
%16 = add i64 %9, -1
br label %17
17: ; preds = %14, %12
%18 = phi i8* [ %15, %14 ], [ %10, %12 ]
%19 = phi i64 [ %16, %14 ], [ %9, %12 ]
%20 = tail call i8* @_geohex_itoa_with_base(i8* %18, i64 %19, i32 3, i64 %8)
br label %27
21: ; preds = %7
%22 = add i64 %9, -2
%23 = udiv i64 %8, 10
%24 = tail call i8* @_geohex_generate_hdec3_f(i8* %10, i64 %22, i64 %23)
%25 = urem i64 %8, 10
%26 = icmp eq i8* %24, null
br i1 %26, label %27, label %7
27: ; preds = %21, %3, %17
%28 = phi i8* [ %20, %17 ], [ null, %3 ], [ null, %21 ]
ret i8* %28
}