#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 hex2char(uint8_t hex, char *out) {
  out[0] = ((((hex & 0xf0) >> 4) >= 0xa) ? (((hex & 0xf0) >> 4) - 0xa + 'a')
                                         : (((hex & 0xf0) >> 4) + '0'));
  out[1] =
      (((hex & 0xf) >= 0xa) ? ((hex & 0xf) - 0xa + 'a') : ((hex & 0xf) + '0'));
}


x86 assembly (clang, -O0):
<hex2char>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
cmp    $0xa,%eax
jl     1138 <hex2char+0x38>
mov    -0x4(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
sub    $0xa,%eax
add    $0x61,%eax
mov    %eax,-0x14(%rbp)
jmp    1149 <hex2char+0x49>
mov    -0x4(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
add    $0x30,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
and    $0xf,%eax
cmp    $0xa,%eax
jl     1177 <hex2char+0x77>
mov    -0x4(%rbp),%eax
and    $0xf,%eax
sub    $0xa,%eax
add    $0x61,%eax
mov    %eax,-0x18(%rbp)
jmp    1183 <hex2char+0x83>
mov    -0x4(%rbp),%eax
and    $0xf,%eax
add    $0x30,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
pop    %rbp
ret

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

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

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