#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 */
char hex(char);
int hexToInt(char **ptr, unsigned int *intValue) {
  unsigned char numChars = 0;
  char hexValue;
  unsigned int tmp;
  *intValue = 0;
  while (**ptr) {
    hexValue = hex(**ptr);
    if (hexValue < 0)
      break;
    tmp = ((*intValue) << 4);
    *intValue = tmp | (hexValue & 0xF);
    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)
movb   $0x0,-0x11(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmpb   $0x0,(%rax)
je     119b <hexToInt+0x8b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <hex@plt>
mov    %al,-0x12(%rbp)
movsbl -0x12(%rbp),%eax
cmp    $0x0,%eax
jge    1162 <hexToInt+0x52>
jmp    119b <hexToInt+0x8b>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
shl    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
movsbl -0x12(%rbp),%eax
and    $0xf,%eax
or     %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x11(%rbp),%al
add    $0x1,%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    112e <hexToInt+0x1e>
movzbl -0x11(%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     1164 <hexToInt+0x54>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <hex@plt>
test   %al,%al
js     1166 <hexToInt+0x56>
mov    (%r14),%ecx
shl    $0x4,%ecx
and    $0xf,%al
movzbl %al,%eax
or     %ecx,%eax
mov    %eax,(%r14)
add    $0x1,%bpl
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movzbl 0x1(%rax),%eax
test   %al,%al
jne    1130 <hexToInt+0x20>
jmp    1166 <hexToInt+0x56>
xor    %ebp,%ebp
movzbl %bpl,%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 i8
%6 = alloca i8
%7 = alloca i32
store i8** %0, i8*** %3
store i32* %1, i32** %4
store i8 0, i8* %5
%8 = load i32*, i32** %4
store i32 0, i32* %8
br label %9
9: ; preds = %23, %2
%10 = load i8**, i8*** %3
%11 = load i8*, i8** %10
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %38
14: ; preds = %9
%15 = load i8**, i8*** %3
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
%18 = call signext i8 @hex(i8 signext %17)
store i8 %18, i8* %6
%19 = load i8, i8* %6
%20 = sext i8 %19 to i32
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %14
br label %38
23: ; preds = %14
%24 = load i32*, i32** %4
%25 = load i32, i32* %24
%26 = shl i32 %25, 4
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = load i8, i8* %6
%29 = sext i8 %28 to i32
%30 = and i32 %29, 15
%31 = or i32 %27, %30
%32 = load i32*, i32** %4
store i32 %31, i32* %32
%33 = load i8, i8* %5
%34 = add i8 %33, 1
store i8 %34, i8* %5
%35 = load i8**, i8*** %3
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %35
br label %9
38: ; preds = %22, %9
%39 = load i8, i8* %5
%40 = zext i8 %39 to i32
ret i32 %40
}

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 %22, label %6
6: ; preds = %2, %11
%7 = phi i8 [ %20, %11 ], [ %4, %2 ]
%8 = phi i8 [ %17, %11 ], [ 0, %2 ]
%9 = tail call signext i8 @hex(i8 signext %7)
%10 = icmp slt i8 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %6
%12 = load i32, i32* %1
%13 = shl i32 %12, 4
%14 = and i8 %9, 15
%15 = zext i8 %14 to i32
%16 = or i32 %13, %15
store i32 %16, i32* %1
%17 = add i8 %8, 1
%18 = load i8*, i8** %0
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8* %19, i8** %0
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %6
22: ; preds = %11, %6, %2
%23 = phi i8 [ 0, %2 ], [ %8, %6 ], [ %17, %11 ]
%24 = zext i8 %23 to i32
ret i32 %24
}