#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 */
scalar_t__ fisxdigit(char const);
int /*<<< orphan*/ printf(char *, unsigned char);
long strtoul(char *, char **, int);
void print_hex(const char **msg) {
  char buf[4];
  char *end;
  long n;
  unsigned char c;
  int i;
  if (!fisxdigit(**msg))
    return;
  for (i = 0; fisxdigit(**msg) && i < 2; ++*msg, ++i)
    buf[i] = **msg;
  buf[i] = 0;
  --*msg;
  n = strtoul(buf, &end, 16);
  printf("%c", (c = n));
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <fisxdigit@plt>
cmp    $0x0,%rax
jne    115a <print_hex+0x2a>
jmp    120c <print_hex+0xdc>
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <fisxdigit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
je     118c <print_hex+0x5c>
cmpl   $0x2,-0x28(%rbp)
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    119c <print_hex+0x6c>
jmp    11c9 <print_hex+0x99>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%cl
movslq -0x28(%rbp),%rax
mov    %cl,-0xc(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1161 <print_hex+0x31>
movslq -0x28(%rbp),%rax
movb   $0x0,-0xc(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,(%rax)
lea    -0xc(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %al,-0x21(%rbp)
lea    0xdfc(%rip),%rdi
movzbl %al,%esi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    (%rdi),%rax
movsbl (%rax),%edi
call   1030 <fisxdigit@plt>
test   %rax,%rax
je     11cf <print_hex+0x9f>
mov    (%rbx),%rax
movsbl (%rax),%edi
call   1030 <fisxdigit@plt>
test   %rax,%rax
je     119a <print_hex+0x6a>
mov    (%rbx),%rax
mov    (%rax),%cl
mov    %cl,0x4(%rsp)
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movsbl 0x1(%rax),%edi
call   1030 <fisxdigit@plt>
test   %rax,%rax
je     119e <print_hex+0x6e>
mov    (%rbx),%rax
mov    (%rax),%cl
mov    %cl,0x5(%rsp)
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movsbl 0x1(%rax),%edi
call   1030 <fisxdigit@plt>
mov    $0x2,%eax
jmp    11a3 <print_hex+0x73>
xor    %eax,%eax
jmp    11a3 <print_hex+0x73>
mov    $0x1,%eax
movb   $0x0,0x4(%rsp,%rax,1)
addq   $0xffffffffffffffff,(%rbx)
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0x10,%edx
call   1050 <strtoul@plt>
movzbl %al,%esi
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @print_hex(i8** %0) {
%2 = alloca i8**
%3 = alloca [4 x i8]
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8
%7 = alloca i32
store i8** %0, i8*** %2
%8 = load i8**, i8*** %2
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = call i64 @fisxdigit(i8 signext %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %1
br label %51
14: ; preds = %1
store i32 0, i32* %7
br label %15
15: ; preds = %33, %14
%16 = load i8**, i8*** %2
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = call i64 @fisxdigit(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 2
br label %24
24: ; preds = %21, %15
%25 = phi i1 [ false, %15 ], [ %23, %21 ]
br i1 %25, label %26, label %39
26: ; preds = %24
%27 = load i8**, i8*** %2
%28 = load i8*, i8** %27
%29 = load i8, i8* %28
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %31
store i8 %29, i8* %32
br label %33
33: ; preds = %26
%34 = load i8**, i8*** %2
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %34
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %15
39: ; preds = %24
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %41
store i8 0, i8* %42
%43 = load i8**, i8*** %2
%44 = load i8*, i8** %43
%45 = getelementptr inbounds i8, i8* %44, i32 -1
store i8* %45, i8** %43
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%47 = call i64 @strtoul(i8* %46, i8** %4, i32 16)
store i64 %47, i64* %5
%48 = load i64, i64* %5
%49 = trunc i64 %48 to i8
store i8 %49, i8* %6
%50 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %49)
br label %51
51: ; preds = %39, %13
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @print_hex(i8** nocapture %0) {
%2 = alloca [4 x i8]
%3 = alloca i8*
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%5 = bitcast i8** %3 to i8*
%6 = load i8*, i8** %0
%7 = load i8, i8* %6
%8 = tail call i64 @fisxdigit(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %38, label %10
10: ; preds = %1
%11 = load i8*, i8** %0
%12 = load i8, i8* %11
%13 = tail call i64 @fisxdigit(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %30, label %15
15: ; preds = %10
%16 = load i8*, i8** %0
%17 = load i8, i8* %16
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
store i8 %17, i8* %18
%19 = getelementptr inbounds i8, i8* %16, i64 1
store i8* %19, i8** %0
%20 = load i8, i8* %19
%21 = tail call i64 @fisxdigit(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %30, label %23
23: ; preds = %15
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
%25 = load i8*, i8** %0
%26 = load i8, i8* %25
store i8 %26, i8* %24
%27 = getelementptr inbounds i8, i8* %25, i64 1
store i8* %27, i8** %0
%28 = load i8, i8* %27
%29 = tail call i64 @fisxdigit(i8 signext %28)
br label %30
30: ; preds = %15, %23, %10
%31 = phi i64 [ 0, %10 ], [ 1, %15 ], [ 2, %23 ]
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %0
%34 = getelementptr inbounds i8, i8* %33, i64 -1
store i8* %34, i8** %0
%35 = call i64 @strtoul(i8* %4, i8** %3, i32 16)
%36 = trunc i64 %35 to i8
%37 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %36)
br label %38
38: ; preds = %1, %30
ret void
}