#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 ft_ll_len(long long);
char *ft_strdup(char *);
char *ft_strnew(int);
char *ft_lltoa(long long n) {
  char *s;
  int len;
  len = ft_ll_len(n);
  s = ft_strnew(len);
  if (n == 0)
    s[0] = '0';
  if (n < 0) {
    n = -n;
    if (n < 0)
      return (ft_strdup("-9223372036854775808"));
    s[0] = '-';
  }
  while (n) {
    --len;
    s[len] = '0' + n % 10;
    n /= 10;
  }
  return (s);
}


x86 assembly (clang, -O0):
<ft_lltoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ft_ll_len@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <ft_strnew@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1166 <ft_lltoa+0x36>
mov    -0x18(%rbp),%rax
movb   $0x30,(%rax)
cmpq   $0x0,-0x10(%rbp)
jge    11a2 <ft_lltoa+0x72>
xor    %eax,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    119b <ft_lltoa+0x6b>
lea    0xe73(%rip),%rdi
call   1040 <ft_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11f7 <ft_lltoa+0xc7>
mov    -0x18(%rbp),%rax
movb   $0x2d,(%rax)
jmp    11a7 <ft_lltoa+0x77>
cmpq   $0x0,-0x10(%rbp)
je     11ef <ft_lltoa+0xbf>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
add    $0x30,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
jmp    11a7 <ft_lltoa+0x77>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_lltoa>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <ft_ll_len@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <ft_strnew@plt>
mov    %rax,%rcx
mov    %rbx,%rsi
neg    %rsi
cmovs  %rbx,%rsi
test   %rbx,%rbx
jle    114d <ft_lltoa+0x2d>
test   %rsi,%rsi
jne    1160 <ft_lltoa+0x40>
jmp    11b4 <ft_lltoa+0x94>
setns  %al
movzbl %al,%eax
lea    (%rax,%rax,2),%eax
add    $0x2d,%eax
mov    %al,(%rcx)
test   %rsi,%rsi
je     11b4 <ft_lltoa+0x94>
movslq %ebp,%rax
lea    (%rax,%rcx,1),%rdi
add    $0xffffffffffffffff,%rdi
movabs $0x6666666666666667,%rbp
66 66 66
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rsi,%rax
imul   %rbp
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %esi,%ebx
sub    %eax,%ebx
add    $0x30,%bl
mov    %bl,(%rdi)
add    $0x9,%rsi
add    $0xffffffffffffffff,%rdi
cmp    $0x12,%rsi
mov    %rdx,%rsi
ja     1180 <ft_lltoa+0x60>
mov    %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"-9223372036854775808\00"
define i8* @ft_lltoa(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
store i64 %0, i64* %3
%6 = load i64, i64* %3
%7 = call i32 @ft_ll_len(i64 %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = call i8* @ft_strnew(i32 %8)
store i8* %9, i8** %4
%10 = load i64, i64* %3
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 48, i8* %14
br label %15
15: ; preds = %12, %1
%16 = load i64, i64* %3
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %15
%19 = load i64, i64* %3
%20 = sub nsw i64 0, %19
store i64 %20, i64* %3
%21 = load i64, i64* %3
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i8* @ft_strdup(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i8* %24, i8** %2
br label %47
25: ; preds = %18
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 45, i8* %27
br label %28
28: ; preds = %25, %15
br label %29
29: ; preds = %32, %28
%30 = load i64, i64* %3
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %29
%33 = load i32, i32* %5
%34 = add nsw i32 %33, -1
store i32 %34, i32* %5
%35 = load i64, i64* %3
%36 = srem i64 %35, 10
%37 = add nsw i64 48, %36
%38 = trunc i64 %37 to i8
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
%43 = load i64, i64* %3
%44 = sdiv i64 %43, 10
store i64 %44, i64* %3
br label %29
45: ; preds = %29
%46 = load i8*, i8** %4
store i8* %46, i8** %2
br label %47
47: ; preds = %45, %23
%48 = load i8*, i8** %2
ret i8* %48
}

LLVM IR (-O2):
define i8* @ft_lltoa(i64 %0) {
%2 = tail call i32 @ft_ll_len(i64 %0)
%3 = tail call i8* @ft_strnew(i32 %2)
%4 = icmp slt i64 %0, 0
%5 = sub nsw i64 0, %0
%6 = select i1 %4, i64 %5, i64 %0
%7 = icmp slt i64 %0, 1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = select i1 %4, i8 45, i8 48
store i8 %9, i8* %3
br label %10
10: ; preds = %1, %8
%11 = icmp eq i64 %6, 0
br i1 %11, label %25, label %12
12: ; preds = %10
%13 = sext i32 %2 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ %13, %12 ], [ %17, %14 ]
%16 = phi i64 [ %6, %12 ], [ %22, %14 ]
%17 = add i64 %15, -1
%18 = srem i64 %16, 10
%19 = trunc i64 %18 to i8
%20 = add nsw i8 %19, 48
%21 = getelementptr inbounds i8, i8* %3, i64 %17
store i8 %20, i8* %21
%22 = sdiv i64 %16, 10
%23 = add i64 %16, 9
%24 = icmp ult i64 %23, 19
br i1 %24, label %25, label %14
25: ; preds = %14, %10
ret i8* %3
}