#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 */
int util_hex_to_nib(char);
unsigned int util_hex_to_word(char *p) {
  int val;
  int i;
  unsigned int retval = 0;
  for (i = 0; i < 8; i++) {
    val = util_hex_to_nib(*p);
    if (val < 0)
      return retval;
    retval <<= 4;
    retval |= (val & 0x0f);
    p++;
  }
  return retval;
}


x86 assembly (clang, -O0):
<util_hex_to_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    1187 <util_hex_to_word+0x77>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <util_hex_to_nib@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1158 <util_hex_to_word+0x48>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118d <util_hex_to_word+0x7d>
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
and    $0xf,%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <util_hex_to_word+0x1a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_hex_to_word>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1030 <util_hex_to_nib@plt>
test   %eax,%eax
js     11e8 <util_hex_to_word+0xd8>
mov    %eax,%ebx
and    $0xf,%ebx
movsbl 0x1(%r14),%edi
call   1030 <util_hex_to_nib@plt>
test   %eax,%eax
js     11ea <util_hex_to_word+0xda>
mov    %ebx,%ecx
shl    $0x4,%ecx
and    $0xf,%eax
mov    %eax,%ebx
or     %ecx,%ebx
movsbl 0x2(%r14),%edi
call   1030 <util_hex_to_nib@plt>
test   %eax,%eax
js     11ea <util_hex_to_word+0xda>
mov    %ebx,%ecx
shl    $0x4,%ecx
and    $0xf,%eax
mov    %eax,%ebx
or     %ecx,%ebx
movsbl 0x3(%r14),%edi
call   1030 <util_hex_to_nib@plt>
test   %eax,%eax
js     11ea <util_hex_to_word+0xda>
mov    %ebx,%ecx
shl    $0x4,%ecx
and    $0xf,%eax
mov    %eax,%ebx
or     %ecx,%ebx
movsbl 0x4(%r14),%edi
call   1030 <util_hex_to_nib@plt>
test   %eax,%eax
js     11ea <util_hex_to_word+0xda>
mov    %ebx,%ecx
shl    $0x4,%ecx
and    $0xf,%eax
mov    %eax,%ebx
or     %ecx,%ebx
movsbl 0x5(%r14),%edi
call   1030 <util_hex_to_nib@plt>
test   %eax,%eax
js     11ea <util_hex_to_word+0xda>
mov    %ebx,%ecx
shl    $0x4,%ecx
and    $0xf,%eax
mov    %eax,%ebx
or     %ecx,%ebx
movsbl 0x6(%r14),%edi
call   1030 <util_hex_to_nib@plt>
test   %eax,%eax
js     11ea <util_hex_to_word+0xda>
mov    %ebx,%ecx
shl    $0x4,%ecx
and    $0xf,%eax
mov    %eax,%ebx
or     %ecx,%ebx
movsbl 0x7(%r14),%edi
call   1030 <util_hex_to_nib@plt>
test   %eax,%eax
js     11ea <util_hex_to_word+0xda>
shl    $0x4,%ebx
and    $0xf,%eax
or     %eax,%ebx
jmp    11ea <util_hex_to_word+0xda>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @util_hex_to_word(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @util_hex_to_nib(i8 signext %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %63, label %5
5: ; preds = %1
%6 = and i32 %3, 15
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = tail call i32 @util_hex_to_nib(i8 signext %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %63, label %11
11: ; preds = %5
%12 = shl nuw nsw i32 %6, 4
%13 = and i32 %9, 15
%14 = or i32 %13, %12
%15 = getelementptr inbounds i8, i8* %0, i64 2
%16 = load i8, i8* %15
%17 = tail call i32 @util_hex_to_nib(i8 signext %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %63, label %19
19: ; preds = %11
%20 = shl nuw nsw i32 %14, 4
%21 = and i32 %17, 15
%22 = or i32 %21, %20
%23 = getelementptr inbounds i8, i8* %0, i64 3
%24 = load i8, i8* %23
%25 = tail call i32 @util_hex_to_nib(i8 signext %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %63, label %27
27: ; preds = %19
%28 = shl nuw nsw i32 %22, 4
%29 = and i32 %25, 15
%30 = or i32 %29, %28
%31 = getelementptr inbounds i8, i8* %0, i64 4
%32 = load i8, i8* %31
%33 = tail call i32 @util_hex_to_nib(i8 signext %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %63, label %35
35: ; preds = %27
%36 = shl i32 %30, 4
%37 = and i32 %33, 15
%38 = or i32 %37, %36
%39 = getelementptr inbounds i8, i8* %0, i64 5
%40 = load i8, i8* %39
%41 = tail call i32 @util_hex_to_nib(i8 signext %40)
%42 = icmp slt i32 %41, 0
br i1 %42, label %63, label %43
43: ; preds = %35
%44 = shl i32 %38, 4
%45 = and i32 %41, 15
%46 = or i32 %45, %44
%47 = getelementptr inbounds i8, i8* %0, i64 6
%48 = load i8, i8* %47
%49 = tail call i32 @util_hex_to_nib(i8 signext %48)
%50 = icmp slt i32 %49, 0
br i1 %50, label %63, label %51
51: ; preds = %43
%52 = shl i32 %46, 4
%53 = and i32 %49, 15
%54 = or i32 %53, %52
%55 = getelementptr inbounds i8, i8* %0, i64 7
%56 = load i8, i8* %55
%57 = tail call i32 @util_hex_to_nib(i8 signext %56)
%58 = icmp slt i32 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %51
%60 = shl i32 %54, 4
%61 = and i32 %57, 15
%62 = or i32 %61, %60
br label %63
63: ; preds = %59, %51, %43, %35, %27, %19, %11, %5, %1
%64 = phi i32 [ 0, %1 ], [ %6, %5 ], [ %14, %11 ], [ %22, %19 ], [ %30, %27 ], [ %38, %35 ], [ %46, %43 ], [ %54, %51 ], [ %62, %59 ]
ret i32 %64
}