#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 */
void byte_to_hex(char *digits, uint8_t byte) {
  uint8_t nybbel = byte >> 4;
  if (nybbel > 9)
    digits[0] = 'a' + nybbel - 10;
  else
    digits[0] = '0' + nybbel;
  nybbel = byte & 0x0f;
  if (nybbel > 9)
    digits[1] = 'a' + nybbel - 10;
  else
    digits[1] = '0' + nybbel;
}


x86 assembly (clang, -O0):
<byte_to_hex>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x9,-0x10(%rbp)
jle    1134 <byte_to_hex+0x34>
mov    -0x10(%rbp),%eax
add    $0x61,%eax
sub    $0xa,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
jmp    1142 <byte_to_hex+0x42>
mov    -0x10(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x9,-0x10(%rbp)
jle    116c <byte_to_hex+0x6c>
mov    -0x10(%rbp),%eax
add    $0x61,%eax
sub    $0xa,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
jmp    117b <byte_to_hex+0x7b>
mov    -0x10(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<byte_to_hex>:
mov    %esi,%eax
shr    $0x4,%eax
cmp    $0xa0,%esi
mov    $0x57,%ecx
mov    $0x30,%edx
cmovge %ecx,%edx
add    %al,%dl
mov    %dl,(%rdi)
and    $0xf,%esi
lea    0x57(%rsi),%eax
lea    0x30(%rsi),%ecx
cmp    $0xa,%esi
movzbl %al,%eax
movzbl %cl,%ecx
cmovae %eax,%ecx
mov    %cl,0x1(%rdi)
ret

LLVM IR (-O0):
define void @byte_to_hex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = ashr i32 %6, 4
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sgt i32 %8, 9
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* %5
%12 = add nsw i32 97, %11
%13 = sub nsw i32 %12, 10
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 %14, i8* %16
br label %23
17: ; preds = %2
%18 = load i32, i32* %5
%19 = add nsw i32 48, %18
%20 = trunc i32 %19 to i8
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 %20, i8* %22
br label %23
23: ; preds = %17, %10
%24 = load i32, i32* %4
%25 = and i32 %24, 15
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = icmp sgt i32 %26, 9
br i1 %27, label %28, label %35
28: ; preds = %23
%29 = load i32, i32* %5
%30 = add nsw i32 97, %29
%31 = sub nsw i32 %30, 10
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8 %32, i8* %34
br label %41
35: ; preds = %23
%36 = load i32, i32* %5
%37 = add nsw i32 48, %36
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8 %38, i8* %40
br label %41
41: ; preds = %35, %28
ret void
}

LLVM IR (-O2):
define void @byte_to_hex(i8* nocapture writeonly %0, i32 %1) {
%3 = lshr i32 %1, 4
%4 = icmp sgt i32 %1, 159
%5 = trunc i32 %3 to i8
%6 = select i1 %4, i8 87, i8 48
%7 = add i8 %6, %5
store i8 %7, i8* %0
%8 = and i32 %1, 15
%9 = icmp ugt i32 %8, 9
%10 = trunc i32 %8 to i8
%11 = add nuw nsw i8 %10, 87
%12 = or i8 %10, 48
%13 = select i1 %9, i8 %11, i8 %12
%14 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %13, i8* %14
ret void
}