#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 */
char *shex2(char *, char *, int);
char *shex3(char *buf, char *end, int val) {
  if (buf <= end)
    *buf++ = ((((val >> 8) & 0xf) < 10 ? '0' + ((val >> 8) & 0xf)
                                       : 'A' + ((val >> 8) & 0xf) - 10));
  return shex2(buf, end, val);
}


x86 assembly (clang, -O0):
<shex3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     117f <shex3+0x6f>
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
and    $0xf,%eax
cmp    $0xa,%eax
jge    1157 <shex3+0x47>
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
and    $0xf,%eax
add    $0x30,%eax
mov    %eax,-0x18(%rbp)
jmp    1169 <shex3+0x59>
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
and    $0xf,%eax
add    $0x41,%eax
sub    $0xa,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <shex2@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shex3>:
cmp    %rsi,%rdi
ja     1137 <shex3+0x27>
mov    %edx,%eax
shr    $0x8,%eax
and    $0xf,%eax
lea    0x37(%rax),%r8d
lea    0x30(%rax),%ecx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %r8b,%ecx
cmovb  %eax,%ecx
mov    %cl,(%rdi)
add    $0x1,%rdi
jmp    1030 <shex2@plt>

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

LLVM IR (-O2):
define i8* @shex3(i8* %0, i8* %1, i32 %2) {
%4 = icmp ugt i8* %0, %1
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = lshr i32 %2, 8
%7 = and i32 %6, 15
%8 = icmp ult i32 %7, 10
%9 = or i32 %7, 48
%10 = add nuw nsw i32 %7, 55
%11 = select i1 %8, i32 %9, i32 %10
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %12, i8* %0
br label %14
14: ; preds = %5, %3
%15 = phi i8* [ %13, %5 ], [ %0, %3 ]
%16 = tail call i8* @shex2(i8* %15, i8* %1, i32 %2)
ret i8* %16
}