#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*/ scanf(char *, long *);
int main() {
  long int decimalNumber, remainder, quotient;
  int i = 1, j, temp;
  char hexadecimalNumber[100];
  printf("Enter any decimal number: ");
  scanf("%ld", &decimalNumber);
  quotient = decimalNumber;
  while (quotient != 0) {
    temp = quotient % 16;
    if (temp < 10)
      temp = temp + 48;
    else
      temp = temp + 55;
    hexadecimalNumber[i++] = temp;
    quotient = quotient / 16;
  }
  printf("Equivalent hexadecimal value of decimal number %d: ", decimalNumber);
  for (j = i - 1; j > 0; j--)
    printf("%c", hexadecimalNumber[j]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecd(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ce <main+0xae>
mov    -0x20(%rbp),%rax
mov    $0x10,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jge    1195 <main+0x75>
mov    -0x2c(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x2c(%rbp)
jmp    119e <main+0x7e>
mov    -0x2c(%rbp),%eax
add    $0x37,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %al,%cl
mov    -0x24(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
cltq
mov    %cl,-0x90(%rbp,%rax,1)
mov    -0x20(%rbp),%rax
mov    $0x10,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
jmp    115f <main+0x3f>
mov    -0x10(%rbp),%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    121b <main+0xfb>
movslq -0x28(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%esi
ff
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    11e9 <main+0xc9>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%rsi
test   %rsi,%rsi
je     11d9 <main+0xa9>
mov    $0x1,%ebx
mov    %rsi,%rcx
mov    %rsi,%rax
nopl   0x0(%rax)
lea    0xf(%rcx),%r8
test   %rcx,%rcx
cmovs  %r8,%rax
sar    $0x4,%rax
mov    %eax,%edi
shl    $0x4,%edi
sub    %edi,%ecx
lea    0x37(%rcx),%edi
lea    0x30(%rcx),%edx
cmp    $0xa,%ecx
cmovge %edi,%edx
mov    %dl,0x10(%rsp,%rbx,1)
add    $0x1,%rbx
mov    %rax,%rcx
cmp    $0x1e,%r8
ja     1170 <main+0x40>
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebx
jl     11e7 <main+0xb7>
mov    %ebx,%ebx
add    $0x1,%rbx
nopl   0x0(%rax)
lea    -0x2(%rbx),%eax
movsbl 0x10(%rsp,%rax,1),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x2,%rbx
ja     11c0 <main+0x90>
jmp    11e7 <main+0xb7>
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter any decimal number: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [52 x i8] c"Equivalent hexadecimal value of decimal number %d: \00"
@.str.3 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
store i32 0, i32* %1
store i32 1, i32* %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%11 = load i64, i64* %2
store i64 %11, i64* %4
br label %12
12: ; preds = %27, %0
%13 = load i64, i64* %4
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %36
15: ; preds = %12
%16 = load i64, i64* %4
%17 = srem i64 %16, 16
%18 = trunc i64 %17 to i32
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 48
store i32 %23, i32* %7
br label %27
24: ; preds = %15
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 55
store i32 %26, i32* %7
br label %27
27: ; preds = %24, %21
%28 = load i32, i32* %7
%29 = trunc i32 %28 to i8
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %32
store i8 %29, i8* %33
%34 = load i64, i64* %4
%35 = sdiv i64 %34, 16
store i64 %35, i64* %4
br label %12
36: ; preds = %12
%37 = load i64, i64* %2
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i64 %37)
%39 = load i32, i32* %5
%40 = sub nsw i32 %39, 1
store i32 %40, i32* %6
br label %41
41: ; preds = %51, %36
%42 = load i32, i32* %6
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %54
44: ; preds = %41
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %44
%52 = load i32, i32* %6
%53 = add nsw i32 %52, -1
store i32 %53, i32* %6
br label %41
54: ; preds = %41
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"Enter any decimal number: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [52 x i8] c"Equivalent hexadecimal value of decimal number %d: \00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [100 x i8]
%3 = bitcast i64* %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%7 = load i64, i64* %1
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i64 %7)
br label %40
11: ; preds = %0, %11
%12 = phi i64 [ %20, %11 ], [ 1, %0 ]
%13 = phi i64 [ %22, %11 ], [ %7, %0 ]
%14 = srem i64 %13, 16
%15 = trunc i64 %14 to i32
%16 = icmp slt i32 %15, 10
%17 = select i1 %16, i32 48, i32 55
%18 = add nsw i32 %17, %15
%19 = trunc i32 %18 to i8
%20 = add nuw i64 %12, 1
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %12
store i8 %19, i8* %21
%22 = sdiv i64 %13, 16
%23 = add i64 %13, 15
%24 = icmp ult i64 %23, 31
br i1 %24, label %25, label %11
25: ; preds = %11
%26 = trunc i64 %20 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i64 %7)
%28 = icmp sgt i32 %26, 1
br i1 %28, label %29, label %40
29: ; preds = %25
%30 = and i64 %20, 4294967295
br label %31
31: ; preds = %29, %31
%32 = phi i64 [ %30, %29 ], [ %33, %31 ]
%33 = add nsw i64 %32, -1
%34 = and i64 %33, 4294967295
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = call i32 @putchar(i32 %37)
%39 = icmp ugt i64 %32, 2
br i1 %39, label %31, label %40
40: ; preds = %31, %9, %25
ret i32 0
}