#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 */

/* Variables and functions */
char *base36enc(unsigned long);
int /*<<< orphan*/ griddoor_free(char *);
char *griddoor_malloc(unsigned long);
char *memset(char *, int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ strcpy(char *, char *);
unsigned long strlen(char *);
char *ucaseConvLuToAlphanum(long unsigned int l) {
  long unsigned int sum = 36;
  for (long unsigned int len = 1;;) {
    if (l < sum) {
      char *str = base36enc(l);
      long unsigned int diff = len - strlen(str);
      if (!diff)
        return str;
      char *valtoret = griddoor_malloc(len + 1);
      if (!valtoret) {
        griddoor_free(str);
        return NULL;
      }
      strcpy(valtoret + diff, str);
      griddoor_free(str);
      return memset(valtoret, '0', diff);
    } else {
      l -= sum;
      sum *= 36;
      len++;
    }
  }
}


x86 assembly (clang, -O0):
<ucaseConvLuToAlphanum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x24,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1235 <ucaseConvLuToAlphanum+0xd5>
mov    -0x10(%rbp),%rdi
call   1040 <base36enc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ce <ucaseConvLuToAlphanum+0x6e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    125e <ucaseConvLuToAlphanum+0xfe>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1060 <griddoor_malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1200 <ucaseConvLuToAlphanum+0xa0>
mov    -0x28(%rbp),%rdi
call   1080 <griddoor_free@plt>
movq   $0x0,-0x8(%rbp)
jmp    125e <ucaseConvLuToAlphanum+0xfe>
mov    -0x38(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1080 <griddoor_free@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    $0x30,%esi
call   1070 <memset@plt>
mov    %rax,-0x8(%rbp)
jmp    125e <ucaseConvLuToAlphanum+0xfe>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
imul   $0x24,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117c <ucaseConvLuToAlphanum+0x1c>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ucaseConvLuToAlphanum>:
push   %r15
push   %r14
push   %rbx
mov    $0x1,%ebx
cmp    $0x24,%rdi
jb     1194 <ucaseConvLuToAlphanum+0x34>
mov    $0x1,%ebx
mov    $0x24,%eax
nopw   0x0(%rax,%rax,1)
sub    %rax,%rdi
shl    $0x2,%rax
lea    (%rax,%rax,8),%rax
add    $0x1,%rbx
cmp    %rax,%rdi
jae    1180 <ucaseConvLuToAlphanum+0x20>
call   1040 <base36enc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %rbx,%r15
sub    %rax,%r15
je     11f6 <ucaseConvLuToAlphanum+0x96>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1060 <griddoor_malloc@plt>
test   %rax,%rax
je     11eb <ucaseConvLuToAlphanum+0x8b>
mov    %rax,%rbx
mov    %rax,%rdi
add    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1080 <griddoor_free@plt>
mov    %rbx,%rdi
mov    $0x30,%esi
mov    %r15,%rdx
call   1070 <memset@plt>
mov    %rbx,%r14
jmp    11f6 <ucaseConvLuToAlphanum+0x96>
mov    %r14,%rdi
call   1080 <griddoor_free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ucaseConvLuToAlphanum(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
store i64 %0, i64* %3
store i64 36, i64* %4
store i64 1, i64* %5
br label %9
9: ; preds = %52, %1
%10 = load i64, i64* %3
%11 = load i64, i64* %4
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %44
13: ; preds = %9
%14 = load i64, i64* %3
%15 = call i8* @base36enc(i64 %14)
store i8* %15, i8** %6
%16 = load i64, i64* %5
%17 = load i8*, i8** %6
%18 = call i64 @strlen(i8* %17)
%19 = sub i64 %16, %18
store i64 %19, i64* %7
%20 = load i64, i64* %7
%21 = icmp ne i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %13
%23 = load i8*, i8** %6
store i8* %23, i8** %2
br label %53
24: ; preds = %13
%25 = load i64, i64* %5
%26 = add i64 %25, 1
%27 = call i8* @griddoor_malloc(i64 %26)
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = icmp ne i8* %28, null
br i1 %29, label %33, label %30
30: ; preds = %24
%31 = load i8*, i8** %6
%32 = call i32 @griddoor_free(i8* %31)
store i8* null, i8** %2
br label %53
33: ; preds = %24
%34 = load i8*, i8** %8
%35 = load i64, i64* %7
%36 = getelementptr inbounds i8, i8* %34, i64 %35
%37 = load i8*, i8** %6
%38 = call i32 @strcpy(i8* %36, i8* %37)
%39 = load i8*, i8** %6
%40 = call i32 @griddoor_free(i8* %39)
%41 = load i8*, i8** %8
%42 = load i64, i64* %7
%43 = call i8* @memset(i8* %41, i32 48, i64 %42)
store i8* %43, i8** %2
br label %53
44: ; preds = %9
%45 = load i64, i64* %4
%46 = load i64, i64* %3
%47 = sub i64 %46, %45
store i64 %47, i64* %3
%48 = load i64, i64* %4
%49 = mul i64 %48, 36
store i64 %49, i64* %4
%50 = load i64, i64* %5
%51 = add i64 %50, 1
store i64 %51, i64* %5
br label %52
52: ; preds = %44
br label %9
53: ; preds = %33, %30, %22
%54 = load i8*, i8** %2
ret i8* %54
}

LLVM IR (-O2):
define i8* @ucaseConvLuToAlphanum(i64 %0) {
%2 = icmp ult i64 %0, 36
br i1 %2, label %3, label %22
3: ; preds = %22, %1
%4 = phi i64 [ 1, %1 ], [ %28, %22 ]
%5 = phi i64 [ %0, %1 ], [ %26, %22 ]
%6 = tail call i8* @base36enc(i64 %5)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%8 = sub i64 %4, %7
%9 = icmp eq i64 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %3
%11 = add i64 %4, 1
%12 = tail call i8* @griddoor_malloc(i64 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @griddoor_free(i8* %6)
br label %20
16: ; preds = %10
%17 = getelementptr inbounds i8, i8* %12, i64 %8
%18 = tail call i32 @strcpy(i8* %17, i8* %6)
%19 = tail call i32 @griddoor_free(i8* %6)
tail call void @llvm.memset.p0i8.i64(i8* align 1 %12, i8 48, i64 %8, i1 false)
br label %20
20: ; preds = %14, %16, %3
%21 = phi i8* [ %6, %3 ], [ %12, %16 ], [ null, %14 ]
ret i8* %21
22: ; preds = %1, %22
%23 = phi i64 [ %26, %22 ], [ %0, %1 ]
%24 = phi i64 [ %27, %22 ], [ 36, %1 ]
%25 = phi i64 [ %28, %22 ], [ 1, %1 ]
%26 = sub i64 %23, %24
%27 = mul i64 %24, 36
%28 = add i64 %25, 1
%29 = icmp ult i64 %26, %27
br i1 %29, label %3, label %22
}