#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 scanf(char *, char *);
scalar_t__ strstr(char *, char *);
int main() {
  char line[80];
  FILE *in = fopen("spooky.csv", "r");
  FILE *f_ufo = fopen("ufo.csv", "w");
  FILE *f_disap = fopen("disappearance.csv", "w");
  FILE *f_other = fopen("other.csv", "w");
  while (scanf("%79[^\n]\n", line) == 1) {
    if (strstr(line, "UFO")) {
      fprintf(f_ufo, "%s\n", line);
    } else if (strstr(line, "Disappearance")) {
      fprintf(f_disap, "%s\n", line);
    } else {
      fprintf(f_other, "%s\n", line);
    }
  }
  fclose(in);
  fclose(f_ufo);
  fclose(f_disap);
  fclose(f_other);
  return 0;
}


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,-0x68(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x70(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x78(%rbp)
lea    0xe7b(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x80(%rbp)
lea    -0x60(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    125b <main+0x10b>
lea    -0x60(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     120a <main+0xba>
mov    -0x70(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe40(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1256 <main+0x106>
lea    -0x60(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     123d <main+0xed>
mov    -0x78(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe0d(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1251 <main+0x101>
mov    -0x80(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xdf4(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1256 <main+0x106>
jmp    11be <main+0x6e>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x70(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x80(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%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,0x8(%rsp)
lea    0xe90(%rip),%rdi
lea    0xe91(%rip),%rbp
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe81(%rip),%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,(%rsp)
lea    0xe80(%rip),%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
lea    0xe78(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    123b <main+0xeb>
lea    0xe6b(%rip),%r13
lea    0x10(%rsp),%rbp
lea    0xe63(%rip),%r14
lea    0xe4f(%rip),%r15
jmp    120b <main+0xbb>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rsi
mov    %rbp,%rdx
call   1040 <fprintf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    123b <main+0xeb>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1070 <strstr@plt>
mov    %rbx,%rdi
test   %rax,%rax
jne    11f0 <main+0xa0>
mov    %rbp,%rdi
lea    0xe1c(%rip),%rsi
call   1070 <strstr@plt>
mov    %r12,%rdi
test   %rax,%rax
je     11f0 <main+0xa0>
mov    (%rsp),%rdi
jmp    11f0 <main+0xa0>
mov    0x8(%rsp),%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%rsp),%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%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 = [8 x i8] c"ufo.csv\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [18 x i8] c"disappearance.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 = [14 x i8] c"Disappearance\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
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** %3
%8 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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** %4
%9 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 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** %5
%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** %6
br label %11
11: ; preds = %36, %0
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %37
15: ; preds = %11
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%17 = call i64 @strstr(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32*, i32** %4
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%22 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %21)
br label %36
23: ; preds = %15
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%25 = call i64 @strstr(i8* %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32*, i32** %5
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%30 = call i32 @fprintf(i32* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %29)
br label %35
31: ; preds = %23
%32 = load i32*, i32** %6
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%34 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %31, %27
br label %36
36: ; preds = %35, %19
br label %11
37: ; preds = %11
%38 = load i32*, i32** %3
%39 = call i32 @fclose(i32* %38)
%40 = load i32*, i32** %4
%41 = call i32 @fclose(i32* %40)
%42 = load i32*, i32** %5
%43 = call i32 @fclose(i32* %42)
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"spooky.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"ufo.csv\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [18 x i8] c"disappearance.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 = [14 x i8] c"Disappearance\00"
define i32 @main() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, 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 ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%6 = 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))
%7 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %21
9: ; preds = %0, %16
%10 = call i64 @strstr(i8* %2, 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* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i32* %6, i32* %5
br label %16
16: ; preds = %12, %9
%17 = phi i32* [ %4, %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* %2)
%19 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%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* %6)
ret i32 0
}