#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 hex_val_char(char);
char hex_val(char **h) {
  char *s = *h;
  char val = 0;
  if (*s) {
    val = hex_val_char(*s) << 4;
    ++s;
    if (*s)
      val += hex_val_char(*s++);
  }
  *h = s;
  return val;
}


x86 assembly (clang, -O0):
<hex_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     118e <hex_val+0x7e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <hex_val_char@plt>
movsbl %al,%eax
shl    $0x4,%eax
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1189 <hex_val+0x79>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edi
call   1030 <hex_val_char@plt>
movsbl %al,%ecx
movsbl -0x11(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x11(%rbp)
jmp    118e <hex_val+0x7e>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movsbl -0x11(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_val>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%rbx
mov    (%rbx),%al
test   %al,%al
je     1148 <hex_val+0x38>
movsbl %al,%edi
call   1030 <hex_val_char@plt>
mov    %eax,%ebp
shl    $0x4,%bpl
mov    0x1(%rbx),%al
test   %al,%al
je     114c <hex_val+0x3c>
add    $0x2,%rbx
movsbl %al,%edi
call   1030 <hex_val_char@plt>
add    %bpl,%al
mov    %eax,%ebp
jmp    1150 <hex_val+0x40>
xor    %ebp,%ebp
jmp    1150 <hex_val+0x40>
add    $0x1,%rbx
mov    %rbx,(%r14)
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @hex_val(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8
store i8** %0, i8*** %2
%5 = load i8**, i8*** %2
%6 = load i8*, i8** %5
store i8* %6, i8** %3
store i8 0, i8* %4
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %33
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = call signext i8 @hex_val_char(i8 signext %12)
%14 = sext i8 %13 to i32
%15 = shl i32 %14, 4
%16 = trunc i32 %15 to i8
store i8 %16, i8* %4
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %10
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %3
%25 = load i8, i8* %23
%26 = call signext i8 @hex_val_char(i8 signext %25)
%27 = sext i8 %26 to i32
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = add nsw i32 %29, %27
%31 = trunc i32 %30 to i8
store i8 %31, i8* %4
br label %32
32: ; preds = %22, %10
br label %33
33: ; preds = %32, %1
%34 = load i8*, i8** %3
%35 = load i8**, i8*** %2
store i8* %34, i8** %35
%36 = load i8, i8* %4
ret i8 %36
}

LLVM IR (-O2):
define signext i8 @hex_val(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = tail call signext i8 @hex_val_char(i8 signext %3)
%7 = shl i8 %6, 4
%8 = getelementptr inbounds i8, i8* %2, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %2, i64 2
%13 = tail call signext i8 @hex_val_char(i8 signext %9)
%14 = add i8 %13, %7
br label %15
15: ; preds = %5, %11, %1
%16 = phi i8* [ %12, %11 ], [ %8, %5 ], [ %2, %1 ]
%17 = phi i8 [ %14, %11 ], [ %7, %5 ], [ 0, %1 ]
store i8* %16, i8** %0
ret i8 %17
}