#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 */
typedef int /*<<< orphan*/ str;

/* Variables and functions */
scalar_t__ malloc(int);
char switch_hexa(unsigned long long);
char *ft_hexa_itoa(unsigned long long n) {
  char *str;
  int size;
  unsigned long long x;
  x = n;
  size = 0;
  while (x >= 16) {
    x /= 16;
    size++;
  }
  str = (char *)malloc(sizeof(str) * (size + 1));
  if (str) {
    str[size + 1] = '\0';
    while (size >= 0) {
      x = n % 16;
      str[size] = switch_hexa(x);
      n /= 16;
      size--;
    }
  }
  return (str);
}


x86 assembly (clang, -O0):
<ft_hexa_itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x10,-0x20(%rbp)
jb     1160 <ft_hexa_itoa+0x40>
mov    -0x20(%rbp),%rax
shr    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <ft_hexa_itoa+0x1b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11de <ft_hexa_itoa+0xbe>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x14(%rbp)
jl     11d9 <ft_hexa_itoa+0xb9>
mov    -0x8(%rbp),%rax
and    $0xf,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <switch_hexa@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
shr    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <ft_hexa_itoa+0x73>
jmp    11de <ft_hexa_itoa+0xbe>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_hexa_itoa>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
xor    %ebp,%ebp
cmp    $0x10,%rdi
jb     1152 <ft_hexa_itoa+0x32>
xor    %ebp,%ebp
mov    %r15,%rax
mov    %r15,%rcx
nopl   0x0(%rax,%rax,1)
shr    $0x4,%rcx
add    $0x1,%ebp
cmp    $0xff,%rax
mov    %rcx,%rax
ja     1140 <ft_hexa_itoa+0x20>
mov    %ebp,%ebx
lea    0x1(%rbx),%r12
lea    0x0(,%r12,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     1199 <ft_hexa_itoa+0x79>
movb   $0x0,(%r14,%r12,1)
test   %ebp,%ebp
js     1199 <ft_hexa_itoa+0x79>
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%edi
and    $0xf,%edi
call   1030 <switch_hexa@plt>
mov    %al,(%r14,%rbx,1)
shr    $0x4,%r15
add    $0xffffffffffffffff,%rbx
jb     1180 <ft_hexa_itoa+0x60>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @ft_hexa_itoa(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i64 %0, i64* %2
%6 = load i64, i64* %2
store i64 %6, i64* %5
store i32 0, i32* %4
br label %7
7: ; preds = %10, %1
%8 = load i64, i64* %5
%9 = icmp uge i64 %8, 16
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i64, i64* %5
%12 = udiv i64 %11, 16
store i64 %12, i64* %5
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
br label %7
15: ; preds = %7
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = mul i64 8, %18
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %3
%23 = load i8*, i8** %3
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %48
25: ; preds = %15
%26 = load i8*, i8** %3
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %34, %25
%32 = load i32, i32* %4
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %47
34: ; preds = %31
%35 = load i64, i64* %2
%36 = urem i64 %35, 16
store i64 %36, i64* %5
%37 = load i64, i64* %5
%38 = call signext i8 @switch_hexa(i64 %37)
%39 = load i8*, i8** %3
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
%43 = load i64, i64* %2
%44 = udiv i64 %43, 16
store i64 %44, i64* %2
%45 = load i32, i32* %4
%46 = add nsw i32 %45, -1
store i32 %46, i32* %4
br label %31
47: ; preds = %31
br label %48
48: ; preds = %47, %15
%49 = load i8*, i8** %3
ret i8* %49
}

LLVM IR (-O2):
define i8* @ft_hexa_itoa(i64 %0) {
%2 = icmp ugt i64 %0, 15
br i1 %2, label %3, label %9
3: ; preds = %1, %3
%4 = phi i64 [ %6, %3 ], [ %0, %1 ]
%5 = phi i32 [ %7, %3 ], [ 0, %1 ]
%6 = lshr i64 %4, 4
%7 = add nuw nsw i32 %5, 1
%8 = icmp ugt i64 %4, 255
br i1 %8, label %3, label %9
9: ; preds = %3, %1
%10 = phi i32 [ 0, %1 ], [ %7, %3 ]
%11 = add nuw nsw i32 %10, 1
%12 = shl i32 %11, 3
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i64 %13, 0
br i1 %15, label %31, label %16
16: ; preds = %9
%17 = zext i32 %11 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
store i8 0, i8* %18
%19 = icmp sgt i32 %10, -1
br i1 %19, label %20, label %31
20: ; preds = %16
%21 = zext i32 %10 to i64
br label %22
22: ; preds = %20, %22
%23 = phi i64 [ %21, %20 ], [ %29, %22 ]
%24 = phi i64 [ %0, %20 ], [ %28, %22 ]
%25 = and i64 %24, 15
%26 = tail call signext i8 @switch_hexa(i64 %25)
%27 = getelementptr inbounds i8, i8* %14, i64 %23
store i8 %26, i8* %27
%28 = lshr i64 %24, 4
%29 = add nsw i64 %23, -1
%30 = icmp eq i64 %23, 0
br i1 %30, label %31, label %22
31: ; preds = %22, %16, %9
ret i8* %14
}