#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 *ft_chrjoin(char *, char);
int ft_strlen(char *);
char *ft_strnew(int);
char *ft_itobase(int n, char *str) {
  int base;
  static char *ret;
  ret = ft_strnew(1);
  base = ft_strlen(str);
  if (n < 0)
    n = n * -1;
  if (n >= base)
    ft_itobase(n / base, str);
  ret = ft_chrjoin(ret, str[(n % base)]);
  return (ret);
}


x86 assembly (clang, -O0):
<ft_itobase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
call   1040 <ft_strnew@plt>
mov    %rax,0x2ee8(%rip)
mov    -0x10(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    117d <ft_itobase+0x3d>
imul   $0xffffffff,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     119b <ft_itobase+0x5b>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1050 <ft_itobase@plt>
mov    0x2ea6(%rip),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    -0x20(%rbp),%rax
movslq %edx,%rcx
movsbl (%rax,%rcx,1),%esi
call   1060 <ft_chrjoin@plt>
mov    %rax,0x2e80(%rip)
mov    0x2e79(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_itobase>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
mov    $0x1,%edi
call   1040 <ft_strnew@plt>
mov    %rax,0x2eea(%rip)
mov    %r14,%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%ebp
mov    %r15d,%ebx
neg    %ebx
cmovs  %r15d,%ebx
cmp    %eax,%ebx
jl     1184 <ft_itobase+0x44>
mov    %ebx,%eax
cltd
idiv   %ebp
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <ft_itobase@plt>
mov    0x2ebd(%rip),%rdi
mov    %ebx,%eax
cltd
idiv   %ebp
movsbl (%r14,%rdx,1),%esi
call   1060 <ft_chrjoin@plt>
mov    %rax,0x2ea7(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ft_itobase.ret = internal global i8* null
define i8* @ft_itobase(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = call i8* @ft_strnew(i32 1)
store i8* %6, i8** @ft_itobase.ret
%7 = load i8*, i8** %4
%8 = call i32 @ft_strlen(i8* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* %3
%13 = mul nsw i32 %12, -1
store i32 %13, i32* %3
br label %14
14: ; preds = %11, %2
%15 = load i32, i32* %3
%16 = load i32, i32* %5
%17 = icmp sge i32 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* %3
%20 = load i32, i32* %5
%21 = sdiv i32 %19, %20
%22 = load i8*, i8** %4
%23 = call i8* @ft_itobase(i32 %21, i8* %22)
br label %24
24: ; preds = %18, %14
%25 = load i8*, i8** @ft_itobase.ret
%26 = load i8*, i8** %4
%27 = load i32, i32* %3
%28 = load i32, i32* %5
%29 = srem i32 %27, %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %26, i64 %30
%32 = load i8, i8* %31
%33 = call i8* @ft_chrjoin(i8* %25, i8 signext %32)
store i8* %33, i8** @ft_itobase.ret
%34 = load i8*, i8** @ft_itobase.ret
ret i8* %34
}

LLVM IR (-O2):
@ft_itobase.ret = internal unnamed_addr global i8* null
define i8* @ft_itobase(i32 %0, i8* %1) {
%3 = tail call i8* @ft_strnew(i32 1)
store i8* %3, i8** @ft_itobase.ret
%4 = tail call i32 @ft_strlen(i8* %1)
%5 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%6 = icmp slt i32 %5, %4
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = sdiv i32 %5, %4
%9 = tail call i8* @ft_itobase(i32 %8, i8* %1)
br label %10
10: ; preds = %7, %2
%11 = load i8*, i8** @ft_itobase.ret
%12 = srem i32 %5, %4
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %1, i64 %13
%15 = load i8, i8* %14
%16 = tail call i8* @ft_chrjoin(i8* %11, i8 signext %15)
store i8* %16, i8** @ft_itobase.ret
ret i8* %16
}