#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_strln(int);
char *itoa_2pt(char *, int, int, int);
scalar_t__ malloc(int);
char *ft_itoa(int n) {
  char *s;
  int i;
  int j;
  s = NULL;
  i = 1;
  j = 0;
  s = (char *)malloc(sizeof(char) * ft_strln(n) + 1);
  if (s == NULL)
    return (NULL);
  s = itoa_2pt(s, i, j, n);
  s[ft_strln(n) + 1] = '\0';
  return (s);
}


x86 assembly (clang, -O0):
<ft_itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <ft_strln@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1186 <ft_itoa+0x56>
movq   $0x0,-0x8(%rbp)
jmp    11c4 <ft_itoa+0x94>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1040 <itoa_2pt@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <ft_strln@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_itoa>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
call   1050 <ft_strln@plt>
lea    0x1(%rax),%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     116b <ft_itoa+0x3b>
mov    %rax,%rdi
mov    $0x1,%esi
xor    %edx,%edx
mov    %ebp,%ecx
call   1040 <itoa_2pt@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1050 <ft_strln@plt>
cltq
movb   $0x0,0x1(%rax,%rbx,1)
jmp    116d <ft_itoa+0x3d>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
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
store i8* null, i8** %4
store i32 1, i32* %5
store i32 0, i32* %6
%7 = load i32, i32* %3
%8 = call i32 @ft_strln(i32 %7)
%9 = sext i32 %8 to i64
%10 = mul i64 1, %9
%11 = add i64 %10, 1
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load i8*, i8** %4
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %1
store i8* null, i8** %2
br label %31
18: ; preds = %1
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = load i32, i32* %3
%23 = call i8* @itoa_2pt(i8* %19, i32 %20, i32 %21, i32 %22)
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = load i32, i32* %3
%26 = call i32 @ft_strln(i32 %25)
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
store i8 0, i8* %29
%30 = load i8*, i8** %4
store i8* %30, i8** %2
br label %31
31: ; preds = %18, %17
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
define i8* @ft_itoa(i32 %0) {
%2 = tail call i32 @ft_strln(i32 %0)
%3 = add i32 %2, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = inttoptr i64 %4 to i8*
%8 = tail call i8* @itoa_2pt(i8* %7, i32 1, i32 0, i32 %0)
%9 = tail call i32 @ft_strln(i32 %0)
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
store i8 0, i8* %12
br label %13
13: ; preds = %1, %6
%14 = phi i8* [ %8, %6 ], [ null, %1 ]
ret i8* %14
}