#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
scalar_t__ isxdigit(int);
const uint32_t hex_uint32(const char *s) {
  uint32_t ret = 0;
  uint8_t nibble;
  while (*s != '\0') {
    char d = *s;
    if (isxdigit((int)d) == 0) {
      break;
    }
    nibble = d > '9' ? ((uint8_t)d | (uint8_t)0x20) - (uint8_t)'a' + (uint8_t)10
                     : (uint8_t)(d - '0');
    ret = (ret << 4) | nibble;
    s++;
  }
  return ret;
}


x86 assembly (clang, -O0):
<hex_uint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a3 <hex_uint32+0x93>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%edi
call   1030 <isxdigit@plt>
cmp    $0x0,%rax
jne    1154 <hex_uint32+0x44>
jmp    11a3 <hex_uint32+0x93>
movsbl -0x11(%rbp),%eax
cmp    $0x39,%eax
jle    1176 <hex_uint32+0x66>
movsbl -0x11(%rbp),%eax
or     $0x20,%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x18(%rbp)
jmp    1180 <hex_uint32+0x70>
movsbl -0x11(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1123 <hex_uint32+0x13>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_uint32>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     1163 <hex_uint32+0x53>
mov    %rdi,%r14
add    $0x1,%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%ebx
mov    %ebx,%edi
call   1030 <isxdigit@plt>
test   %rax,%rax
je     1165 <hex_uint32+0x55>
mov    %ebx,%eax
or     $0x20,%eax
add    $0xffffffa9,%eax
lea    -0x30(%rbx),%ecx
cmp    $0x3a,%bl
cmovge %eax,%ecx
shl    $0x4,%ebp
or     %ecx,%ebp
movzbl (%r14),%eax
add    $0x1,%r14
test   %al,%al
jne    1130 <hex_uint32+0x20>
jmp    1165 <hex_uint32+0x55>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hex_uint32(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
br label %6
6: ; preds = %33, %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %41
11: ; preds = %6
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
store i8 %13, i8* %5
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = call i64 @isxdigit(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %11
br label %41
19: ; preds = %11
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
%22 = icmp sgt i32 %21, 57
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i8, i8* %5
%25 = sext i8 %24 to i32
%26 = or i32 %25, 32
%27 = sub nsw i32 %26, 97
%28 = add nsw i32 %27, 10
br label %33
29: ; preds = %19
%30 = load i8, i8* %5
%31 = sext i8 %30 to i32
%32 = sub nsw i32 %31, 48
br label %33
33: ; preds = %29, %23
%34 = phi i32 [ %28, %23 ], [ %32, %29 ]
store i32 %34, i32* %4
%35 = load i32, i32* %3
%36 = shl i32 %35, 4
%37 = load i32, i32* %4
%38 = or i32 %36, %37
store i32 %38, i32* %3
%39 = load i8*, i8** %2
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %2
br label %6
41: ; preds = %18, %6
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @hex_uint32(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %1, %11
%5 = phi i8 [ %20, %11 ], [ %2, %1 ]
%6 = phi i8* [ %19, %11 ], [ %0, %1 ]
%7 = phi i32 [ %18, %11 ], [ 0, %1 ]
%8 = sext i8 %5 to i32
%9 = tail call i64 @isxdigit(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %4
%12 = icmp sgt i8 %5, 57
%13 = or i32 %8, 32
%14 = add nsw i32 %13, -87
%15 = add nsw i32 %8, -48
%16 = select i1 %12, i32 %14, i32 %15
%17 = shl i32 %7, 4
%18 = or i32 %16, %17
%19 = getelementptr inbounds i8, i8* %6, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %4
22: ; preds = %11, %4, %1
%23 = phi i32 [ 0, %1 ], [ %7, %4 ], [ %18, %11 ]
ret i32 %23
}