#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 */
int /*<<< orphan*/ free(char *);
char *ft_memalloc(int);
char *ft_strdup(char *);
char *ft_llutoa_base(unsigned long long n, int base) {
  char *str;
  char *bases;
  char *head;
  bases = "0123456789abcdef";
  if (!(head = ft_memalloc(64)))
    return (0);
  str = head + 63;
  if (!n)
    *(--str) = '0';
  while (n) {
    *(--str) = bases[n % base];
    n /= base;
  }
  str = ft_strdup(str);
  free(head);
  return (str);
}


x86 assembly (clang, -O0):
<ft_llutoa_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    $0x40,%edi
call   1050 <ft_memalloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    116f <ft_llutoa_base+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    120b <ft_llutoa_base+0xdb>
mov    -0x30(%rbp),%rax
add    $0x3f,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <ft_llutoa_base+0x69>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x30,-0x1(%rax)
jmp    119e <ft_llutoa_base+0x6e>
cmpq   $0x0,-0x10(%rbp)
je     11ed <ft_llutoa_base+0xbd>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    -0x38(%rbp),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,-0x1(%rax)
movslq -0x14(%rbp),%rcx
mov    -0x10(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
jmp    119e <ft_llutoa_base+0x6e>
mov    -0x20(%rbp),%rdi
call   1040 <ft_strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_llutoa_base>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x40,%edi
call   1050 <ft_memalloc@plt>
test   %rax,%rax
je     119f <ft_llutoa_base+0x6f>
mov    %rax,%r14
mov    %rax,%rdi
test   %rbx,%rbx
je     11a3 <ft_llutoa_base+0x73>
add    $0x3f,%rdi
movslq %ebp,%rcx
lea    0xe9f(%rip),%rsi
jmp    118b <ft_llutoa_base+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rax
xor    %edx,%edx
div    %rcx
movzbl (%rdx,%rsi,1),%edx
mov    %dl,-0x1(%rdi)
add    $0xffffffffffffffff,%rdi
cmp    %rcx,%rbx
mov    %rax,%rbx
jb     11ac <ft_llutoa_base+0x7c>
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    1170 <ft_llutoa_base+0x40>
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
jmp    1178 <ft_llutoa_base+0x48>
xor    %eax,%eax
jmp    11bf <ft_llutoa_base+0x8f>
add    $0x3e,%rdi
movb   $0x30,0x3e(%r14)
call   1040 <ft_strdup@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789abcdef\00"
define i8* @ft_llutoa_base(i64 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i64 %0, i64* %4
store i32 %1, i32* %5
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = call i8* @ft_memalloc(i32 64)
store i8* %9, i8** %8
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i8* null, i8** %3
br label %44
12: ; preds = %2
%13 = load i8*, i8** %8
%14 = getelementptr inbounds i8, i8* %13, i64 63
store i8* %14, i8** %6
%15 = load i64, i64* %4
%16 = icmp ne i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = load i8*, i8** %6
%19 = getelementptr inbounds i8, i8* %18, i32 -1
store i8* %19, i8** %6
store i8 48, i8* %19
br label %20
20: ; preds = %17, %12
br label %21
21: ; preds = %24, %20
%22 = load i64, i64* %4
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %21
%25 = load i8*, i8** %7
%26 = load i64, i64* %4
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = urem i64 %26, %28
%30 = getelementptr inbounds i8, i8* %25, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i32 -1
store i8* %33, i8** %6
store i8 %31, i8* %33
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = load i64, i64* %4
%37 = udiv i64 %36, %35
store i64 %37, i64* %4
br label %21
38: ; preds = %21
%39 = load i8*, i8** %6
%40 = call i8* @ft_strdup(i8* %39)
store i8* %40, i8** %6
%41 = load i8*, i8** %8
%42 = call i32 @free(i8* %41)
%43 = load i8*, i8** %6
store i8* %43, i8** %3
br label %44
44: ; preds = %38, %11
%45 = load i8*, i8** %3
ret i8* %45
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
define i8* @ft_llutoa_base(i64 %0, i32 %1) {
%3 = tail call i8* @ft_memalloc(i32 64)
%4 = icmp eq i8* %3, null
br i1 %4, label %25, label %5
5: ; preds = %2
%6 = icmp eq i64 %0, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = getelementptr inbounds i8, i8* %3, i64 62
store i8 48, i8* %8
br label %21
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %3, i64 63
%11 = sext i32 %1 to i64
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ %0, %9 ], [ %19, %12 ]
%14 = phi i8* [ %10, %9 ], [ %18, %12 ]
%15 = urem i64 %13, %11
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %14, i64 -1
store i8 %17, i8* %18
%19 = udiv i64 %13, %11
%20 = icmp ult i64 %13, %11
br i1 %20, label %21, label %12
21: ; preds = %12, %7
%22 = phi i8* [ %8, %7 ], [ %18, %12 ]
%23 = tail call i8* @ft_strdup(i8* %22)
%24 = tail call i32 @free(i8* %3)
br label %25
25: ; preds = %2, %21
%26 = phi i8* [ %23, %21 ], [ null, %2 ]
ret i8* %26
}