#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*/ aux(int, int, char *, int *);
scalar_t__ malloc(int);
char *ft_itoa_base(int value, int base) {
  char *ans;
  int p;
  if (base < 2 || 36 < base ||
      !(ans = (char *)malloc(sizeof(char) * (sizeof(int) * 8 + 1))))
    return (NULL);
  p = 0;
  if (value < 0)
    ans[p++] = '-';
  aux(value, base, ans, &p);
  ans[p] = '\0';
  return (ans);
}


x86 assembly (clang, -O0):
<ft_itoa_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x2,-0x10(%rbp)
jl     115e <ft_itoa_base+0x3e>
mov    $0x24,%eax
cmp    -0x10(%rbp),%eax
jl     115e <ft_itoa_base+0x3e>
mov    $0x21,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    116b <ft_itoa_base+0x4b>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <ft_itoa_base+0x99>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1192 <ft_itoa_base+0x72>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1040 <aux@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_itoa_base>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
lea    -0x25(%r14),%eax
cmp    $0xffffffdd,%eax
jb     117c <ft_itoa_base+0x5c>
mov    %edi,%ebp
mov    $0x21,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     117c <ft_itoa_base+0x5c>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
test   %ebp,%ebp
jns    115f <ft_itoa_base+0x3f>
movl   $0x1,0xc(%rsp)
movb   $0x2d,(%rbx)
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1040 <aux@plt>
movslq 0xc(%rsp),%rax
movb   $0x0,(%rbx,%rax,1)
jmp    117e <ft_itoa_base+0x5e>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @ft_itoa_base(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 2
br i1 %9, label %17, label %10
10: ; preds = %2
%11 = load i32, i32* %5
%12 = icmp slt i32 36, %11
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = call i64 @malloc(i32 33)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %13, %10, %2
store i8* null, i8** %3
br label %37
18: ; preds = %13
store i32 0, i32* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i8*, i8** %6
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 45, i8* %26
br label %27
27: ; preds = %21, %18
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = load i8*, i8** %6
%31 = call i32 @aux(i32 %28, i32 %29, i8* %30, i32* %7)
%32 = load i8*, i8** %6
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %6
store i8* %36, i8** %3
br label %37
37: ; preds = %27, %17
%38 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
define i8* @ft_itoa_base(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = add i32 %1, -37
%6 = icmp ult i32 %5, -35
br i1 %6, label %19, label %7
7: ; preds = %2
%8 = tail call i64 @malloc(i32 33)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %19, label %11
11: ; preds = %7
store i32 0, i32* %3
%12 = icmp slt i32 %0, 0
br i1 %12, label %13, label %14
13: ; preds = %11
store i32 1, i32* %3
store i8 45, i8* %9
br label %14
14: ; preds = %13, %11
%15 = call i32 @aux(i32 %0, i32 %1, i8* %9, i32* %3)
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %9, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %2, %7, %14
%20 = phi i8* [ %9, %14 ], [ null, %7 ], [ null, %2 ]
ret i8* %20
}