#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ strstr(char *, char *);
int main() {
  FILE *in = fopen("spooky.csv", "r");
  FILE *file1 = fopen("ufos.csv", "w");
  FILE *file2 = fopen("elvis.csv", "w");
  FILE *file3 = fopen("other.csv", "w");
  char line[80];
  while (fscanf(in, "%79[^\n]\n", line) == 1) {
    if (strstr(line, "UFO")) {
      fprintf(file1, "%s\n", line);
    } else if (strstr(line, "Elvis")) {
      fprintf(file2, "%s\n", line);
    } else {
      fprintf(file3, "%s\n", line);
    }
  }
  fclose(file1);
  fclose(file2);
  fclose(file3);
  fclose(in);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe81(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe74(%rip),%rdi
lea    0xe61(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    125f <main+0x10f>
lea    -0x80(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     120e <main+0xbe>
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe35(%rip),%rsi
call   1050 <fprintf@plt>
jmp    125a <main+0x10a>
lea    -0x80(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1241 <main+0xf1>
mov    -0x20(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xe02(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1255 <main+0x105>
mov    -0x28(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xde9(%rip),%rsi
call   1050 <fprintf@plt>
jmp    125a <main+0x10a>
jmp    11be <main+0x6e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe9b(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe92(%rip),%rdi
lea    0xe94(%rip),%rbp
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe84(%rip),%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,(%rsp)
lea    0xe7b(%rip),%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,0x8(%rsp)
lea    0xe71(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1240 <main+0xf0>
lea    0xe61(%rip),%r13
lea    0x10(%rsp),%rbp
lea    0xe59(%rip),%r15
lea    0xe45(%rip),%r12
jmp    120e <main+0xbe>
nopl   0x0(%rax)
mov    %r15,%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1240 <main+0xf0>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1070 <strstr@plt>
mov    %rbx,%rdi
test   %rax,%rax
jne    11f0 <main+0xa0>
mov    %rbp,%rdi
lea    0xe12(%rip),%rsi
call   1070 <strstr@plt>
mov    0x8(%rsp),%rdi
test   %rax,%rax
je     11f0 <main+0xa0>
mov    (%rsp),%rdi
jmp    11f0 <main+0xa0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%rsp),%rdi
call   1030 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"spooky.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"ufos.csv\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [10 x i8] c"elvis.csv\00"
@.str.5 = [10 x i8] c"other.csv\00"
@.str.6 = [9 x i8] c"%79[^\0A]\0A\00"
@.str.7 = [4 x i8] c"UFO\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [6 x i8] c"Elvis\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [80 x i8]
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %8, i32** %3
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %9, i32** %4
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %10, i32** %5
br label %11
11: ; preds = %37, %0
%12 = load i32*, i32** %2
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%14 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %13)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %38
16: ; preds = %11
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%18 = call i64 @strstr(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32*, i32** %3
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%23 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %22)
br label %37
24: ; preds = %16
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%26 = call i64 @strstr(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i32*, i32** %4
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%31 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %30)
br label %36
32: ; preds = %24
%33 = load i32*, i32** %5
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%35 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %32, %28
br label %37
37: ; preds = %36, %20
br label %11
38: ; preds = %11
%39 = load i32*, i32** %3
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %4
%42 = call i32 @fclose(i32* %41)
%43 = load i32*, i32** %5
%44 = call i32 @fclose(i32* %43)
%45 = load i32*, i32** %2
%46 = call i32 @fclose(i32* %45)
ret i32 1
}

LLVM IR (-O2):
@.str = [11 x i8] c"spooky.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"ufos.csv\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [10 x i8] c"elvis.csv\00"
@.str.5 = [10 x i8] c"other.csv\00"
@.str.6 = [9 x i8] c"%79[^\0A]\0A\00"
@.str.7 = [4 x i8] c"UFO\00"
@.str.8 = [4 x i8] c"%s\0A\00"
@.str.9 = [6 x i8] c"Elvis\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%7 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %21
9: ; preds = %0, %16
%10 = call i64 @strstr(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = call i64 @strstr(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i32* %5, i32* %4
br label %16
16: ; preds = %12, %9
%17 = phi i32* [ %3, %9 ], [ %15, %12 ]
%18 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %6)
%19 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %6)
%20 = icmp eq i32 %19, 1
br i1 %20, label %9, label %21
21: ; preds = %16, %0
%22 = call i32 @fclose(i32* %3)
%23 = call i32 @fclose(i32* %4)
%24 = call i32 @fclose(i32* %5)
%25 = call i32 @fclose(i32* %2)
ret i32 1
}