#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 hwp_hex(char);
unsigned long int hwp_hex2reg(char *buf) {
  int n;
  unsigned long int val = 0;
  for (n = 0; n < 8; n++) {
    int nyb_shift = 28 - (n * 4);
    val |= hwp_hex(buf[n]) << nyb_shift;
  }
  return val;
}


x86 assembly (clang, -O0):
<hwp_hex2reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    1173 <hwp_hex2reg+0x63>
mov    -0xc(%rbp),%ecx
shl    $0x2,%ecx
mov    $0x1c,%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <hwp_hex@plt>
mov    -0x1c(%rbp),%ecx
shl    %cl,%eax
cltq
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112b <hwp_hex2reg+0x1b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hwp_hex2reg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1030 <hwp_hex@plt>
mov    %eax,%ebp
shl    $0x1c,%ebp
movsbl 0x1(%r14),%edi
call   1030 <hwp_hex@plt>
mov    %eax,%ebx
shl    $0x18,%ebx
or     %ebp,%ebx
movsbl 0x2(%r14),%edi
call   1030 <hwp_hex@plt>
mov    %eax,%r15d
shl    $0x14,%r15d
movsbl 0x3(%r14),%edi
call   1030 <hwp_hex@plt>
mov    %eax,%r12d
shl    $0x10,%r12d
or     %r15d,%r12d
or     %ebx,%r12d
movsbl 0x4(%r14),%edi
call   1030 <hwp_hex@plt>
mov    %eax,%r15d
shl    $0xc,%r15d
movsbl 0x5(%r14),%edi
call   1030 <hwp_hex@plt>
mov    %eax,%ebx
shl    $0x8,%ebx
or     %r15d,%ebx
movsbl 0x6(%r14),%edi
call   1030 <hwp_hex@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
or     %ebx,%ebp
or     %r12d,%ebp
movsbl 0x7(%r14),%edi
call   1030 <hwp_hex@plt>
or     %ebp,%eax
cltq
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @hwp_hex2reg(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i32 @hwp_hex(i8 signext %2)
%4 = shl i32 %3, 28
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = tail call i32 @hwp_hex(i8 signext %6)
%8 = shl i32 %7, 24
%9 = or i32 %4, %8
%10 = getelementptr inbounds i8, i8* %0, i64 2
%11 = load i8, i8* %10
%12 = tail call i32 @hwp_hex(i8 signext %11)
%13 = shl i32 %12, 20
%14 = or i32 %9, %13
%15 = getelementptr inbounds i8, i8* %0, i64 3
%16 = load i8, i8* %15
%17 = tail call i32 @hwp_hex(i8 signext %16)
%18 = shl i32 %17, 16
%19 = or i32 %14, %18
%20 = getelementptr inbounds i8, i8* %0, i64 4
%21 = load i8, i8* %20
%22 = tail call i32 @hwp_hex(i8 signext %21)
%23 = shl i32 %22, 12
%24 = or i32 %19, %23
%25 = getelementptr inbounds i8, i8* %0, i64 5
%26 = load i8, i8* %25
%27 = tail call i32 @hwp_hex(i8 signext %26)
%28 = shl i32 %27, 8
%29 = or i32 %24, %28
%30 = getelementptr inbounds i8, i8* %0, i64 6
%31 = load i8, i8* %30
%32 = tail call i32 @hwp_hex(i8 signext %31)
%33 = shl i32 %32, 4
%34 = or i32 %29, %33
%35 = getelementptr inbounds i8, i8* %0, i64 7
%36 = load i8, i8* %35
%37 = tail call i32 @hwp_hex(i8 signext %36)
%38 = or i32 %34, %37
%39 = sext i32 %38 to i64
ret i64 %39
}