#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
unsigned int hexToInt(char const);
int strHexToInt(const char *str, size_t strLen, unsigned *iOut) {
  assert(str != NULL);
  assert(iOut != NULL);
  unsigned iTmp;
  for (int i = 0; i < strLen; ++i) {
    *iOut <<= 4;
    if ((iTmp = hexToInt(str[i])) < 0) {
      return -1;
    }
    *iOut |= iTmp;
  }
  return strLen;
}


x86 assembly (clang, -O0):
<strHexToInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movl   $0x0,-0x28(%rbp)
movslq -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ba <strHexToInt+0x9a>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
shl    $0x4,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <hexToInt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jae    11a1 <strHexToInt+0x81>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <strHexToInt+0xa1>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115f <strHexToInt+0x3f>
mov    -0x18(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strHexToInt>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r12,%r12
setne  %dil
call   1030 <assert@plt>
test   %r14,%r14
je     1182 <strHexToInt+0x62>
mov    (%r12),%eax
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
shl    $0x4,%eax
mov    %eax,(%r12)
movsbl (%r15,%rbx,1),%edi
call   1040 <hexToInt@plt>
or     (%r12),%eax
mov    %eax,(%r12)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1160 <strHexToInt+0x40>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @strHexToInt(i8* %0, i64 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32*, i32** %7
%15 = icmp ne i32* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
store i32 0, i32* %9
br label %18
18: ; preds = %40, %3
%19 = load i32, i32* %9
%20 = sext i32 %19 to i64
%21 = load i64, i64* %6
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %43
23: ; preds = %18
%24 = load i32*, i32** %7
%25 = load i32, i32* %24
%26 = shl i32 %25, 4
store i32 %26, i32* %24
%27 = load i8*, i8** %5
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @hexToInt(i8 signext %31)
store i32 %32, i32* %8
%33 = icmp ult i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %23
store i32 -1, i32* %4
br label %46
35: ; preds = %23
%36 = load i32, i32* %8
%37 = load i32*, i32** %7
%38 = load i32, i32* %37
%39 = or i32 %38, %36
store i32 %39, i32* %37
br label %40
40: ; preds = %35
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %18
43: ; preds = %18
%44 = load i64, i64* %6
%45 = trunc i64 %44 to i32
store i32 %45, i32* %4
br label %46
46: ; preds = %43, %34
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
define i32 @strHexToInt(i8* %0, i64 %1, i32* %2) {
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp ne i32* %2, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp eq i64 %1, 0
br i1 %10, label %24, label %11
11: ; preds = %3
%12 = load i32, i32* %2
br label %13
13: ; preds = %11, %13
%14 = phi i32 [ %12, %11 ], [ %21, %13 ]
%15 = phi i64 [ 0, %11 ], [ %22, %13 ]
%16 = shl i32 %14, 4
store i32 %16, i32* %2
%17 = getelementptr inbounds i8, i8* %0, i64 %15
%18 = load i8, i8* %17
%19 = tail call i32 @hexToInt(i8 signext %18)
%20 = load i32, i32* %2
%21 = or i32 %20, %19
store i32 %21, i32* %2
%22 = add nuw i64 %15, 1
%23 = icmp eq i64 %22, %1
br i1 %23, label %24, label %13
24: ; preds = %13, %3
%25 = trunc i64 %1 to i32
ret i32 %25
}