#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 int, int);
int /*<<< orphan*/ ft_strcpy(char *, char *);
char *ft_strnew(int);
char *ft_uitoa(unsigned int n) {
  int len;
  unsigned 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_uitoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <ft_n_count@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1050 <ft_strnew@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11bb <ft_uitoa+0x7b>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
add    $0x30,%edx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
jmp    1175 <ft_uitoa+0x35>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <ft_n_count@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <ft_strnew@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <ft_strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_uitoa>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x1,%esi
call   1060 <ft_n_count@plt>
mov    %eax,%ebp
lea    0x1(%rbp),%edi
call   1050 <ft_strnew@plt>
mov    %rax,%rbx
test   %ebp,%ebp
jle    1213 <ft_uitoa+0xd3>
mov    %ebp,%eax
test   $0x1,%al
jne    1179 <ft_uitoa+0x39>
mov    %r14d,%ecx
cmp    $0x1,%ebp
jne    11a7 <ft_uitoa+0x67>
jmp    1213 <ft_uitoa+0xd3>
mov    %r14d,%edx
mov    $0xcccccccd,%ecx
imul   %rdx,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %r14d,%esi
sub    %edx,%esi
or     $0x30,%sil
add    $0xffffffffffffffff,%rax
mov    %eax,%edx
mov    %sil,(%rbx,%rdx,1)
cmp    $0x1,%ebp
je     1213 <ft_uitoa+0xd3>
add    $0xfffffffffffffffe,%rax
mov    $0xcccccccd,%r8d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ecx,%esi
mov    %rsi,%rdi
imul   %r8,%rdi
shr    $0x23,%rdi
lea    (%rdi,%rdi,1),%ebp
lea    0x0(%rbp,%rbp,4),%ebp
sub    %ebp,%ecx
or     $0x30,%cl
lea    0x1(%rax),%rbp
mov    %ebp,%edx
mov    %cl,(%rbx,%rdx,1)
mov    %rdi,%rcx
imul   %r8,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%edi
or     $0x30,%dil
mov    %eax,%ecx
mov    %dil,(%rbx,%rcx,1)
imul   $0x51eb851f,%rsi,%rcx
shr    $0x25,%rcx
add    $0xfffffffffffffffe,%rax
cmp    $0x1,%rbp
ja     11c0 <ft_uitoa+0x80>
mov    %r14d,%edi
mov    $0x1,%esi
call   1060 <ft_n_count@plt>
lea    0x1(%rax),%edi
call   1050 <ft_strnew@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <ft_strcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @ft_uitoa(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %2
store i32 1, i32* %3
%8 = load i32, i32* %2
store i32 %8, i32* %4
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = call i32 @ft_n_count(i32 %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 i32, i32* %4
%20 = urem i32 %19, 10
%21 = add i32 %20, 48
%22 = trunc i32 %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 i32, i32* %4
%31 = udiv i32 %30, 10
store i32 %31, i32* %4
br label %15
32: ; preds = %15
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = call i32 @ft_n_count(i32 %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_uitoa(i32 %0) {
%2 = tail call i32 @ft_n_count(i32 %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 i32 %0, 10
%12 = trunc i32 %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 i32 %0, 10
br label %18
18: ; preds = %10, %6
%19 = phi i64 [ %7, %6 ], [ %14, %10 ]
%20 = phi i32 [ %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 i32 [ %38, %22 ], [ %20, %18 ]
%25 = urem i32 %24, 10
%26 = trunc i32 %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 i32 %24, 10
%32 = urem i32 %31, 10
%33 = trunc i32 %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 i32 %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(i32 %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
}