#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*/ printf(char *, ...);
int /*<<< orphan*/ printhexa(int);
void dec2hexa(int decimal) {
  int remainder[32];
  int quocient = decimal, i = 0;
  while (quocient >= 15) {
    remainder[i] = quocient % 16;
    quocient = quocient / 16;
    i++;
  }
  remainder[i] = quocient;
  printf("The decimal number %d in hexadecimal is: 0x", decimal);
  while (i >= 0) {
    printhexa(remainder[i]);
    i--;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dec2hexa>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
cmpl   $0xf,-0x94(%rbp)
jl     1192 <dec2hexa+0x72>
mov    -0x94(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movslq -0x98(%rbp),%rax
mov    %edx,-0x90(%rbp,%rax,4)
mov    -0x94(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x94(%rbp)
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    1141 <dec2hexa+0x21>
mov    -0x94(%rbp),%ecx
movslq -0x98(%rbp),%rax
mov    %ecx,-0x90(%rbp,%rax,4)
mov    -0x4(%rbp),%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x98(%rbp)
jl     11eb <dec2hexa+0xcb>
movslq -0x98(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%edi
call   1040 <printhexa@plt>
mov    -0x98(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x98(%rbp)
jmp    11b7 <dec2hexa+0x97>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec2hexa>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %edi,%r14d
cmp    $0xf,%edi
jl     1186 <dec2hexa+0x56>
xor    %ebx,%ebx
mov    %r14d,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
mov    %ebp,%ecx
and    $0xf,%ecx
mov    %ecx,(%rsp,%rbx,4)
shr    $0x4,%ebp
add    $0x1,%rbx
cmp    $0xef,%eax
ja     1150 <dec2hexa+0x20>
mov    %ebp,(%rsp,%rbx,4)
lea    0xe8e(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x80000000,%ebx
je     11a0 <dec2hexa+0x70>
jmp    11c3 <dec2hexa+0x93>
mov    %r14d,(%rsp)
lea    0xe6f(%rip),%rdi
xor    %ebx,%ebx
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%ebp
mov    %ebp,%edi
call   1050 <printhexa@plt>
test   %rbx,%rbx
je     11c3 <dec2hexa+0x93>
add    $0x1,%rbx
mov    -0x8(%rsp,%rbx,4),%edi
call   1050 <printhexa@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jg     11b0 <dec2hexa+0x80>
mov    $0xa,%edi
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [44 x i8] c"The decimal number %d in hexadecimal is: 0x\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @dec2hexa(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i32]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
store i32 %6, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %10, %1
%8 = load i32, i32* %4
%9 = icmp sge i32 %8, 15
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32, i32* %4
%12 = srem i32 %11, 16
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %14
store i32 %12, i32* %15
%16 = load i32, i32* %4
%17 = sdiv i32 %16, 16
store i32 %17, i32* %4
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %7
20: ; preds = %7
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %23
store i32 %21, i32* %24
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %30, %20
%28 = load i32, i32* %5
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @printhexa(i32 %34)
%36 = load i32, i32* %5
%37 = add nsw i32 %36, -1
store i32 %37, i32* %5
br label %27
38: ; preds = %27
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"The decimal number %d in hexadecimal is: 0x\00"
define void @dec2hexa(i32 %0) {
%2 = alloca [32 x i32]
%3 = bitcast [32 x i32]* %2 to i8*
%4 = icmp sgt i32 %0, 14
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 0
store i32 %0, i32* %6
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %22
8: ; preds = %1, %8
%9 = phi i64 [ %14, %8 ], [ 0, %1 ]
%10 = phi i32 [ %13, %8 ], [ %0, %1 ]
%11 = and i32 %10, 15
%12 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %9
store i32 %11, i32* %12
%13 = lshr i32 %10, 4
%14 = add nuw nsw i64 %9, 1
%15 = icmp ugt i32 %10, 239
br i1 %15, label %8, label %16
16: ; preds = %8
%17 = and i64 %14, 4294967295
%18 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %17
store i32 %13, i32* %18
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %0)
%20 = and i64 %14, 2147483648
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %34
22: ; preds = %5, %16
%23 = phi i64 [ 0, %5 ], [ %17, %16 ]
%24 = phi i32 [ %0, %5 ], [ %13, %16 ]
%25 = tail call i32 @printhexa(i32 %24)
%26 = icmp eq i64 %23, 0
br i1 %26, label %34, label %27
27: ; preds = %22, %27
%28 = phi i64 [ %29, %27 ], [ %23, %22 ]
%29 = add nsw i64 %28, -1
%30 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = tail call i32 @printhexa(i32 %31)
%33 = icmp sgt i64 %28, 1
br i1 %33, label %27, label %34
34: ; preds = %27, %22, %16
%35 = tail call i32 @putchar(i32 10)
ret void
}