#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 int hexc2bin(int /*<<< orphan*/);
scalar_t__ isxdigit(char);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
unsigned int a2hex(char *s) {
  unsigned int val = 0;
  if (!strncasecmp("0x", s, 2)) {
    s += 2;
  }
  while (*s && isxdigit(*s)) {
    val = (val << 4) + hexc2bin(*s++);
  }
  return val;
}


x86 assembly (clang, -O0):
<a2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb2(%rip),%rdi
mov    $0x2,%edx
call   1030 <strncasecmp@plt>
cmp    $0x0,%eax
jne    116d <a2hex+0x3d>
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    1172 <a2hex+0x42>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
je     119d <a2hex+0x6d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    11ad <a2hex+0x7d>
jmp    11dc <a2hex+0xac>
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1040 <hexc2bin@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    1172 <a2hex+0x42>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a2hex>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec2(%rip),%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <strncasecmp@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
mov    (%rbx,%rcx,2),%al
test   %al,%al
je     119a <a2hex+0x6a>
add    %rcx,%rcx
lea    (%rcx,%rbx,1),%r14
add    $0x1,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1050 <isxdigit@plt>
test   %rax,%rax
je     119c <a2hex+0x6c>
shl    $0x4,%ebx
movsbl -0x1(%r14),%edi
call   1040 <hexc2bin@plt>
add    %eax,%ebx
movzbl (%r14),%eax
add    $0x1,%r14
test   %al,%al
jne    1170 <a2hex+0x40>
jmp    119c <a2hex+0x6c>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
define i32 @a2hex(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%4 = load i8*, i8** %2
%5 = call i32 @strncasecmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4, i32 2)
%6 = icmp ne i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 2
store i8* %9, i8** %2
br label %10
10: ; preds = %7, %1
br label %11
11: ; preds = %23, %10
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = call i64 @isxdigit(i8 signext %18)
%20 = icmp ne i64 %19, 0
br label %21
21: ; preds = %16, %11
%22 = phi i1 [ false, %11 ], [ %20, %16 ]
br i1 %22, label %23, label %32
23: ; preds = %21
%24 = load i32, i32* %3
%25 = shl i32 %24, 4
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %2
%28 = load i8, i8* %26
%29 = sext i8 %28 to i32
%30 = call i32 @hexc2bin(i32 %29)
%31 = add i32 %25, %30
store i32 %31, i32* %3
br label %11
32: ; preds = %21
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
define i32 @a2hex(i8* nocapture %0) {
%2 = tail call i32 @strncasecmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0, i32 2)
%3 = icmp eq i32 %2, 0
%4 = select i1 %3, i64 2, i64 0
%5 = getelementptr i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %1, %14
%9 = phi i8 [ %21, %14 ], [ %6, %1 ]
%10 = phi i32 [ %20, %14 ], [ 0, %1 ]
%11 = phi i8* [ %16, %14 ], [ %5, %1 ]
%12 = tail call i64 @isxdigit(i8 signext %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %8
%15 = shl i32 %10, 4
%16 = getelementptr inbounds i8, i8* %11, i64 1
%17 = load i8, i8* %11
%18 = sext i8 %17 to i32
%19 = tail call i32 @hexc2bin(i32 %18)
%20 = add i32 %19, %15
%21 = load i8, i8* %16
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %8
23: ; preds = %8, %14, %1
%24 = phi i32 [ 0, %1 ], [ %20, %14 ], [ %10, %8 ]
ret i32 %24
}