#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 get_digit(long long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, long long *);
int main() {
  printf("Please enter an integer number to convert to Hex: ");
  long long n;
  scanf("%lld", &n);
  char hex[17];
  int i = 0;
  while (n > 0) {
    char currentDigit = get_digit(n % 16);
    hex[i] = currentDigit;
    n /= 16;
    i++;
  }
  for (i = i - 1; i >= 0; i--) {
    printf("%c", hex[i]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedf(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    11b3 <main+0x83>
mov    -0x10(%rbp),%rax
mov    $0x10,%ecx
cqto
idiv   %rcx
mov    %rdx,%rdi
call   1050 <get_digit@plt>
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%cl
movslq -0x34(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    $0x10,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1164 <main+0x34>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     11eb <main+0xbb>
movslq -0x34(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    11bc <main+0x8c>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed9(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
jle    11c7 <main+0x87>
xor    %ebx,%ebx
and    $0xf,%edi
call   1060 <get_digit@plt>
mov    %al,0x10(%rsp,%rbx,1)
mov    0x8(%rsp),%rax
lea    0xf(%rax),%rdi
test   %rax,%rax
cmovns %rax,%rdi
sar    $0x4,%rdi
mov    %rdi,0x8(%rsp)
add    $0x1,%rbx
cmp    $0xf,%rax
jg     1170 <main+0x30>
test   %ebx,%ebx
jle    11c7 <main+0x87>
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    $0x1,%rbx
ja     11b0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [51 x i8] c"Please enter an integer number to convert to Hex: \00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [17 x i8]
%4 = alloca i32
%5 = alloca i8
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %2)
store i32 0, i32* %4
br label %8
8: ; preds = %11, %0
%9 = load i64, i64* %2
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i64, i64* %2
%13 = srem i64 %12, 16
%14 = call signext i8 @get_digit(i64 %13)
store i8 %14, i8* %5
%15 = load i8, i8* %5
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %17
store i8 %15, i8* %18
%19 = load i64, i64* %2
%20 = sdiv i64 %19, 16
store i64 %20, i64* %2
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %8
23: ; preds = %8
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
store i32 %25, i32* %4
br label %26
26: ; preds = %36, %23
%27 = load i32, i32* %4
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %29
%37 = load i32, i32* %4
%38 = add nsw i32 %37, -1
store i32 %38, i32* %4
br label %26
39: ; preds = %26
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [51 x i8] c"Please enter an integer number to convert to Hex: \00"
@.str.1 = [5 x i8] c"%lld\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [17 x i8]
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%4 = bitcast i64* %1 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%6 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%7 = load i64, i64* %1
%8 = icmp sgt i64 %7, 0
br i1 %8, label %14, label %33
9: ; preds = %14
%10 = trunc i64 %22 to i32
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %33
12: ; preds = %9
%13 = and i64 %22, 4294967295
br label %24
14: ; preds = %0, %14
%15 = phi i64 [ %22, %14 ], [ 0, %0 ]
%16 = phi i64 [ %21, %14 ], [ %7, %0 ]
%17 = and i64 %16, 15
%18 = call signext i8 @get_digit(i64 %17)
%19 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 %15
store i8 %18, i8* %19
%20 = load i64, i64* %1
%21 = sdiv i64 %20, 16
store i64 %21, i64* %1
%22 = add nuw i64 %15, 1
%23 = icmp sgt i64 %20, 15
br i1 %23, label %14, label %9
24: ; preds = %12, %24
%25 = phi i64 [ %13, %12 ], [ %26, %24 ]
%26 = add nsw i64 %25, -1
%27 = and i64 %26, 4294967295
%28 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 @putchar(i32 %30)
%32 = icmp ugt i64 %25, 1
br i1 %32, label %24, label %33
33: ; preds = %24, %0, %9
%34 = call i32 @putchar(i32 10)
ret i32 0
}