#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 */
unsigned long _from_hex(int /*<<< orphan*/);
scalar_t__ _is_hex(unsigned char);
unsigned long _hex(char **_cp) {
  unsigned long val;
  unsigned char *cp = *_cp;
  val = 0;
  while (_is_hex(*cp)) {
    val = (val << 4) | _from_hex(*cp++);
  }
  *_cp = cp;
  return val;
}


x86 assembly (clang, -O0):
<_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1040 <_is_hex@plt>
cmp    $0x0,%rax
je     118b <_hex+0x6b>
mov    -0x10(%rbp),%rax
shl    $0x4,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movzbl (%rax),%edi
call   1030 <_from_hex@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
or     %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    113f <_hex+0x1f>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_hex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%r15
movzbl (%r15),%edi
call   1040 <_is_hex@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1179 <_hex+0x59>
mov    %r15,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
shl    $0x4,%rbx
lea    0x1(%r12),%r15
movzbl (%r12),%edi
call   1030 <_from_hex@plt>
or     %rax,%rbx
movzbl 0x1(%r12),%edi
call   1040 <_is_hex@plt>
mov    %r15,%r12
test   %rax,%rax
jne    1150 <_hex+0x30>
mov    %r15,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @_hex(i8** %0) {
%2 = alloca i8**
%3 = alloca i64
%4 = alloca i8*
store i8** %0, i8*** %2
%5 = load i8**, i8*** %2
%6 = load i8*, i8** %5
store i8* %6, i8** %4
store i64 0, i64* %3
br label %7
7: ; preds = %12, %1
%8 = load i8*, i8** %4
%9 = load i8, i8* %8
%10 = call i64 @_is_hex(i8 zeroext %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %7
%13 = load i64, i64* %3
%14 = shl i64 %13, 4
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %4
%17 = load i8, i8* %15
%18 = zext i8 %17 to i32
%19 = call i64 @_from_hex(i32 %18)
%20 = or i64 %14, %19
store i64 %20, i64* %3
br label %7
21: ; preds = %7
%22 = load i8*, i8** %4
%23 = load i8**, i8*** %2
store i8* %22, i8** %23
%24 = load i64, i64* %3
ret i64 %24
}

LLVM IR (-O2):
define i64 @_hex(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = load i8, i8* %2
%4 = tail call i64 @_is_hex(i8 zeroext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %1, %6
%7 = phi i8* [ %10, %6 ], [ %2, %1 ]
%8 = phi i64 [ %14, %6 ], [ 0, %1 ]
%9 = shl i64 %8, 4
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = load i8, i8* %7
%12 = zext i8 %11 to i32
%13 = tail call i64 @_from_hex(i32 %12)
%14 = or i64 %13, %9
%15 = load i8, i8* %10
%16 = tail call i64 @_is_hex(i8 zeroext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %6, %1
%19 = phi i64 [ 0, %1 ], [ %14, %6 ]
%20 = phi i8* [ %2, %1 ], [ %10, %6 ]
store i8* %20, i8** %0
ret i64 %19
}