#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 */
char *malloc(int);
int /*<<< orphan*/ reverse_string(char *);
char *dec_to_hex(int number) {
  char *hex_number = malloc(3);
  int temp, i = 0;
  if (number == 0) {
    hex_number[0] = '0';
    hex_number[1] = '0';
    i = 2;
  }
  while (number != 0) {
    temp = number % 16;
    if (temp < 10) {
      temp = temp + 48;
    } else {
      temp = temp + 55;
    }
    hex_number[i++] = temp;
    number /= 16;
  }
  hex_number[i] = '\0';
  reverse_string(hex_number);
  return hex_number;
}


x86 assembly (clang, -O0):
<dec_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1160 <dec_to_hex+0x40>
mov    -0x10(%rbp),%rax
movb   $0x30,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x30,0x1(%rax)
movl   $0x2,-0x18(%rbp)
jmp    1165 <dec_to_hex+0x45>
cmpl   $0x0,-0x4(%rbp)
je     11cb <dec_to_hex+0xab>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    1195 <dec_to_hex+0x75>
mov    -0x14(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    119e <dec_to_hex+0x7e>
mov    -0x14(%rbp),%eax
add    $0x37,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1165 <dec_to_hex+0x45>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <reverse_string@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec_to_hex>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
je     117b <dec_to_hex+0x5b>
xor    %eax,%eax
nopl   0x0(%rax)
lea    0xf(%rbx),%r8d
test   %ebx,%ebx
mov    %ebx,%edx
cmovs  %r8d,%edx
mov    %edx,%esi
and    $0xfffffff0,%esi
mov    %ebx,%edi
sub    %esi,%edi
lea    0x30(%rdi),%ecx
neg    %esi
cmp    $0xa,%edi
lea    0x37(%rbx,%rsi,1),%esi
cmovl  %ecx,%esi
mov    %sil,(%r14,%rax,1)
add    $0x1,%rax
sar    $0x4,%edx
mov    %edx,%ebx
cmp    $0x1e,%r8d
ja     1140 <dec_to_hex+0x20>
mov    %eax,%eax
jmp    1186 <dec_to_hex+0x66>
movw   $0x3030,(%r14)
mov    $0x2,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rdi
call   1030 <reverse_string@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @dec_to_hex(i32 %0) {
%2 = tail call dereferenceable_or_null(3) i8* @malloc(i32 3)
%3 = icmp eq i32 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %1
store i8 48, i8* %2
%5 = getelementptr inbounds i8, i8* %2, i64 1
store i8 48, i8* %5
br label %21
6: ; preds = %1, %6
%7 = phi i64 [ %14, %6 ], [ 0, %1 ]
%8 = phi i32 [ %16, %6 ], [ %0, %1 ]
%9 = srem i32 %8, 16
%10 = icmp slt i32 %9, 10
%11 = select i1 %10, i32 48, i32 55
%12 = add nsw i32 %11, %9
%13 = trunc i32 %12 to i8
%14 = add nuw i64 %7, 1
%15 = getelementptr inbounds i8, i8* %2, i64 %7
store i8 %13, i8* %15
%16 = sdiv i32 %8, 16
%17 = add i32 %8, 15
%18 = icmp ult i32 %17, 31
br i1 %18, label %19, label %6
19: ; preds = %6
%20 = and i64 %14, 4294967295
br label %21
21: ; preds = %4, %19
%22 = phi i64 [ %20, %19 ], [ 2, %4 ]
%23 = getelementptr inbounds i8, i8* %2, i64 %22
store i8 0, i8* %23
%24 = tail call i32 @reverse_string(i8* %2)
ret i8* %2
}