#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_bzero(char *, int);
char *ft_strcpy(char *, char *);
char *ft_strnew(int);
char *reverse(char *);
char *ft_itoa(int n) {
  int i;
  int sign;
  char *s;
  s = ft_strnew(11);
  ft_bzero(s, 11);
  if (n == -2147483648)
    return (ft_strcpy(s, "-2147483648"));
  if (n == 0)
    return (ft_strcpy(s, "0"));
  if ((sign = n) < 0)
    n = -n;
  i = 0;
  while (n > 0) {
    s[i++] = n % 10 + '0';
    n /= 10;
  }
  if (sign < 0)
    s[i++] = '-';
  s[i] = '\0';
  return (reverse(s));
}


x86 assembly (clang, -O0):
<ft_itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    $0xb,%edi
call   1060 <ft_strnew@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0xb,%esi
call   1050 <ft_bzero@plt>
movslq -0xc(%rbp),%rax
cmp    $0xffffffff80000000,%rax
jne    1190 <ft_itoa+0x50>
mov    -0x20(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1040 <ft_strcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    124a <ft_itoa+0x10a>
cmpl   $0x0,-0xc(%rbp)
jne    11b3 <ft_itoa+0x73>
mov    -0x20(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1040 <ft_strcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    124a <ft_itoa+0x10a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11ca <ft_itoa+0x8a>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1211 <ft_itoa+0xd1>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    11d1 <ft_itoa+0x91>
cmpl   $0x0,-0x14(%rbp)
jge    1231 <ft_itoa+0xf1>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1030 <reverse@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_itoa>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0xb,%edi
call   1060 <ft_strnew@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xb,%esi
call   1050 <ft_bzero@plt>
test   %r14d,%r14d
je     1178 <ft_itoa+0x38>
cmp    $0x80000000,%r14d
jne    118b <ft_itoa+0x4b>
lea    0xe8a(%rip),%rsi
jmp    117f <ft_itoa+0x3f>
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <ft_strcpy@plt>
mov    %r14d,%ebp
neg    %ebp
cmovs  %r14d,%ebp
xor    %eax,%eax
mov    $0xcccccccd,%edx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%esi
imul   %rdx,%rsi
shr    $0x23,%rsi
lea    (%rsi,%rsi,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %ebp,%ecx
sub    %edi,%ecx
or     $0x30,%cl
mov    %cl,(%rbx,%rax,1)
add    $0x1,%rax
cmp    $0x9,%ebp
mov    %esi,%ebp
ja     11a0 <ft_itoa+0x60>
test   %r14d,%r14d
jns    11d4 <ft_itoa+0x94>
mov    %eax,%ecx
add    $0x1,%rax
movb   $0x2d,(%rbx,%rcx,1)
cltq
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <reverse@plt>

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

LLVM IR (-O2):
@.str = [12 x i8] c"-2147483648\00"
@.str.1 = [2 x i8] c"0\00"
define i8* @ft_itoa(i32 %0) {
%2 = tail call i8* @ft_strnew(i32 11)
%3 = tail call i32 @ft_bzero(i8* %2, i32 11)
switch i32 %0, label %8 [
i32 -2147483648, label %4
i32 0, label %6
]
4: ; preds = %1
%5 = tail call i8* @ft_strcpy(i8* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %33
6: ; preds = %1
%7 = tail call i8* @ft_strcpy(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %33
8: ; preds = %1
%9 = icmp slt i32 %0, 0
%10 = sub nsw i32 0, %0
%11 = select i1 %9, i32 %10, i32 %0
br label %12
12: ; preds = %8, %12
%13 = phi i64 [ 0, %8 ], [ %18, %12 ]
%14 = phi i32 [ %11, %8 ], [ %20, %12 ]
%15 = urem i32 %14, 10
%16 = trunc i32 %15 to i8
%17 = or i8 %16, 48
%18 = add nuw i64 %13, 1
%19 = getelementptr inbounds i8, i8* %2, i64 %13
store i8 %17, i8* %19
%20 = udiv i32 %14, 10
%21 = icmp ult i32 %14, 10
br i1 %21, label %22, label %12
22: ; preds = %12
br i1 %9, label %23, label %27
23: ; preds = %22
%24 = add i64 %13, 2
%25 = and i64 %18, 4294967295
%26 = getelementptr inbounds i8, i8* %2, i64 %25
store i8 45, i8* %26
br label %27
27: ; preds = %23, %22
%28 = phi i64 [ %24, %23 ], [ %18, %22 ]
%29 = shl i64 %28, 32
%30 = ashr exact i64 %29, 32
%31 = getelementptr inbounds i8, i8* %2, i64 %30
store i8 0, i8* %31
%32 = tail call i8* @reverse(i8* %2)
br label %33
33: ; preds = %27, %6, %4
%34 = phi i8* [ %5, %4 ], [ %7, %6 ], [ %32, %27 ]
ret i8* %34
}