#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 */
scalar_t__ ft_memalloc(int);
char *ft_uitoa(unsigned long n) {
  char *p;
  p = (char *)ft_memalloc(sizeof(char) * 22);
  p = p + 21;
  if (n == 0)
    *p = n + 48;
  while (n != 0) {
    *--p = (n % 10) + 48;
    n /= 10;
  }
  return (p);
}


x86 assembly (clang, -O0):
<ft_uitoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x16,%edi
call   1030 <ft_memalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x15,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1151 <ft_uitoa+0x41>
mov    -0x8(%rbp),%rax
add    $0x30,%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    1156 <ft_uitoa+0x46>
cmpq   $0x0,-0x8(%rbp)
je     119e <ft_uitoa+0x8e>
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
add    $0x30,%rdx
mov    %dl,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x8(%rbp)
jmp    1156 <ft_uitoa+0x46>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_uitoa>:
push   %rbx
mov    %rdi,%rbx
mov    $0x16,%edi
call   1030 <ft_memalloc@plt>
mov    %rax,%rcx
add    $0x15,%rcx
test   %rbx,%rbx
je     116b <ft_uitoa+0x5b>
movabs $0xcccccccccccccccd,%rsi
cc cc cc
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rax
mul    %rsi
shr    $0x3,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebx,%edi
sub    %eax,%edi
or     $0x30,%dil
mov    %dil,-0x1(%rcx)
add    $0xffffffffffffffff,%rcx
cmp    $0x9,%rbx
mov    %rdx,%rbx
ja     1140 <ft_uitoa+0x30>
jmp    116e <ft_uitoa+0x5e>
movb   $0x30,(%rcx)
mov    %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @ft_uitoa(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = call i64 @ft_memalloc(i32 22)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 21
store i8* %7, i8** %3
%8 = load i64, i64* %2
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i64, i64* %2
%12 = add i64 %11, 48
%13 = trunc i64 %12 to i8
%14 = load i8*, i8** %3
store i8 %13, i8* %14
br label %15
15: ; preds = %10, %1
br label %16
16: ; preds = %19, %15
%17 = load i64, i64* %2
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = load i64, i64* %2
%21 = urem i64 %20, 10
%22 = add i64 %21, 48
%23 = trunc i64 %22 to i8
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %3
store i8 %23, i8* %25
%26 = load i64, i64* %2
%27 = udiv i64 %26, 10
store i64 %27, i64* %2
br label %16
28: ; preds = %16
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
define i8* @ft_uitoa(i64 %0) {
%2 = tail call i64 @ft_memalloc(i32 22)
%3 = inttoptr i64 %2 to i8*
%4 = getelementptr inbounds i8, i8* %3, i64 21
%5 = icmp eq i64 %0, 0
br i1 %5, label %6, label %7
6: ; preds = %1
store i8 48, i8* %4
br label %16
7: ; preds = %1, %7
%8 = phi i8* [ %13, %7 ], [ %4, %1 ]
%9 = phi i64 [ %14, %7 ], [ %0, %1 ]
%10 = urem i64 %9, 10
%11 = trunc i64 %10 to i8
%12 = or i8 %11, 48
%13 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 %12, i8* %13
%14 = udiv i64 %9, 10
%15 = icmp ult i64 %9, 10
br i1 %15, label %16, label %7
16: ; preds = %7, %6
%17 = phi i8* [ %4, %6 ], [ %13, %7 ]
ret i8* %17
}