#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(int argc, char *args[]) {
  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)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x68(%rbp)
lea    0xe86(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x70(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x78(%rbp)
lea    0xe76(%rip),%rdi
lea    0xe5a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe62(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1266 <main+0x116>
lea    -0x60(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1215 <main+0xc5>
mov    -0x70(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe38(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1261 <main+0x111>
lea    -0x60(%rbp),%rdi
lea    0xe27(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1248 <main+0xf8>
mov    -0x78(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe05(%rip),%rsi
call   1050 <fprintf@plt>
jmp    125c <main+0x10c>
mov    -0x80(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xdec(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1261 <main+0x111>
jmp    11c5 <main+0x75>
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(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = 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* %11, i32** %7
%12 = 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* %12, i32** %8
%13 = 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* %13, i32** %9
%14 = 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* %14, i32** %10
br label %15
15: ; preds = %41, %2
%16 = load i32*, i32** %7
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%18 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %17)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %42
20: ; preds = %15
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%22 = call i64 @strstr(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32*, i32** %8
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%27 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %26)
br label %41
28: ; preds = %20
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%30 = call i64 @strstr(i8* %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i32*, i32** %9
%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 %40
36: ; preds = %28
%37 = load i32*, i32** %10
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%39 = call i32 @fprintf(i32* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %36, %32
br label %41
41: ; preds = %40, %24
br label %15
42: ; preds = %15
%43 = load i32*, i32** %8
%44 = call i32 @fclose(i32* %43)
%45 = load i32*, i32** %9
%46 = call i32 @fclose(i32* %45)
%47 = load i32*, i32** %10
%48 = call i32 @fclose(i32* %47)
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(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = 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))
%6 = 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))
%7 = 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))
%8 = 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))
%9 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %23
11: ; preds = %2, %18
%12 = call i64 @strstr(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = call i64 @strstr(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i32* %8, i32* %7
br label %18
18: ; preds = %14, %11
%19 = phi i32* [ %6, %11 ], [ %17, %14 ]
%20 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %4)
%21 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%22 = icmp eq i32 %21, 1
br i1 %22, label %11, label %23
23: ; preds = %18, %2
%24 = call i32 @fclose(i32* %6)
%25 = call i32 @fclose(i32* %7)
%26 = call i32 @fclose(i32* %8)
ret i32 0
}