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

/* Variables and functions */
int fscanf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *);
size_t read_hex_array(FILE *file, uint8_t *buf, const size_t count) {
  size_t ii = 0;
  for (ii = 0; ii < count; ++ii)
    if (fscanf(file, "%2hhX", buf + ii) != 1)
      break;
  return ii;
}


x86 assembly (clang, -O0):
<read_hex_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1185 <read_hex_array+0x75>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xea4(%rip),%rsi
call   1030 <fscanf@plt>
cmp    $0x1,%eax
je     116f <read_hex_array+0x5f>
jmp    1185 <read_hex_array+0x75>
jmp    1174 <read_hex_array+0x64>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1134 <read_hex_array+0x24>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_hex_array>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdx,%rdx
je     1165 <read_hex_array+0x55>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
xor    %r15d,%r15d
lea    0xecf(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1030 <fscanf@plt>
cmp    $0x1,%eax
jne    1168 <read_hex_array+0x58>
add    $0x1,%r15
add    $0x4,%rbx
cmp    %r15,%r14
jne    1140 <read_hex_array+0x30>
mov    %r14,%r15
jmp    1168 <read_hex_array+0x58>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%2hhX\00"
define i64 @read_hex_array(i32* %0, i32* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
store i32* %0, i32** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
store i64 0, i64* %7
store i64 0, i64* %7
br label %8
8: ; preds = %21, %3
%9 = load i64, i64* %7
%10 = load i64, i64* %6
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %24
12: ; preds = %8
%13 = load i32*, i32** %4
%14 = load i32*, i32** %5
%15 = load i64, i64* %7
%16 = getelementptr inbounds i32, i32* %14, i64 %15
%17 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %16)
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %12
br label %24
20: ; preds = %12
br label %21
21: ; preds = %20
%22 = load i64, i64* %7
%23 = add i64 %22, 1
store i64 %23, i64* %7
br label %8
24: ; preds = %19, %8
%25 = load i64, i64* %7
ret i64 %25
}

LLVM IR (-O2):
@.str = [6 x i8] c"%2hhX\00"
define i64 @read_hex_array(i32* nocapture %0, i32* %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %13, label %5
5: ; preds = %3, %10
%6 = phi i64 [ %11, %10 ], [ 0, %3 ]
%7 = getelementptr inbounds i32, i32* %1, i64 %6
%8 = tail call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %7)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = add nuw i64 %6, 1
%12 = icmp eq i64 %11, %2
br i1 %12, label %13, label %5
13: ; preds = %10, %5, %3
%14 = phi i64 [ 0, %3 ], [ %6, %5 ], [ %2, %10 ]
ret i64 %14
}