#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() {
  char line[80];
  FILE *in = fopen("spooky.csv", "r");
  FILE *file1 = fopen("ufos.csv", "w");
  FILE *file2 = fopen("disappearances.csv", "w");
  FILE *file3 = fopen("others.csv", "w");
  while (fscanf(in, "%79[^\n]\n", line) == 1) {
    if (strstr(line, "UFO"))
      fprintf(file1, "%s\n", line);
    else if (strstr(line, "Disappearance"))
      fprintf(file2, "%s\n", line);
    else
      fprintf(file3, "%s\n", line);
  }
  fclose(file1);
  fclose(file2);
  fclose(file3);
  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    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x70(%rbp)
lea    0xe81(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x78(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe61(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe69(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    125f <main+0x10f>
lea    -0x60(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     120e <main+0xbe>
mov    -0x70(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe3f(%rip),%rsi
call   1050 <fprintf@plt>
jmp    125a <main+0x10a>
lea    -0x60(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1241 <main+0xf1>
mov    -0x78(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe0c(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1255 <main+0x105>
mov    -0x80(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xdf3(%rip),%rsi
call   1050 <fprintf@plt>
jmp    125a <main+0x10a>
jmp    11be <main+0x6e>
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,%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    0xe84(%rip),%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,0x8(%rsp)
lea    0xe7b(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1240 <main+0xf0>
lea    0xe6b(%rip),%r13
lea    0x10(%rsp),%rbp
lea    0xe63(%rip),%r15
lea    0xe4f(%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    0xe1c(%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>
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 = [9 x i8] c"ufos.csv\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [19 x i8] c"disappearances.csv\00"
@.str.5 = [11 x i8] c"others.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 ([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** %4
%9 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 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 ([11 x i8], [11 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 = %37, %0
%12 = load i32*, i32** %3
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %2, 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]* %2, 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** %4
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %2, 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]* %2, i64 0, i64 0
%26 = call i64 @strstr(i8* %25, i8* getelementptr inbounds ([14 x i8], [14 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** %5
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %2, 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** %6
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %2, 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** %4
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %5
%42 = call i32 @fclose(i32* %41)
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
ret i32 0
}

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 = [19 x i8] c"disappearances.csv\00"
@.str.5 = [11 x i8] c"others.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 ([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))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 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 ([11 x i8], [11 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 @fscanf(i32* %3, 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 @fscanf(i32* %3, 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* %4)
%23 = call i32 @fclose(i32* %5)
%24 = call i32 @fclose(i32* %6)
ret i32 0
}