#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(int argc, char const *argv[]) {
  char b[] = "0123456789ABCDEF";
  long int n, x;
  int i;
  int a[40];
  printf("input\n");
  scanf("%ld", &n);
  x = n;
  i = 0;
  while (x > 0) {
    a[i] = x % 16;
    x = x / 16;
    i++;
  }
  while (i > 0) {
    printf("%c", b[a[i - 1]]);
    i--;
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec0(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xebd(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xebb(%rip),%al
mov    %al,-0x20(%rbp)
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeab(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
cmpq   $0x0,-0x40(%rbp)
jle    11cb <main+0xab>
mov    -0x40(%rbp),%rax
mov    $0x10,%ecx
cqto
idiv   %rcx
mov    %edx,%ecx
movslq -0x44(%rbp),%rax
mov    %ecx,-0xf0(%rbp,%rax,4)
mov    -0x40(%rbp),%rax
mov    $0x10,%ecx
cqto
idiv   %rcx
mov    %rax,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1185 <main+0x65>
jmp    11d0 <main+0xb0>
cmpl   $0x0,-0x44(%rbp)
jle    120b <main+0xeb>
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
cltq
movslq -0xf0(%rbp,%rax,4),%rax
ff
movsbl -0x30(%rbp,%rax,1),%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    11d0 <main+0xb0>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0xb8,%rsp
lea    0xed4(%rip),%rdi
call   1040 <puts@plt>
lea    0xec4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
jle    11b9 <main+0x89>
xor    %ebx,%ebx
mov    %rax,%rcx
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%edx
and    $0xf,%edx
mov    %edx,0x10(%rsp,%rbx,4)
shr    $0x4,%rcx
add    $0x1,%rbx
cmp    $0x10,%rax
mov    %rcx,%rax
jae    1170 <main+0x40>
test   %ebx,%ebx
jle    11b9 <main+0x89>
add    $0x1,%rbx
lea    0xe67(%rip),%r14
nopl   0x0(%rax)
movslq 0x8(%rsp,%rbx,4),%rax
movsbl (%rax,%r14,1),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11a0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.b = [17 x i8] c"0123456789ABCDEF\00"
@.str = [7 x i8] c"input\0A\00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [17 x i8]
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca [40 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [17 x i8]* %6 to i8*
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %7)
%14 = load i64, i64* %7
store i64 %14, i64* %8
store i32 0, i32* %9
br label %15
15: ; preds = %18, %2
%16 = load i64, i64* %8
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i64, i64* %8
%20 = srem i64 %19, 16
%21 = trunc i64 %20 to i32
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [40 x i32], [40 x i32]* %10, i64 0, i64 %23
store i32 %21, i32* %24
%25 = load i64, i64* %8
%26 = sdiv i64 %25, 16
store i64 %26, i64* %8
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
br label %15
29: ; preds = %15
br label %30
30: ; preds = %33, %29
%31 = load i32, i32* %9
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load i32, i32* %9
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [40 x i32], [40 x i32]* %10, i64 0, i64 %36
%38 = load i32, i32* %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [17 x i8], [17 x i8]* %6, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = load i32, i32* %9
%45 = add nsw i32 %44, -1
store i32 %45, i32* %9
br label %30
46: ; preds = %30
%47 = 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):
@__const.main.b = [17 x i8] c"0123456789ABCDEF\00"
@.str.1 = [4 x i8] c"%ld\00"
@str = [6 x i8] c"input\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca [40 x i32]
%5 = bitcast i64* %3 to i8*
%6 = bitcast [40 x i32]* %4 to i8*
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%9 = load i64, i64* %3
%10 = icmp sgt i64 %9, 0
br i1 %10, label %16, label %36
11: ; preds = %16
%12 = trunc i64 %23 to i32
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %36
14: ; preds = %11
%15 = and i64 %23, 4294967295
br label %25
16: ; preds = %2, %16
%17 = phi i64 [ %23, %16 ], [ 0, %2 ]
%18 = phi i64 [ %22, %16 ], [ %9, %2 ]
%19 = trunc i64 %18 to i32
%20 = and i32 %19, 15
%21 = getelementptr inbounds [40 x i32], [40 x i32]* %4, i64 0, i64 %17
store i32 %20, i32* %21
%22 = lshr i64 %18, 4
%23 = add nuw nsw i64 %17, 1
%24 = icmp ult i64 %18, 16
br i1 %24, label %11, label %16
25: ; preds = %14, %25
%26 = phi i64 [ %15, %14 ], [ %27, %25 ]
%27 = add nsw i64 %26, -1
%28 = getelementptr inbounds [40 x i32], [40 x i32]* %4, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.main.b, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = call i32 @putchar(i32 %33)
%35 = icmp ugt i64 %26, 1
br i1 %35, label %25, label %36
36: ; preds = %25, %2, %11
%37 = call i32 @putchar(i32 10)
ret i32 0
}