#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ check_get_hexval(char *, int, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
char *strtok_r(char *, char *, char **);
void pbl_parser(char *name) {
  FILE *f = NULL;
  char *line = NULL;
  char *token, *saveptr1, *saveptr2;
  size_t len = 0;
  int lineno = 0;
  f = fopen(name, "r");
  if (!f) {
    fprintf(stderr, "Error: Cannot open %s: %s\n", name, strerror(errno));
    exit(EXIT_FAILURE);
  }
  while ((getline(&line, &len, f)) > 0) {
    lineno++;
    token = strtok_r(line, "\r\n", &saveptr1);
    if (!token)
      continue;
    for (line = token;; line = NULL) {
      token = strtok_r(line, " \t", &saveptr2);
      if (!token)
        break;
      if (token[0] == '#')
        break;
      check_get_hexval(name, lineno, token);
    }
  }
  if (line)
    free(line);
  fclose(f);
}


x86 assembly (clang, -O0):
<pbl_parser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1220 <pbl_parser+0x90>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xdf5(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1225 <pbl_parser+0x95>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1090 <getline@plt>
cmp    $0x0,%rax
jle    12d8 <pbl_parser+0x148>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdc9(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1271 <pbl_parser+0xe1>
jmp    1225 <pbl_parser+0x95>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd9c(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12a1 <pbl_parser+0x111>
jmp    12d3 <pbl_parser+0x143>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    12b6 <pbl_parser+0x126>
jmp    12d3 <pbl_parser+0x143>
mov    -0x8(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <check_get_hexval@plt>
movq   $0x0,-0x18(%rbp)
jmp    1279 <pbl_parser+0xe9>
jmp    1225 <pbl_parser+0x95>
cmpq   $0x0,-0x18(%rbp)
je     12ec <pbl_parser+0x15c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pbl_parser>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r15
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe46(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1295 <pbl_parser+0x105>
mov    %rax,%r14
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
test   %rax,%rax
jle    126f <pbl_parser+0xdf>
xor    %ebx,%ebx
lea    0x10(%rsp),%r12
lea    0xe2c(%rip),%r13
lea    0x18(%rsp),%rbp
jmp    1215 <pbl_parser+0x85>
nopl   0x0(%rax,%rax,1)
lea    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1090 <getline@plt>
test   %rax,%rax
jle    126f <pbl_parser+0xdf>
add    $0x1,%ebx
mov    0x8(%rsp),%rdi
lea    0xdf9(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1060 <strtok_r@plt>
test   %rax,%rax
je     1200 <pbl_parser+0x70>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
nopl   0x0(%rax,%rax,1)
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <strtok_r@plt>
test   %rax,%rax
je     1200 <pbl_parser+0x70>
cmpb   $0x23,(%rax)
je     1200 <pbl_parser+0x70>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1040 <check_get_hexval@plt>
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
jmp    1240 <pbl_parser+0xb0>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     127e <pbl_parser+0xee>
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d44(%rip),%rax
mov    (%rax),%ebx
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd4f(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Error: Cannot open %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"\0D\0A\00"
@.str.3 = [3 x i8] c" \09\00"
define void @pbl_parser(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i8* %0, i8** %2
store i32* null, i32** %3
store i8* null, i8** %4
store i64 0, i64* %8
store i32 0, i32* %9
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp ne i32* %12, null
br i1 %13, label %22, label %14
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %2
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %1
br label %23
23: ; preds = %56, %34, %22
%24 = load i32*, i32** %3
%25 = call i64 @getline(i8** %4, i64* %8, i32* %24)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %57
27: ; preds = %23
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
%30 = load i8*, i8** %4
%31 = call i8* @strtok_r(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %6)
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = icmp ne i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %27
br label %23
35: ; preds = %27
%36 = load i8*, i8** %5
store i8* %36, i8** %4
br label %37
37: ; preds = %55, %35
%38 = load i8*, i8** %4
%39 = call i8* @strtok_r(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %7)
store i8* %39, i8** %5
%40 = load i8*, i8** %5
%41 = icmp ne i8* %40, null
br i1 %41, label %43, label %42
42: ; preds = %37
br label %56
43: ; preds = %37
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i64 0
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 35
br i1 %48, label %49, label %50
49: ; preds = %43
br label %56
50: ; preds = %43
%51 = load i8*, i8** %2
%52 = load i32, i32* %9
%53 = load i8*, i8** %5
%54 = call i32 @check_get_hexval(i8* %51, i32 %52, i8* %53)
br label %55
55: ; preds = %50
store i8* null, i8** %4
br label %37
56: ; preds = %49, %42
br label %23
57: ; preds = %23
%58 = load i8*, i8** %4
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i8*, i8** %4
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %60, %57
%64 = load i32*, i32** %3
%65 = call i32 @fclose(i32* %64)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"Error: Cannot open %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"\0D\0A\00"
@.str.3 = [3 x i8] c" \09\00"
define void @pbl_parser(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%7 = bitcast i8** %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%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 %15, label %12
12: ; preds = %1
%13 = call i64 @getline(i8** %2, i64* %5, i32* %10)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %22, label %42
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %12, %39
%23 = phi i32 [ %24, %39 ], [ 0, %12 ]
%24 = add nuw nsw i32 %23, 1
%25 = load i8*, i8** %2
%26 = call i8* @strtok_r(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %3)
%27 = icmp eq i8* %26, null
br i1 %27, label %39, label %28
28: ; preds = %22
store i8* %26, i8** %2
%29 = call i8* @strtok_r(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %4)
%30 = icmp eq i8* %29, null
br i1 %30, label %39, label %31
31: ; preds = %28, %35
%32 = phi i8* [ %37, %35 ], [ %29, %28 ]
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 35
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = call i32 @check_get_hexval(i8* %0, i32 %24, i8* %32)
store i8* null, i8** %2
%37 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %4)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %31
39: ; preds = %31, %35, %28, %22
%40 = call i64 @getline(i8** %2, i64* %5, i32* %10)
%41 = icmp sgt i64 %40, 0
br i1 %41, label %22, label %42
42: ; preds = %39, %12
%43 = load i8*, i8** %2
%44 = icmp eq i8* %43, null
br i1 %44, label %47, label %45
45: ; preds = %42
%46 = call i32 @free(i8* %43)
br label %47
47: ; preds = %45, %42
%48 = call i32 @fclose(i32* %10)
ret void
}