#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 uint64_t;

/* Variables and functions */
scalar_t__ is_hex(char const);
int parse_hex(char const);
uint64_t __get_uint_hex(const char *s) {
  uint64_t res = 0;
  while (*s) {
    if (is_hex(*s))
      res = (res << 4) + parse_hex(*s);
    else if (*s != '_')
      break;
    s++;
  }
  return res;
}


x86 assembly (clang, -O0):
<__get_uint_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a5 <__get_uint_hex+0x85>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <is_hex@plt>
cmp    $0x0,%rax
je     117a <__get_uint_hex+0x5a>
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <parse_hex@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <__get_uint_hex+0x74>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
je     118f <__get_uint_hex+0x6f>
jmp    11a5 <__get_uint_hex+0x85>
jmp    1194 <__get_uint_hex+0x74>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1133 <__get_uint_hex+0x13>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__get_uint_hex>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     115d <__get_uint_hex+0x3d>
mov    %rdi,%rbx
xor    %ebp,%ebp
jmp    1149 <__get_uint_hex+0x29>
shl    $0x4,%ebp
movsbl (%rbx),%edi
call   1040 <parse_hex@plt>
add    %eax,%ebp
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     115f <__get_uint_hex+0x3f>
movsbl %al,%edi
call   1030 <is_hex@plt>
test   %rax,%rax
jne    1130 <__get_uint_hex+0x10>
cmpb   $0x5f,(%rbx)
je     113d <__get_uint_hex+0x1d>
jmp    115f <__get_uint_hex+0x3f>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @__get_uint_hex(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %23, label %4
4: ; preds = %1, %18
%5 = phi i8 [ %21, %18 ], [ %2, %1 ]
%6 = phi i32 [ %19, %18 ], [ 0, %1 ]
%7 = phi i8* [ %20, %18 ], [ %0, %1 ]
%8 = tail call i64 @is_hex(i8 signext %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %4
%11 = shl i32 %6, 4
%12 = load i8, i8* %7
%13 = tail call i32 @parse_hex(i8 signext %12)
%14 = add nsw i32 %13, %11
br label %18
15: ; preds = %4
%16 = load i8, i8* %7
%17 = icmp eq i8 %16, 95
br i1 %17, label %18, label %23
18: ; preds = %15, %10
%19 = phi i32 [ %14, %10 ], [ %6, %15 ]
%20 = getelementptr inbounds i8, i8* %7, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %4
23: ; preds = %18, %15, %1
%24 = phi i32 [ 0, %1 ], [ %6, %15 ], [ %19, %18 ]
ret i32 %24
}