#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);
int /*<<< orphan*/ putchar(char);
void printToHex(int n) {
  if (n == 0) {
    return;
  }
  int rem = n % 16;
  printToHex(n / 16);
  if (rem >= 10) {
    putchar((char)('a' + (rem - 10)));
  } else {
    printf("%d", rem);
  }
}


x86 assembly (clang, -O0):
<printToHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    114a <printToHex+0x1a>
jmp    1199 <printToHex+0x69>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <printToHex@plt>
cmpl   $0xa,-0x8(%rbp)
jl     118a <printToHex+0x5a>
mov    -0x8(%rbp),%eax
sub    $0xa,%eax
add    $0x61,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    1199 <printToHex+0x69>
mov    -0x8(%rbp),%esi
lea    0xe6c(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printToHex>:
push   %rbx
test   %edi,%edi
je     115f <printToHex+0x2f>
mov    %edi,%ebx
lea    0xf(%rbx),%edi
test   %ebx,%ebx
cmovns %ebx,%edi
mov    %edi,%eax
and    $0xfffffff0,%eax
sub    %eax,%ebx
sar    $0x4,%edi
call   1050 <printToHex@plt>
cmp    $0xa,%ebx
jl     1161 <printToHex+0x31>
add    $0x57,%bl
movsbl %bl,%edi
pop    %rbx
jmp    1030 <putchar@plt>
pop    %rbx
ret
lea    0xe98(%rip),%rdi
mov    %ebx,%esi
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define void @printToHex(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %1
br label %23
7: ; preds = %1
%8 = load i32, i32* %2
%9 = srem i32 %8, 16
store i32 %9, i32* %3
%10 = load i32, i32* %2
%11 = sdiv i32 %10, 16
%12 = load i32, i32* %3
%13 = icmp sge i32 %12, 10
br i1 %13, label %14, label %20
14: ; preds = %7
%15 = load i32, i32* %3
%16 = sub nsw i32 %15, 10
%17 = add nsw i32 97, %16
%18 = trunc i32 %17 to i8
%19 = call i32 @putchar(i8 signext %18)
br label %23
20: ; preds = %7
%21 = load i32, i32* %3
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %6, %20, %14
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @printToHex(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = srem i32 %0, 16
%5 = sdiv i32 %0, 16
tail call void @printToHex(i32 %5)
%6 = icmp sgt i32 %4, 9
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = trunc i32 %4 to i8
%9 = add nuw nsw i8 %8, 87
%10 = tail call i32 @putchar(i8 signext %9)
br label %13
11: ; preds = %3
%12 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %13
13: ; preds = %7, %11, %1
ret void
}