#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(char);
int hexToInt(char **ptr, int *intValue) {
  int numChars = 0;
  int hexValue;
  *intValue = 0;
  while (**ptr) {
    hexValue = hex(**ptr);
    if (hexValue >= 0) {
      *intValue = (*intValue << 4) | 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
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmpb   $0x0,(%rax)
je     1195 <hexToInt+0x85>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <hex@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     117d <hexToInt+0x6d>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
shl    $0x4,%ecx
or     -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <hexToInt+0x72>
jmp    1195 <hexToInt+0x85>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1131 <hexToInt+0x21>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexToInt>:
push   %rbp
push   %r14
push   %rbx
movl   $0x0,(%rsi)
mov    (%rdi),%rax
mov    (%rax),%al
test   %al,%al
je     115e <hexToInt+0x4e>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <hex@plt>
test   %eax,%eax
js     1160 <hexToInt+0x50>
mov    (%r14),%ecx
shl    $0x4,%ecx
or     %eax,%ecx
mov    %ecx,(%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    1160 <hexToInt+0x50>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hexToInt(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %3
store i32* %1, i32** %4
store i32 0, i32* %5
%7 = load i32*, i32** %4
store i32 0, i32* %7
br label %8
8: ; preds = %30, %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 %34
13: ; preds = %8
%14 = load i8**, i8*** %3
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = call i32 @hex(i8 signext %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %13
%21 = load i32*, i32** %4
%22 = load i32, i32* %21
%23 = shl i32 %22, 4
%24 = load i32, i32* %6
%25 = or i32 %23, %24
%26 = load i32*, i32** %4
store i32 %25, i32* %26
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %30
29: ; preds = %13
br label %34
30: ; preds = %20
%31 = load i8**, i8*** %3
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %31
br label %8
34: ; preds = %29, %8
%35 = load i32, i32* %5
ret i32 %35
}

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