#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 */
char *ft_hex(long long, char *);
scalar_t__ malloc(int);
char *ft_dec_to_hex(long long int num, int byte) {
  char *str;
  int len;
  len = byte * 2;
  str = (char *)malloc(sizeof(str) * (len + 1));
  str[len] = '\0';
  len--;
  while (len >= 0) {
    str[len] = '0';
    len--;
  }
  str = ft_hex(num, str);
  return (str);
}


x86 assembly (clang, -O0):
<ft_dec_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1188 <ft_dec_to_hex+0x68>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1164 <ft_dec_to_hex+0x44>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <ft_hex@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_dec_to_hex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r12d
mov    %rdi,%r14
lea    (%r12,%r12,1),%ebx
mov    %esi,%edi
shl    $0x4,%edi
or     $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
test   %r12d,%r12d
jle    118b <ft_dec_to_hex+0x5b>
lea    -0x2(%rbx),%eax
or     $0x1,%eax
test   %ebx,%ebx
mov    $0x1,%ecx
cmovle %ebx,%ecx
sub    %ecx,%ebx
sub    %rbx,%rax
mov    %r15,%rdi
add    %rax,%rdi
add    $0x1,%rbx
mov    $0x30,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
mov    %r14,%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <ft_hex@plt>

LLVM IR (-O0):
define i8* @ft_dec_to_hex(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i64 %0, i64* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = mul nsw i32 %7, 2
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 8, %11
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %19
%20 = load i32, i32* %6
%21 = add nsw i32 %20, -1
store i32 %21, i32* %6
br label %22
22: ; preds = %25, %2
%23 = load i32, i32* %6
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i8*, i8** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 48, i8* %29
%30 = load i32, i32* %6
%31 = add nsw i32 %30, -1
store i32 %31, i32* %6
br label %22
32: ; preds = %22
%33 = load i64, i64* %3
%34 = load i8*, i8** %5
%35 = call i8* @ft_hex(i64 %33, i8* %34)
store i8* %35, i8** %5
%36 = load i8*, i8** %5
ret i8* %36
}

LLVM IR (-O2):
define i8* @ft_dec_to_hex(i64 %0, i32 %1) {
%3 = shl i32 %1, 1
%4 = shl i32 %1, 4
%5 = or i32 %4, 8
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = sext i32 %3 to i64
%9 = getelementptr inbounds i8, i8* %7, i64 %8
store i8 0, i8* %9
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = add i32 %3, -2
%13 = or i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i32 @llvm.smin.i32(i32 %3, i32 1)
%16 = sub i32 %3, %15
%17 = zext i32 %16 to i64
%18 = sub nsw i64 %14, %17
%19 = getelementptr i8, i8* %7, i64 %18
%20 = add nuw nsw i64 %17, 1
br label %21
21: ; preds = %11, %2
%22 = tail call i8* @ft_hex(i64 %0, i8* %7)
ret i8* %22
}