#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*/ printOct(int);
int /*<<< orphan*/ printf(char *, char);
void printHex(int number) {
  if (number > 0 && number / 16 != 0)
    printOct(number / 16);
  char digit;
  switch (number % 16) {
  case 10:
    digit = 'A';
    break;
  case 11:
    digit = 'B';
    break;
  case 12:
    digit = 'C';
    break;
  case 13:
    digit = 'D';
    break;
  case 14:
    digit = 'E';
    break;
  case 15:
    digit = 'F';
    break;
  default:
    digit = (char)((int)'0' + number % 16);
    break;
  }
  printf("%c", digit);
}


x86 assembly (clang, -O0):
<printHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    115b <printHex+0x3b>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%eax
je     115b <printHex+0x3b>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <printOct@plt>
mov    -0x4(%rbp),%edx
mov    %edx,%ecx
add    $0xf,%ecx
test   %edx,%edx
mov    %edx,%eax
cmovs  %ecx,%eax
and    $0xfffffff0,%eax
neg    %eax
mov    %eax,%ecx
mov    %edx,%eax
lea    -0xa(%rax,%rcx,1),%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x5,%eax
ja     11d0 <printHex+0xb0>
mov    -0x10(%rbp),%rax
lea    0xe6f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x41,-0x5(%rbp)
jmp    11e3 <printHex+0xc3>
movb   $0x42,-0x5(%rbp)
jmp    11e3 <printHex+0xc3>
movb   $0x43,-0x5(%rbp)
jmp    11e3 <printHex+0xc3>
movb   $0x44,-0x5(%rbp)
jmp    11e3 <printHex+0xc3>
movb   $0x45,-0x5(%rbp)
jmp    11e3 <printHex+0xc3>
movb   $0x46,-0x5(%rbp)
jmp    11e3 <printHex+0xc3>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%al
mov    %al,-0x5(%rbp)
lea    0xe2e(%rip),%rdi
movsbl -0x5(%rbp),%esi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printHex>:
push   %rbx
mov    %edi,%ebx
cmp    $0x10,%edi
jl     1132 <printHex+0x12>
mov    %ebx,%edi
shr    $0x4,%edi
call   1030 <printOct@plt>
lea    0xf(%rbx),%eax
test   %ebx,%ebx
cmovns %ebx,%eax
and    $0xfffffff0,%eax
mov    %ebx,%ecx
sub    %eax,%ecx
neg    %eax
add    %ebx,%eax
add    $0xfffffff6,%eax
cmp    $0x6,%eax
mov    $0x41,%edx
mov    $0x30,%esi
cmovb  %edx,%esi
cmovb  %eax,%ecx
add    %sil,%cl
movsbl %cl,%esi
lea    0xe98(%rip),%rdi
pop    %rbx
jmp    1040 <printf@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @printHex(i32 %0) {
%2 = icmp slt i32 %0, 16
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = lshr i32 %0, 4
%5 = tail call i32 @printOct(i32 %4)
br label %6
6: ; preds = %3, %1
%7 = srem i32 %0, 16
%8 = add nsw i32 %7, -10
%9 = icmp ult i32 %8, 6
%10 = select i1 %9, i32 %8, i32 %7
%11 = select i1 %9, i8 65, i8 48
%12 = trunc i32 %10 to i8
%13 = add i8 %11, %12
%14 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %13)
ret void
}