#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*/ ft_convert(long, char *, int, int);
scalar_t__ ft_len(long, int);
char *ft_strnew(int);
char *ft_itoa(long int n, int sys) {
  char *str;
  int sign;
  int i;
  sign = 0;
  i = 0;
  if (n < 0) {
    n *= -1;
    sign = 1;
    i++;
  }
  i += ft_len(n, sys);
  str = ft_strnew(i + 1);
  ft_convert(n, str, i, sys);
  if (sign == 1)
    str[0] = '-';
  return (str);
}


x86 assembly (clang, -O0):
<ft_itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    1171 <ft_itoa+0x41>
imul   $0xffffffffffffffff,-0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <ft_len@plt>
mov    %rax,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
add    $0x1,%edi
call   1040 <ft_strnew@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1050 <ft_convert@plt>
cmpl   $0x1,-0x1c(%rbp)
jne    11bd <ft_itoa+0x8d>
mov    -0x18(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_itoa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r13
mov    %rdi,%rbx
neg    %rbx
cmovs  %rdi,%rbx
mov    %rdi,%rbp
shr    $0x3f,%rbp
mov    %rbx,%rdi
call   1030 <ft_len@plt>
lea    (%rax,%rbp,1),%r12d
lea    (%rax,%rbp,1),%edi
add    $0x1,%edi
call   1040 <ft_strnew@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r12d,%edx
mov    %r14d,%ecx
call   1050 <ft_convert@plt>
test   %r13,%r13
jns    1186 <ft_itoa+0x56>
movb   $0x2d,(%r15)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @ft_itoa(i64 %0, i32 %1) {
%3 = icmp slt i64 %0, 0
%4 = sub nsw i64 0, %0
%5 = select i1 %3, i64 %4, i64 %0
%6 = lshr i64 %0, 63
%7 = trunc i64 %6 to i32
%8 = tail call i64 @ft_len(i64 %5, i32 %1)
%9 = trunc i64 %8 to i32
%10 = add i32 %9, %7
%11 = add nsw i32 %10, 1
%12 = tail call i8* @ft_strnew(i32 %11)
%13 = tail call i32 @ft_convert(i64 %5, i8* %12, i32 %10, i32 %1)
br i1 %3, label %14, label %15
14: ; preds = %2
store i8 45, i8* %12
br label %15
15: ; preds = %14, %2
ret i8* %12
}