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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
char *strstrip(char *);
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/ *, int);
int read_file(const char *filename, uint16_t vals[][2], int *n_vals) {
  FILE *fp;
  char _line[256];
  char _regstr[128], _valstr[128];
  if ((fp = fopen(filename, "r")) == NULL) {
    return 1;
  }
  int n = 0;
  while (fgets(_line, sizeof _line, fp) != NULL) {
    _line[strlen(_line) - 1] = '\0';
    char *__line = strstrip(_line);
    if ('#' == __line[0] || '\0' == __line[0]) {
      fprintf(stderr, "--- Ignore line : %s\n", __line);
    } else {
      sscanf(__line, "%4s %4s", _regstr, _valstr);
      vals[n][0] = strtoul(_regstr, NULL, 16);
      vals[n][1] = strtoul(_valstr, NULL, 16);
      n++;
    }
  }
  fclose(fp);
  *n_vals = n;
  return 0;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11c1 <read_file+0x41>
movl   $0x1,-0x4(%rbp)
jmp    12fe <read_file+0x17e>
movl   $0x0,-0x234(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12e2 <read_file+0x162>
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x130(%rbp,%rax,1)
lea    -0x130(%rbp),%rdi
call   1060 <strstrip@plt>
mov    %rax,-0x240(%rbp)
mov    -0x240(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x23,%eax
cmp    %ecx,%eax
je     1241 <read_file+0xc1>
mov    -0x240(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1262 <read_file+0xe2>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    -0x240(%rbp),%rdx
lea    0xdaa(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12dd <read_file+0x15d>
mov    -0x240(%rbp),%rdi
lea    -0x1b0(%rbp),%rdx
lea    -0x230(%rbp),%rcx
lea    0xd9a(%rip),%rsi
call   1080 <sscanf@plt>
lea    -0x1b0(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x234(%rbp),%rcx
mov    %edx,(%rax,%rcx,8)
lea    -0x230(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x234(%rbp),%rcx
mov    %edx,0x4(%rax,%rcx,8)
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
jmp    11cb <read_file+0x4b>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x234(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rdx,%rbp
mov    %rsi,%r15
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1299 <read_file+0x119>
mov    %rax,%rbx
mov    %rbp,0x8(%rsp)
lea    0x110(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    $0x0,%r13d
test   %rax,%rax
je     1285 <read_file+0x105>
xor    %r13d,%r13d
lea    0x90(%rsp),%r12
lea    0x10(%rsp),%r14
jmp    121d <read_file+0x9d>
nopl   (%rax)
mov    0x2de9(%rip),%rcx
mov    (%rcx),%edi
lea    0xe02(%rip),%rsi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1285 <read_file+0x105>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
mov    %rbp,%rdi
call   1060 <strstrip@plt>
movzbl (%rax),%ecx
cmp    $0x23,%cl
je     11f0 <read_file+0x70>
test   %cl,%cl
je     11f0 <read_file+0x70>
mov    %rax,%rdi
lea    0xdce(%rip),%rsi
mov    %r12,%rdx
mov    %r14,%rcx
call   1080 <sscanf@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
movslq %r13d,%r13
mov    %eax,(%r15,%r13,8)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,0x4(%r15,%r13,8)
add    $0x1,%r13d
jmp    1208 <read_file+0x88>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x8(%rsp),%rax
mov    %r13d,(%rax)
xor    %eax,%eax
jmp    129e <read_file+0x11e>
mov    $0x1,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"--- Ignore line : %s\0A\00"
@.str.2 = [8 x i8] c"%4s %4s\00"
define i32 @read_file(i8* %0, [2 x i32]* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [2 x i32]*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [256 x i8]
%10 = alloca [128 x i8]
%11 = alloca [128 x i8]
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %5
store [2 x i32]* %1, [2 x i32]** %6
store i32* %2, i32** %7
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %8
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %3
store i32 1, i32* %4
br label %74
18: ; preds = %3
store i32 0, i32* %12
br label %19
19: ; preds = %68, %18
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%21 = load i32*, i32** %8
%22 = call i32* @fgets(i8* %20, i32 256, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %69
24: ; preds = %19
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 %28
store i8 0, i8* %29
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%31 = call i8* @strstrip(i8* %30)
store i8* %31, i8** %13
%32 = load i8*, i8** %13
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 35, %35
br i1 %36, label %43, label %37
37: ; preds = %24
%38 = load i8*, i8** %13
%39 = getelementptr inbounds i8, i8* %38, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 0, %41
br i1 %42, label %43, label %47
43: ; preds = %37, %24
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %13
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %45)
br label %68
47: ; preds = %37
%48 = load i8*, i8** %13
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%50 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%51 = call i32 @sscanf(i8* %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %49, i8* %50)
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%53 = call i32 @strtoul(i8* %52, i32* null, i32 16)
%54 = load [2 x i32]*, [2 x i32]** %6
%55 = load i32, i32* %12
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %54, i64 %56
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %57, i64 0, i64 0
store i32 %53, i32* %58
%59 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%60 = call i32 @strtoul(i8* %59, i32* null, i32 16)
%61 = load [2 x i32]*, [2 x i32]** %6
%62 = load i32, i32* %12
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %61, i64 %63
%65 = getelementptr inbounds [2 x i32], [2 x i32]* %64, i64 0, i64 1
store i32 %60, i32* %65
%66 = load i32, i32* %12
%67 = add nsw i32 %66, 1
store i32 %67, i32* %12
br label %68
68: ; preds = %47, %43
br label %19
69: ; preds = %19
%70 = load i32*, i32** %8
%71 = call i32 @fclose(i32* %70)
%72 = load i32, i32* %12
%73 = load i32*, i32** %7
store i32 %72, i32* %73
store i32 0, i32* %4
br label %74
74: ; preds = %69, %17
%75 = load i32, i32* %4
ret i32 %75
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"--- Ignore line : %s\0A\00"
@.str.2 = [8 x i8] c"%4s %4s\00"
define i32 @read_file(i8* nocapture %0, [2 x i32]* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca [256 x i8]
%5 = alloca [128 x i8]
%6 = alloca [128 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %41, label %12
12: ; preds = %3
%13 = call i32* @fgets(i8* %7, i32 256, i32* %10)
%14 = icmp eq i32* %13, null
br i1 %14, label %38, label %15
15: ; preds = %12, %34
%16 = phi i32 [ %35, %34 ], [ 0, %12 ]
%17 = call i32 @strlen(i8* %7)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i8* @strstrip(i8* %7)
%22 = load i8, i8* %21
switch i8 %22, label %26 [
i8 35, label %23
i8 0, label %23
]
23: ; preds = %15, %15
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %34
26: ; preds = %15
%27 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %9)
%28 = call i32 @strtoul(i8* nocapture %8, i32* null, i32 16)
%29 = sext i32 %16 to i64
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 %29, i64 0
store i32 %28, i32* %30
%31 = call i32 @strtoul(i8* nocapture %9, i32* null, i32 16)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 %29, i64 1
store i32 %31, i32* %32
%33 = add nsw i32 %16, 1
br label %34
34: ; preds = %26, %23
%35 = phi i32 [ %16, %23 ], [ %33, %26 ]
%36 = call i32* @fgets(i8* %7, i32 256, i32* %10)
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %15
38: ; preds = %34, %12
%39 = phi i32 [ 0, %12 ], [ %35, %34 ]
%40 = call i32 @fclose(i32* %10)
store i32 %39, i32* %2
br label %41
41: ; preds = %3, %38
%42 = phi i32 [ 0, %38 ], [ 1, %3 ]
ret i32 %42
}