#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 *, ...);
void printToHex(int n, int step) {
  if (step == 1 && n == 0) {
    printf("00");
  } else if (n <= 15 && step == 1) {
    printf("0");
  } else if (n == 0) {
    return;
  }
  int rem = n % 16;
  printToHex(n / 16, step + 1);
  if (rem >= 10) {
    printf("%c", (char)('a' + (rem - 10)));
  } else if (n != 0) {
    printf("%d", rem);
  }
}


x86 assembly (clang, -O0):
<printToHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1155 <printToHex+0x35>
cmpl   $0x0,-0x4(%rbp)
jne    1155 <printToHex+0x35>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1195 <printToHex+0x75>
cmpl   $0xf,-0x4(%rbp)
jg     117c <printToHex+0x5c>
cmpl   $0x1,-0x8(%rbp)
jne    117c <printToHex+0x5c>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1190 <printToHex+0x70>
cmpl   $0x0,-0x4(%rbp)
jne    118b <printToHex+0x6b>
jmp    1204 <printToHex+0xe4>
jmp    1190 <printToHex+0x70>
jmp    1195 <printToHex+0x75>
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
call   1040 <printToHex@plt>
cmpl   $0xa,-0xc(%rbp)
jl     11e4 <printToHex+0xc4>
mov    -0xc(%rbp),%eax
sub    $0xa,%eax
add    $0x61,%eax
movsbl %al,%esi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1204 <printToHex+0xe4>
cmpl   $0x0,-0x4(%rbp)
je     11ff <printToHex+0xdf>
mov    -0xc(%rbp),%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1204 <printToHex+0xe4>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printToHex>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebx
test   %edi,%edi
jne    1153 <printToHex+0x23>
cmp    $0x1,%r14d
jne    1153 <printToHex+0x23>
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    116e <printToHex+0x3e>
cmp    $0xf,%ebx
jg     116a <printToHex+0x3a>
cmp    $0x1,%r14d
jne    116a <printToHex+0x3a>
mov    $0x30,%edi
call   1030 <putchar@plt>
jmp    116e <printToHex+0x3e>
test   %ebx,%ebx
je     11b9 <printToHex+0x89>
lea    0xf(%rbx),%edi
test   %ebx,%ebx
cmovns %ebx,%edi
mov    %edi,%eax
and    $0xfffffff0,%eax
mov    %ebx,%ebp
sub    %eax,%ebp
sar    $0x4,%edi
add    $0x1,%r14d
mov    %r14d,%esi
call   1050 <printToHex@plt>
cmp    $0xa,%ebp
jl     11a1 <printToHex+0x71>
add    $0x57,%ebp
mov    %ebp,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>
test   %ebx,%ebx
je     11b9 <printToHex+0x89>
lea    0xe57(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"00\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [3 x i8] c"%d\00"
define void @printToHex(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %27
13: ; preds = %8, %2
%14 = load i32, i32* %3
%15 = icmp sle i32 %14, 15
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %26
21: ; preds = %16, %13
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
br label %50
25: ; preds = %21
br label %26
26: ; preds = %25, %19
br label %27
27: ; preds = %26, %11
%28 = load i32, i32* %3
%29 = srem i32 %28, 16
store i32 %29, i32* %5
%30 = load i32, i32* %3
%31 = sdiv i32 %30, 16
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
%34 = load i32, i32* %5
%35 = icmp sge i32 %34, 10
br i1 %35, label %36, label %43
36: ; preds = %27
%37 = load i32, i32* %5
%38 = sub nsw i32 %37, 10
%39 = add nsw i32 97, %38
%40 = trunc i32 %39 to i8
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %41)
br label %50
43: ; preds = %27
%44 = load i32, i32* %3
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* %5
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %46, %43
br label %50
50: ; preds = %24, %49, %36
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"00\00"
@.str.3 = [3 x i8] c"%d\00"
define void @printToHex(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 1
%4 = icmp eq i32 %0, 0
%5 = and i1 %4, %3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %14
8: ; preds = %2
%9 = icmp slt i32 %0, 16
%10 = and i1 %9, %3
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @putchar(i32 48)
br label %14
13: ; preds = %8
br i1 %4, label %25, label %14
14: ; preds = %11, %13, %6
%15 = srem i32 %0, 16
%16 = sdiv i32 %0, 16
%17 = add nsw i32 %1, 1
tail call void @printToHex(i32 %16, i32 %17)
%18 = icmp sgt i32 %15, 9
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = add nuw nsw i32 %15, 87
%21 = tail call i32 @putchar(i32 %20)
br label %25
22: ; preds = %14
br i1 %4, label %25, label %23
23: ; preds = %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %15)
br label %25
25: ; preds = %19, %23, %22, %13
ret void
}