#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)
      break;
    *intValue = (*intValue << 4) | hexValue;
    numChars++;
    (*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     1190 <hexToInt+0x80>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <hex@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1162 <hexToInt+0x52>
jmp    1190 <hexToInt+0x80>
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)
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 = %21, %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 %33
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 slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %13
br label %33
21: ; preds = %13
%22 = load i32*, i32** %4
%23 = load i32, i32* %22
%24 = shl i32 %23, 4
%25 = load i32, i32* %6
%26 = or i32 %24, %25
%27 = load i32*, i32** %4
store i32 %26, i32* %27
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
%30 = load i8**, i8*** %3
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %30
br label %8
33: ; preds = %20, %8
%34 = load i32, i32* %5
ret i32 %34
}

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 slt i32 %9, 0
br i1 %10, label %20, label %11
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
}