#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*/ fprintf(int /*<<< orphan*/, char *, char);
int /*<<< orphan*/ stderr;
void to_hexadecimal(int num) {
  char remainder;
  remainder = num % 16;
  switch (remainder) {
  case 0:
  case 1:
  case 2:
  case 3:
  case 4:
  case 5:
  case 6:
  case 7:
  case 8:
  case 9:
    remainder += '0';
    break;
  case 10:
    remainder = 'A';
    break;
  case 11:
    remainder = 'B';
    break;
  case 12:
    remainder = 'C';
    break;
  case 13:
    remainder = 'D';
    break;
  case 14:
    remainder = 'E';
    break;
  case 15:
    remainder = 'F';
    break;
  default:
    break;
  }
  if (16 <= num)
    to_hexadecimal(num / 16);
  fprintf(stderr, "%c", remainder);
}


x86 assembly (clang, -O0):
<to_hexadecimal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%edx
add    $0xf,%edx
test   %eax,%eax
mov    %eax,%ecx
cmovs  %edx,%ecx
and    $0xf0,%ecx
sub    %ecx,%eax
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0xf,%eax
ja     11b1 <to_hexadecimal+0x91>
mov    -0x10(%rbp),%rax
lea    0xe9d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsbl -0x5(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x5(%rbp)
jmp    11b6 <to_hexadecimal+0x96>
movb   $0x41,-0x5(%rbp)
jmp    11b6 <to_hexadecimal+0x96>
movb   $0x42,-0x5(%rbp)
jmp    11b6 <to_hexadecimal+0x96>
movb   $0x43,-0x5(%rbp)
jmp    11b6 <to_hexadecimal+0x96>
movb   $0x44,-0x5(%rbp)
jmp    11b6 <to_hexadecimal+0x96>
movb   $0x45,-0x5(%rbp)
jmp    11b6 <to_hexadecimal+0x96>
movb   $0x46,-0x5(%rbp)
jmp    11b6 <to_hexadecimal+0x96>
jmp    11b6 <to_hexadecimal+0x96>
mov    $0x10,%eax
cmp    -0x4(%rbp),%eax
jg     11d6 <to_hexadecimal+0xb6>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <to_hexadecimal@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
movsbl -0x5(%rbp),%edx
call   1040 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_hexadecimal>:
push   %rbx
lea    0xf(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffff0,%eax
mov    %edi,%ebx
sub    %eax,%ebx
cmp    $0xf,%ebx
ja     1148 <to_hexadecimal+0x28>
lea    0xec4(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
add    $0x30,%ebx
cmp    $0x10,%edi
jl     1155 <to_hexadecimal+0x35>
shr    $0x4,%edi
call   1030 <to_hexadecimal@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
movsbl %bl,%edx
lea    0xed8(%rip),%rsi
pop    %rbx
jmp    1040 <fprintf@plt>
mov    $0x41,%bl
jmp    1148 <to_hexadecimal+0x28>
mov    $0x42,%bl
jmp    1148 <to_hexadecimal+0x28>
mov    $0x43,%bl
jmp    1148 <to_hexadecimal+0x28>
mov    $0x44,%bl
jmp    1148 <to_hexadecimal+0x28>
mov    $0x45,%bl
jmp    1148 <to_hexadecimal+0x28>
mov    $0x46,%bl
jmp    1148 <to_hexadecimal+0x28>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [3 x i8] c"%c\00"
define void @to_hexadecimal(i32 %0) {
%2 = alloca i32
%3 = alloca i8
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = srem i32 %4, 16
%6 = trunc i32 %5 to i8
store i8 %6, i8* %3
%7 = load i8, i8* %3
%8 = sext i8 %7 to i32
switch i32 %8, label %20 [
i32 0, label %9
i32 1, label %9
i32 2, label %9
i32 3, label %9
i32 4, label %9
i32 5, label %9
i32 6, label %9
i32 7, label %9
i32 8, label %9
i32 9, label %9
i32 10, label %14
i32 11, label %15
i32 12, label %16
i32 13, label %17
i32 14, label %18
i32 15, label %19
]
9: ; preds = %1, %1, %1, %1, %1, %1, %1, %1, %1, %1
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
%12 = add nsw i32 %11, 48
%13 = trunc i32 %12 to i8
store i8 %13, i8* %3
br label %21
14: ; preds = %1
store i8 65, i8* %3
br label %21
15: ; preds = %1
store i8 66, i8* %3
br label %21
16: ; preds = %1
store i8 67, i8* %3
br label %21
17: ; preds = %1
store i8 68, i8* %3
br label %21
18: ; preds = %1
store i8 69, i8* %3
br label %21
19: ; preds = %1
store i8 70, i8* %3
br label %21
20: ; preds = %1
br label %21
21: ; preds = %20, %19, %18, %17, %16, %15, %14, %9
%22 = load i32, i32* %2
%23 = icmp sle i32 16, %22
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %2
%26 = sdiv i32 %25, 16
br label %27
27: ; preds = %24, %21
%28 = load i32, i32* @stderr
%29 = load i8, i8* %3
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %29)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [3 x i8] c"%c\00"
define void @to_hexadecimal(i32 %0) {
%2 = srem i32 %0, 16
%3 = trunc i32 %2 to i8
switch i32 %2, label %12 [
i32 0, label %4
i32 1, label %4
i32 2, label %4
i32 3, label %4
i32 4, label %4
i32 5, label %4
i32 6, label %4
i32 7, label %4
i32 8, label %4
i32 9, label %4
i32 10, label %6
i32 11, label %7
i32 12, label %8
i32 13, label %9
i32 14, label %10
i32 15, label %11
]
4: ; preds = %1, %1, %1, %1, %1, %1, %1, %1, %1, %1
%5 = add nuw nsw i8 %3, 48
br label %12
6: ; preds = %1
br label %12
7: ; preds = %1
br label %12
8: ; preds = %1
br label %12
9: ; preds = %1
br label %12
10: ; preds = %1
br label %12
11: ; preds = %1
br label %12
12: ; preds = %1, %11, %10, %9, %8, %7, %6, %4
%13 = phi i8 [ %3, %1 ], [ 70, %11 ], [ 69, %10 ], [ 68, %9 ], [ 67, %8 ], [ 66, %7 ], [ 65, %6 ], [ %5, %4 ]
%14 = icmp sgt i32 %0, 15
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = lshr i32 %0, 4
tail call void @to_hexadecimal(i32 %16)
br label %17
17: ; preds = %15, %12
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %13)
ret void
}