#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 hex(unsigned char);
int hexToInt(unsigned char **ptr, long *intValue) {
  int numChars = 0;
  int hexValue;
  *intValue = 0;
  while (**ptr) {
    hexValue = hex(**ptr);
    if (hexValue >= 0) {
      *intValue = (*intValue << 4) | (unsigned)hexValue;
      numChars++;
    } else
      break;
    (*ptr)++;
  }
  return (numChars);
}


x86 assembly (clang, -O0):
<hexToInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmpb   $0x0,(%rax)
je     119c <hexToInt+0x8c>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movzbl (%rax),%edi
call   1030 <hex@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1184 <hexToInt+0x74>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
shl    $0x4,%rcx
mov    -0x18(%rbp),%eax
or     %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1189 <hexToInt+0x79>
jmp    119c <hexToInt+0x8c>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1132 <hexToInt+0x22>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexToInt>:
push   %rbp
push   %r14
push   %rbx
movq   $0x0,(%rsi)
mov    (%rdi),%rax
mov    (%rax),%al
test   %al,%al
je     1162 <hexToInt+0x52>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
movzbl %al,%edi
call   1030 <hex@plt>
test   %eax,%eax
js     1164 <hexToInt+0x54>
mov    (%r14),%rcx
shl    $0x4,%rcx
mov    %eax,%eax
or     %rcx,%rax
mov    %rax,(%r14)
add    $0x1,%ebp
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movzbl 0x1(%rax),%eax
test   %al,%al
jne    1130 <hexToInt+0x20>
jmp    1164 <hexToInt+0x54>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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