#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ terminal_putchar(int);
void terminal_writehexdigits(uint8_t digit) {
  uint8_t low = digit & 0x0F;
  uint8_t high = (digit & 0xF0) >> 4;
  if (high > 9) {
    terminal_putchar('A' + high - 10);
  } else {
    terminal_putchar('0' + high);
  }
  if (low > 9) {
    terminal_putchar('A' + low - 10);
  } else {
    terminal_putchar('0' + low);
  }
}


x86 assembly (clang, -O0):
<terminal_writehexdigits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x9,-0xc(%rbp)
jle    114f <terminal_writehexdigits+0x3f>
mov    -0xc(%rbp),%edi
add    $0x41,%edi
sub    $0xa,%edi
call   1030 <terminal_putchar@plt>
jmp    115a <terminal_writehexdigits+0x4a>
mov    -0xc(%rbp),%edi
add    $0x30,%edi
call   1030 <terminal_putchar@plt>
cmpl   $0x9,-0x8(%rbp)
jle    1177 <terminal_writehexdigits+0x67>
mov    -0x8(%rbp),%edi
add    $0x41,%edi
sub    $0xa,%edi
call   1030 <terminal_putchar@plt>
jmp    1182 <terminal_writehexdigits+0x72>
mov    -0x8(%rbp),%edi
add    $0x30,%edi
call   1030 <terminal_putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<terminal_writehexdigits>:
push   %rbx
mov    %edi,%ebx
and    $0xf,%ebx
shr    $0x4,%edi
and    $0xf,%edi
lea    0x30(%rdi),%ecx
lea    0x37(%rdi),%eax
cmp    $0xa,%edi
cmovb  %ecx,%eax
mov    %eax,%edi
call   1030 <terminal_putchar@plt>
lea    0x30(%rbx),%eax
lea    0x37(%rbx),%edi
cmp    $0xa,%ebx
cmovb  %eax,%edi
pop    %rbx
jmp    1030 <terminal_putchar@plt>

LLVM IR (-O0):
define void @terminal_writehexdigits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = and i32 %5, 15
store i32 %6, i32* %3
%7 = load i32, i32* %2
%8 = and i32 %7, 240
%9 = ashr i32 %8, 4
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 9
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i32, i32* %4
%14 = add nsw i32 65, %13
%15 = sub nsw i32 %14, 10
%16 = call i32 @terminal_putchar(i32 %15)
br label %21
17: ; preds = %1
%18 = load i32, i32* %4
%19 = add nsw i32 48, %18
%20 = call i32 @terminal_putchar(i32 %19)
br label %21
21: ; preds = %17, %12
%22 = load i32, i32* %3
%23 = icmp sgt i32 %22, 9
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i32, i32* %3
%26 = add nsw i32 65, %25
%27 = sub nsw i32 %26, 10
%28 = call i32 @terminal_putchar(i32 %27)
br label %33
29: ; preds = %21
%30 = load i32, i32* %3
%31 = add nsw i32 48, %30
%32 = call i32 @terminal_putchar(i32 %31)
br label %33
33: ; preds = %29, %24
ret void
}

LLVM IR (-O2):
define void @terminal_writehexdigits(i32 %0) {
%2 = and i32 %0, 15
%3 = lshr i32 %0, 4
%4 = and i32 %3, 15
%5 = icmp ugt i32 %4, 9
%6 = or i32 %4, 48
%7 = add nuw nsw i32 %4, 55
%8 = select i1 %5, i32 %7, i32 %6
%9 = tail call i32 @terminal_putchar(i32 %8)
%10 = icmp ugt i32 %2, 9
%11 = or i32 %2, 48
%12 = add nuw nsw i32 %2, 55
%13 = select i1 %10, i32 %12, i32 %11
%14 = tail call i32 @terminal_putchar(i32 %13)
ret void
}