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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ add_test(char *, char const *, unsigned int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                         char const *);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
void read_input(const char *filename) {
  FILE *fp = fopen(filename, "r");
  if (fp == NULL)
    error(EXIT_FAILURE, errno, "open '%s'", filename);
  unsigned int lineno = 0;
  for (;;) {
    size_t size = 0;
    char *line = NULL;
    ssize_t ret = getline(&line, &size, fp);
    if (ret == -1)
      break;
    lineno++;
    if (line[0] == '#' || line[0] == '\n')
      continue;
    add_test(line, filename, lineno);
  }
  if (ferror(fp))
    error(EXIT_FAILURE, errno, "read from '%s'", filename);
  if (fclose(fp) != 0)
    error(EXIT_FAILURE, errno, "close '%s'", filename);
}


x86 assembly (clang, -O0):
<read_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ad <read_input+0x4d>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
lea    0xe5a(%rip),%rdx
call   1050 <error@plt>
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11e7 <read_input+0x87>
jmp    122a <read_input+0xca>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1210 <read_input+0xb0>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1215 <read_input+0xb5>
jmp    11b4 <read_input+0x54>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <add_test@plt>
jmp    11b4 <read_input+0x54>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     125f <read_input+0xff>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
lea    0xdb2(%rip),%rdx
call   1050 <error@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1294 <read_input+0x134>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
mov    0x2d5e(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
lea    0xd8c(%rip),%rdx
call   1050 <error@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_input>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xe8a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a4 <read_input+0x44>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    0xe66(%rip),%rdx
mov    %r14,%rcx
call   1050 <error@plt>
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1222 <read_input+0xc2>
mov    $0x1,%ebp
mov    %rsp,%r15
lea    0x8(%rsp),%r12
jmp    1207 <read_input+0xa7>
nopl   0x0(%rax)
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
add    $0x1,%ebp
cmp    $0xffffffff,%eax
je     1222 <read_input+0xc2>
mov    (%rsp),%rdi
movzbl (%rdi),%eax
cmp    $0xa,%al
je     11e0 <read_input+0x80>
cmp    $0x23,%al
je     11e0 <read_input+0x80>
mov    %r14,%rsi
mov    %ebp,%edx
call   1060 <add_test@plt>
jmp    11e0 <read_input+0x80>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1250 <read_input+0xf0>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
lea    0xdc4(%rip),%rdx
mov    %r14,%rcx
call   1050 <error@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     127e <read_input+0x11e>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
lea    0xda5(%rip),%rdx
mov    %r14,%rcx
call   1050 <error@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@errno = global i32 0
@.str.1 = [10 x i8] c"open '%s'\00"
@.str.2 = [15 x i8] c"read from '%s'\00"
@.str.3 = [11 x i8] c"close '%s'\00"
define void @read_input(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @EXIT_FAILURE
%8 = load i32, i32* @errno
%9 = tail call i32 @error(i32 %7, i32 %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %10
10: ; preds = %6, %1
%11 = bitcast i64* %2 to i8*
%12 = bitcast i8** %3 to i8*
store i64 0, i64* %2
store i8* null, i8** %3
%13 = call i32 @getline(i8** %3, i64* %2, i32* %4)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %25, %10
%16 = call i64 @ferror(i32* %4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %32, label %28
18: ; preds = %10, %25
%19 = phi i32 [ %20, %25 ], [ 0, %10 ]
%20 = add i32 %19, 1
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
switch i8 %22, label %23 [
i8 35, label %25
i8 10, label %25
]
23: ; preds = %18
%24 = call i32 @add_test(i8* %21, i8* %0, i32 %20)
br label %25
25: ; preds = %18, %18, %23
store i64 0, i64* %2
store i8* null, i8** %3
%26 = call i32 @getline(i8** %3, i64* %2, i32* %4)
%27 = icmp eq i32 %26, -1
br i1 %27, label %15, label %18
28: ; preds = %15
%29 = load i32, i32* @EXIT_FAILURE
%30 = load i32, i32* @errno
%31 = call i32 @error(i32 %29, i32 %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %32
32: ; preds = %28, %15
%33 = call i64 @fclose(i32* %4)
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %32
%36 = load i32, i32* @EXIT_FAILURE
%37 = load i32, i32* @errno
%38 = call i32 @error(i32 %36, i32 %37, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %39
39: ; preds = %35, %32
ret void
}