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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ run_search_test(char *, int);
int test_file(char *filename) {
  FILE *fp;
  if ((fp = fopen(filename, "r")) == NULL) {
    printf("File read error: %s\n", filename);
    return 0;
  }
  char line[512];
  while (fgets(line, sizeof(line), fp)) {
    if (!run_search_test(line, 15)) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<test_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1189 <test_file+0x49>
mov    -0x10(%rbp),%rsi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11df <test_file+0x9f>
jmp    118e <test_file+0x4e>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11d8 <test_file+0x98>
lea    -0x220(%rbp),%rdi
mov    $0xf,%esi
call   1060 <run_search_test@plt>
cmp    $0x0,%eax
jne    11d3 <test_file+0x93>
movl   $0x0,-0x4(%rbp)
jmp    11df <test_file+0x9f>
jmp    118e <test_file+0x4e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_file>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r14
lea    0xeac(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1198 <test_file+0x58>
mov    %rax,%rbx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11ab <test_file+0x6b>
mov    %r14,%rdi
mov    $0xf,%esi
call   1060 <run_search_test@plt>
test   %eax,%eax
jne    1170 <test_file+0x30>
jmp    11a7 <test_file+0x67>
lea    0xe63(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11b0 <test_file+0x70>
mov    $0x1,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"File read error: %s\0A\00"
define i32 @test_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [512 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %10)
store i32 0, i32* %2
br label %25
12: ; preds = %1
br label %13
13: ; preds = %23, %12
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i64 @fgets(i8* %14, i32 512, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%20 = call i32 @run_search_test(i8* %19, i32 15)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %18
store i32 0, i32* %2
br label %25
23: ; preds = %18
br label %13
24: ; preds = %13
store i32 1, i32* %2
br label %25
25: ; preds = %24, %22, %9
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [21 x i8] c"File read error: %s\0A\00"
define i32 @test_file(i8* %0) {
%2 = alloca [512 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %17
7: ; preds = %1
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
br label %9
9: ; preds = %12, %7
%10 = call i64 @fgets(i8* %8, i32 512, i32* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = call i32 @run_search_test(i8* %8, i32 15)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %9
15: ; preds = %9, %12
%16 = phi i32 [ 0, %12 ], [ 1, %9 ]
br label %17
17: ; preds = %15, %5
%18 = phi i32 [ 0, %5 ], [ %16, %15 ]
ret i32 %18
}