#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*/ free(char *);
int ft_n_count(unsigned long, int);
int /*<<< orphan*/ ft_strcpy(char *, char *);
char *ft_strnew(int);
char *ft_ulitoa(unsigned long int n) {
  int len;
  unsigned long int nbr;
  char *str2;
  int i;
  char *str;
  len = 1;
  nbr = n;
  i = ft_n_count(n, len);
  str2 = ft_strnew(i + 1);
  while (i > 0) {
    str2[i - 1] = ((char)((nbr % 10) + 48));
    i--;
    nbr /= 10;
  }
  str = ft_strnew(ft_n_count(n, len) + 1);
  ft_strcpy(str, str2);
  free(str2);
  return (str);
}


x86 assembly (clang, -O0):
<ft_ulitoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <ft_n_count@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1050 <ft_strnew@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    11c5 <ft_ulitoa+0x85>
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
add    $0x30,%rdx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x18(%rbp)
jmp    1179 <ft_ulitoa+0x39>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <ft_n_count@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <ft_strnew@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <ft_strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_ulitoa>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1,%esi
call   1060 <ft_n_count@plt>
mov    %eax,%r15d
lea    0x1(%r15),%edi
call   1050 <ft_strnew@plt>
mov    %rax,%r12
test   %r15d,%r15d
jle    122b <ft_ulitoa+0xeb>
mov    %r15d,%edi
movabs $0xcccccccccccccccd,%r8
cc cc cc
test   $0x1,%dil
jne    118e <ft_ulitoa+0x4e>
mov    %r14,%rcx
cmp    $0x1,%r15d
jne    11b9 <ft_ulitoa+0x79>
jmp    122b <ft_ulitoa+0xeb>
mov    %r14,%rax
mul    %r8
mov    %rdx,%rcx
shr    $0x3,%rcx
lea    (%rcx,%rcx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %r14d,%edx
sub    %eax,%edx
or     $0x30,%dl
add    $0xffffffffffffffff,%rdi
mov    %edi,%eax
mov    %dl,(%r12,%rax,1)
cmp    $0x1,%r15d
je     122b <ft_ulitoa+0xeb>
add    $0xfffffffffffffffe,%rdi
movabs $0x28f5c28f5c28f5c3,%r9
c2 f5 28
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rax
mul    %r8
mov    %rdx,%rsi
shr    $0x3,%rsi
lea    (%rsi,%rsi,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ecx,%edx
sub    %eax,%edx
or     $0x30,%dl
lea    0x1(%rdi),%r10
mov    %r10d,%eax
mov    %dl,(%r12,%rax,1)
mov    %rsi,%rax
mul    %r8
shr    $0x2,%edx
and    $0xfffffffe,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%esi
or     $0x30,%sil
mov    %edi,%ebx
shr    $0x2,%rcx
mov    %rcx,%rax
mul    %r9
mov    %sil,(%r12,%rbx,1)
mov    %rdx,%rcx
shr    $0x2,%rcx
add    $0xfffffffffffffffe,%rdi
cmp    $0x1,%r10
ja     11d0 <ft_ulitoa+0x90>
mov    %r14,%rdi
mov    $0x1,%esi
call   1060 <ft_n_count@plt>
lea    0x1(%rax),%edi
call   1050 <ft_strnew@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <ft_strcpy@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ft_ulitoa(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i64 %0, i64* %2
store i32 1, i32* %3
%8 = load i64, i64* %2
store i64 %8, i64* %4
%9 = load i64, i64* %2
%10 = load i32, i32* %3
%11 = call i32 @ft_n_count(i64 %9, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
%14 = call i8* @ft_strnew(i32 %13)
store i8* %14, i8** %5
br label %15
15: ; preds = %18, %1
%16 = load i32, i32* %6
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %32
18: ; preds = %15
%19 = load i64, i64* %4
%20 = urem i64 %19, 10
%21 = add i64 %20, 48
%22 = trunc i64 %21 to i8
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8 %22, i8* %27
%28 = load i32, i32* %6
%29 = add nsw i32 %28, -1
store i32 %29, i32* %6
%30 = load i64, i64* %4
%31 = udiv i64 %30, 10
store i64 %31, i64* %4
br label %15
32: ; preds = %15
%33 = load i64, i64* %2
%34 = load i32, i32* %3
%35 = call i32 @ft_n_count(i64 %33, i32 %34)
%36 = add nsw i32 %35, 1
%37 = call i8* @ft_strnew(i32 %36)
store i8* %37, i8** %7
%38 = load i8*, i8** %7
%39 = load i8*, i8** %5
%40 = call i32 @ft_strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %5
%42 = call i32 @free(i8* %41)
%43 = load i8*, i8** %7
ret i8* %43
}

LLVM IR (-O2):
define i8* @ft_ulitoa(i64 %0) {
%2 = tail call i32 @ft_n_count(i64 %0, i32 1)
%3 = add nsw i32 %2, 1
%4 = tail call i8* @ft_strnew(i32 %3)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %40
6: ; preds = %1
%7 = zext i32 %2 to i64
%8 = and i64 %7, 1
%9 = icmp eq i64 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %6
%11 = urem i64 %0, 10
%12 = trunc i64 %11 to i8
%13 = or i8 %12, 48
%14 = add nsw i64 %7, -1
%15 = and i64 %14, 4294967295
%16 = getelementptr inbounds i8, i8* %4, i64 %15
store i8 %13, i8* %16
%17 = udiv i64 %0, 10
br label %18
18: ; preds = %10, %6
%19 = phi i64 [ %7, %6 ], [ %14, %10 ]
%20 = phi i64 [ %0, %6 ], [ %17, %10 ]
%21 = icmp eq i32 %2, 1
br i1 %21, label %40, label %22
22: ; preds = %18, %22
%23 = phi i64 [ %35, %22 ], [ %19, %18 ]
%24 = phi i64 [ %38, %22 ], [ %20, %18 ]
%25 = urem i64 %24, 10
%26 = trunc i64 %25 to i8
%27 = or i8 %26, 48
%28 = add nsw i64 %23, -1
%29 = and i64 %28, 4294967295
%30 = getelementptr inbounds i8, i8* %4, i64 %29
store i8 %27, i8* %30
%31 = udiv i64 %24, 10
%32 = urem i64 %31, 10
%33 = trunc i64 %32 to i8
%34 = or i8 %33, 48
%35 = add nsw i64 %23, -2
%36 = and i64 %35, 4294967295
%37 = getelementptr inbounds i8, i8* %4, i64 %36
store i8 %34, i8* %37
%38 = udiv i64 %24, 100
%39 = icmp ugt i64 %28, 1
br i1 %39, label %22, label %40
40: ; preds = %18, %22, %1
%41 = tail call i32 @ft_n_count(i64 %0, i32 1)
%42 = add nsw i32 %41, 1
%43 = tail call i8* @ft_strnew(i32 %42)
%44 = tail call i32 @ft_strcpy(i8* %43, i8* %4)
%45 = tail call i32 @free(i8* %4)
ret i8* %43
}