#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char getc(int /*<<< orphan*/ *);
int strtol(char *, int /*<<< orphan*/ *, int);
int parseHex(FILE *fp, int numDigits) {
  int i;
  char temp[9];
  for (i = 0; i < numDigits; i++)
    temp[i] = getc(fp);
  temp[i] = 0;
  return strtol(temp, NULL, 16);
}


x86 assembly (clang, -O0):
<parseHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1163 <parseHex+0x43>
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %al,%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0x19(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <parseHex+0x16>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x19(%rbp,%rax,1)
lea    -0x19(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseHex>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    1157 <parseHex+0x37>
mov    %rdi,%r15
mov    %esi,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1040 <getc@plt>
mov    %al,0x7(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <parseHex+0x20>
jmp    115a <parseHex+0x3a>
xor    %r14d,%r14d
movb   $0x0,0x7(%rsp,%r14,1)
lea    0x7(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @parseHex(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [9 x i8]
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %17, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = load i32*, i32** %3
%13 = call signext i8 @getc(i32* %12)
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 %15
store i8 %13, i8* %16
br label %17
17: ; preds = %11
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %7
20: ; preds = %7
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 %22
store i8 0, i8* %23
%24 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%25 = call i32 @strtol(i8* %24, i32* null, i32 16)
ret i32 %25
}

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