#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*/ putchar(int);
void printhex(int h) {
  if (h == 0) {
    putchar(0);
  } else {
    int pos = h % 16;
    printhex(h / 16);
    if (pos == 10) {
      putchar(97);
    } else if (pos == 11) {
      putchar(98);
    } else if (pos == 12) {
      putchar(99);
    } else if (pos == 13) {
      putchar(100);
    } else if (pos == 14) {
      putchar(101);
    } else if (pos == 15) {
      putchar(102);
    } else {
      putchar(pos + 48);
    }
  }
}


x86 assembly (clang, -O0):
<printhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1141 <printhex+0x21>
xor    %edi,%edi
call   1030 <putchar@plt>
jmp    1220 <printhex+0x100>
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   1040 <printhex@plt>
cmpl   $0xa,-0x8(%rbp)
jne    117a <printhex+0x5a>
mov    $0x61,%edi
call   1030 <putchar@plt>
jmp    121b <printhex+0xfb>
cmpl   $0xb,-0x8(%rbp)
jne    1193 <printhex+0x73>
mov    $0x62,%edi
call   1030 <putchar@plt>
jmp    1216 <printhex+0xf6>
cmpl   $0xc,-0x8(%rbp)
jne    11ac <printhex+0x8c>
mov    $0x63,%edi
call   1030 <putchar@plt>
jmp    1211 <printhex+0xf1>
cmpl   $0xd,-0x8(%rbp)
jne    11c5 <printhex+0xa5>
mov    $0x64,%edi
call   1030 <putchar@plt>
jmp    120c <printhex+0xec>
cmpl   $0xe,-0x8(%rbp)
jne    11de <printhex+0xbe>
mov    $0x65,%edi
call   1030 <putchar@plt>
jmp    1207 <printhex+0xe7>
cmpl   $0xf,-0x8(%rbp)
jne    11f7 <printhex+0xd7>
mov    $0x66,%edi
call   1030 <putchar@plt>
jmp    1202 <printhex+0xe2>
mov    -0x8(%rbp),%edi
add    $0x30,%edi
call   1030 <putchar@plt>
jmp    1207 <printhex+0xe7>
jmp    120c <printhex+0xec>
jmp    1211 <printhex+0xf1>
jmp    1216 <printhex+0xf6>
jmp    121b <printhex+0xfb>
jmp    1220 <printhex+0x100>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhex>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
je     1158 <printhex+0x38>
mov    %edi,%ebx
lea    0xf(%rbx),%edi
test   %ebx,%ebx
cmovns %ebx,%edi
mov    %edi,%ebp
and    $0xfffffff0,%ebp
mov    %ebx,%r14d
sub    %ebp,%r14d
sar    $0x4,%edi
call   1040 <printhex@plt>
neg    %ebp
lea    (%rbx,%rbp,1),%eax
add    $0xfffffff6,%eax
cmp    $0x6,%eax
jae    115d <printhex+0x3d>
add    $0x57,%r14d
jmp    1161 <printhex+0x41>
xor    %r14d,%r14d
jmp    1161 <printhex+0x41>
add    $0x30,%r14d
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
define void @printhex(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 %8
6: ; preds = %1
%7 = call i32 @putchar(i32 0)
br label %52
8: ; preds = %1
%9 = load i32, i32* %2
%10 = srem i32 %9, 16
store i32 %10, i32* %3
%11 = load i32, i32* %2
%12 = sdiv i32 %11, 16
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 @putchar(i32 97)
br label %51
17: ; preds = %8
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 11
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @putchar(i32 98)
br label %50
22: ; preds = %17
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 12
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @putchar(i32 99)
br label %49
27: ; preds = %22
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 13
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @putchar(i32 100)
br label %48
32: ; preds = %27
%33 = load i32, i32* %3
%34 = icmp eq i32 %33, 14
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @putchar(i32 101)
br label %47
37: ; preds = %32
%38 = load i32, i32* %3
%39 = icmp eq i32 %38, 15
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @putchar(i32 102)
br label %46
42: ; preds = %37
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 48
%45 = call i32 @putchar(i32 %44)
br label %46
46: ; preds = %42, %40
br label %47
47: ; preds = %46, %35
br label %48
48: ; preds = %47, %30
br label %49
49: ; preds = %48, %25
br label %50
50: ; preds = %49, %20
br label %51
51: ; preds = %50, %15
br label %52
52: ; preds = %51, %6
ret void
}

LLVM IR (-O2):
define void @printhex(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = srem i32 %0, 16
%5 = sdiv i32 %0, 16
tail call void @printhex(i32 %5)
%6 = add nsw i32 %4, -10
%7 = icmp ult i32 %6, 6
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = add nsw i32 %4, 48
br label %12
10: ; preds = %3
%11 = add nsw i32 %4, 87
br label %12
12: ; preds = %10, %1, %8
%13 = phi i32 [ %9, %8 ], [ 0, %1 ], [ %11, %10 ]
%14 = tail call i32 @putchar(i32 %13)
ret void
}