#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_do_it(int, char *, int, int);
int ft_intlen(int);
char *ft_strcpy(char *, char *);
char *ft_strnew(int);
char *ft_itoa(int n) {
  char *str;
  int l;
  int sign;
  if (n == -2147483648)
    return (ft_strcpy(ft_strnew(11), "-2147483648"));
  sign = 1;
  l = 0;
  if (n < 0) {
    n *= -1;
    sign = -1;
  }
  l = sign == -1 ? ft_intlen(n) + 1 : ft_intlen(n);
  str = ft_strnew(l);
  if (!str)
    return (NULL);
  return (ft_do_it(n, str, l - 1, sign));
}


x86 assembly (clang, -O0):
<ft_itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0xffffffff80000000,%rax
jne    117d <ft_itoa+0x3d>
mov    $0xb,%edi
call   1050 <ft_strnew@plt>
mov    %rax,%rdi
lea    0xe91(%rip),%rsi
call   1030 <ft_strcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    120e <ft_itoa+0xce>
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11a3 <ft_itoa+0x63>
imul   $0xffffffff,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0xffffffff,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11c0 <ft_itoa+0x80>
mov    -0xc(%rbp),%edi
call   1060 <ft_intlen@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cb <ft_itoa+0x8b>
mov    -0xc(%rbp),%edi
call   1060 <ft_intlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <ft_strnew@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f5 <ft_itoa+0xb5>
movq   $0x0,-0x8(%rbp)
jmp    120e <ft_itoa+0xce>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
mov    -0x20(%rbp),%ecx
call   1040 <ft_do_it@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_itoa>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x80000000,%edi
jne    1169 <ft_itoa+0x29>
mov    $0xb,%edi
call   1050 <ft_strnew@plt>
lea    0xea3(%rip),%rsi
mov    %rax,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <ft_strcpy@plt>
mov    %edi,%ebx
mov    %edi,%r14d
neg    %r14d
cmovs  %edi,%r14d
mov    %r14d,%edi
call   1060 <ft_intlen@plt>
mov    %ebx,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
mov    %ebp,%edi
call   1050 <ft_strnew@plt>
test   %rax,%rax
je     11af <ft_itoa+0x6f>
not    %ebx
shr    $0x1f,%ebx
lea    (%rbx,%rbx,1),%ecx
add    $0xffffffff,%ecx
add    $0xffffffff,%ebp
mov    %r14d,%edi
mov    %rax,%rsi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <ft_do_it@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"-2147483648\00"
define i8* @ft_itoa(i32 %0) {
%2 = icmp eq i32 %0, -2147483648
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = tail call i8* @ft_strnew(i32 11)
%5 = tail call i8* @ft_strcpy(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %19
6: ; preds = %1
%7 = icmp slt i32 %0, 0
%8 = sub nsw i32 0, %0
%9 = select i1 %7, i32 %8, i32 %0
%10 = tail call i32 @ft_intlen(i32 %9)
%11 = lshr i32 %0, 31
%12 = add nsw i32 %10, %11
%13 = tail call i8* @ft_strnew(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %6
%16 = select i1 %7, i32 -1, i32 1
%17 = add nsw i32 %12, -1
%18 = tail call i8* @ft_do_it(i32 %9, i8* %13, i32 %17, i32 %16)
br label %19
19: ; preds = %6, %15, %3
%20 = phi i8* [ %5, %3 ], [ %18, %15 ], [ null, %6 ]
ret i8* %20
}