#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 */
struct input {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
int parse_input_string(char *, struct input *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int read_input_file(const char *str, struct input *inp) {
  FILE *f;
  char *p;
  char s[1024];
  long i;
  f = fopen(str, "r");
  if (f == NULL) {
    return 1;
  }
  i = 0;
  while ((p = fgets(s, 1024, f))) {
    char *eol;
    char *com;
    int r;
    ++i;
    eol = strchr(p, '\n');
    if (eol == NULL) {
      continue;
    }
    *eol = 0;
    com = strchr(p, '#');
    if (com != NULL) {
      *com = 0;
    }
    com = strchr(p, ';');
    if (com != NULL) {
      *com = 0;
    }
    if (*p == 0) {
      continue;
    }
    r = parse_input_string(p, inp);
    if (r != 0) {
      fprintf(stderr, "error at line %ld\n", i);
      return 1;
    }
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<read_input_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119e <read_input_file+0x3e>
movl   $0x1,-0x4(%rbp)
jmp    12dc <read_input_file+0x17c>
movq   $0x0,-0x438(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12cc <read_input_file+0x16c>
mov    -0x438(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x438(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x440(%rbp)
cmpq   $0x0,-0x440(%rbp)
jne    1206 <read_input_file+0xa6>
jmp    11a9 <read_input_file+0x49>
mov    -0x440(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
je     123d <read_input_file+0xdd>
mov    -0x448(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
je     126a <read_input_file+0x10a>
mov    -0x448(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    127f <read_input_file+0x11f>
jmp    11a9 <read_input_file+0x49>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <parse_input_string@plt>
mov    %eax,-0x44c(%rbp)
cmpl   $0x0,-0x44c(%rbp)
je     12c7 <read_input_file+0x167>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
mov    -0x438(%rbp),%rdx
lea    0xd4c(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12dc <read_input_file+0x17c>
jmp    11a9 <read_input_file+0x49>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_input_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r15
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     1255 <read_input_file+0xf5>
mov    %rax,%r13
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     124a <read_input_file+0xea>
mov    %rax,%rbp
mov    $0x1,%ebx
mov    %rsp,%r12
jmp    11dc <read_input_file+0x7c>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
mov    %rax,%rbp
add    $0x1,%rbx
test   %rax,%rax
je     124a <read_input_file+0xea>
mov    %rbp,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c0 <read_input_file+0x60>
movb   $0x0,(%rax)
mov    %rbp,%rdi
mov    $0x23,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1206 <read_input_file+0xa6>
movb   $0x0,(%rax)
mov    %rbp,%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     121b <read_input_file+0xbb>
movb   $0x0,(%rax)
cmpb   $0x0,0x0(%rbp)
je     11c0 <read_input_file+0x60>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1080 <parse_input_string@plt>
test   %eax,%eax
je     11c0 <read_input_file+0x60>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
jmp    1255 <read_input_file+0xf5>
mov    %r13,%rdi
call   1030 <fclose@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.input = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"error at line %ld\0A\00"
define i32 @read_input_file(i8* nocapture %0, %struct.input* %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %38, label %7
7: ; preds = %2
%8 = call i8* @fgets(i8* %4, i32 1024, i32* %5)
%9 = icmp eq i8* %8, null
br i1 %9, label %36, label %10
10: ; preds = %7, %33
%11 = phi i8* [ %34, %33 ], [ %8, %7 ]
%12 = phi i64 [ %13, %33 ], [ 0, %7 ]
%13 = add nuw nsw i64 %12, 1
%14 = call i8* @strchr(i8* %11, i8 signext 10)
%15 = icmp eq i8* %14, null
br i1 %15, label %33, label %16
16: ; preds = %10
store i8 0, i8* %14
%17 = call i8* @strchr(i8* %11, i8 signext 35)
%18 = icmp eq i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %16
store i8 0, i8* %17
br label %20
20: ; preds = %19, %16
%21 = call i8* @strchr(i8* %11, i8 signext 59)
%22 = icmp eq i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %20
store i8 0, i8* %21
br label %24
24: ; preds = %23, %20
%25 = load i8, i8* %11
%26 = icmp eq i8 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %24
%28 = call i32 @parse_input_string(i8* %11, %struct.input* %1)
%29 = icmp eq i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i64 %13)
br label %38
33: ; preds = %27, %24, %10
%34 = call i8* @fgets(i8* %4, i32 1024, i32* %5)
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %10
36: ; preds = %33, %7
%37 = call i32 @fclose(i32* %5)
br label %38
38: ; preds = %30, %2, %36
%39 = phi i32 [ 0, %36 ], [ 1, %2 ], [ 1, %30 ]
ret i32 %39
}