#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 *, ...);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strstr(char *, char *);
int main(int argc, char *argv[]) {
  char line[80];
  if (argc != 6) {
    fprintf(stderr, "You need to give 5 arguments.\n");
    return 1;
  }
  FILE *in;
  if (!(in = fopen("spooky.csv", "r"))) {
    fprintf(stderr, "Cannot open the file.\n");
    return 1;
  }
  FILE *file1 = fopen(argv[2], "w");
  FILE *file2 = fopen(argv[4], "w");
  FILE *file3 = fopen(argv[5], "w");
  while (fscanf(in, "%79[^\n]\n", line) == 1) {
    if (strstr(line, argv[1]))
      fprintf(file1, "%s\n", line);
    else if (strstr(line, argv[3]))
      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)
cmpl   $0x6,-0x8(%rbp)
je     1197 <main+0x47>
mov    0x2e66(%rip),%rax
movslq (%rax),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ef <main+0x19f>
lea    0xe81(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
jne    11dc <main+0x8c>
mov    0x2e21(%rip),%rax
movslq (%rax),%rdi
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ef <main+0x19f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe58(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xe40(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
lea    0xe28(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe12(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    12cd <main+0x17d>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1277 <main+0x127>
mov    -0x70(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12c8 <main+0x178>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     12ad <main+0x15d>
mov    -0x78(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12c3 <main+0x173>
mov    -0x80(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12c8 <main+0x178>
jmp    1224 <main+0xd4>
mov    -0x70(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x80(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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
cmp    $0x6,%edi
jne    1260 <main+0x100>
mov    %rsi,%rbx
lea    0xe9e(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1297 <main+0x137>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe9f(%rip),%rbp
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    0x20(%rbx),%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,(%rsp)
mov    0x28(%rbx),%rdi
mov    %rbp,%rsi
call   1060 <fopen@plt>
mov    %rax,0x8(%rsp)
lea    0xe6e(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1278 <main+0x118>
lea    0x10(%rsp),%rbp
lea    0xe55(%rip),%r12
lea    0xe45(%rip),%r13
jmp    1230 <main+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1278 <main+0x118>
mov    0x8(%rbx),%rsi
mov    %rbp,%rdi
call   1080 <strstr@plt>
mov    %r15,%rdi
test   %rax,%rax
jne    1210 <main+0xb0>
mov    0x18(%rbx),%rsi
mov    %rbp,%rdi
call   1080 <strstr@plt>
mov    0x8(%rsp),%rdi
test   %rax,%rax
je     1210 <main+0xb0>
mov    (%rsp),%rdi
jmp    1210 <main+0xb0>
mov    0x2d79(%rip),%rax
movslq (%rax),%rcx
lea    0xd8f(%rip),%rdi
mov    $0x1e,%esi
jmp    12ad <main+0x14d>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    (%rsp),%rdi
call   1030 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    12bc <main+0x15c>
mov    0x2d42(%rip),%rax
movslq (%rax),%rcx
lea    0xd84(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"You need to give 5 arguments.\0A\00"
@.str.1 = [11 x i8] c"spooky.csv\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"Cannot open the file.\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [9 x i8] c"%79[^\0A]\0A\00"
@.str.6 = [4 x i8] c"%s\0A\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 = load i32, i32* %4
%12 = icmp ne i32 %11, 6
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %79
18: ; preds = %2
%19 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %7
%20 = icmp ne i32* %19, null
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i32*
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %79
26: ; preds = %18
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %30, i32** %8
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 4
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %34, i32** %9
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 5
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %38, i32** %10
br label %39
39: ; preds = %71, %26
%40 = load i32*, i32** %7
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%42 = call i32 @fscanf(i32* %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %72
44: ; preds = %39
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i64 @strstr(i8* %45, i8* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %44
%52 = load i32*, i32** %8
%53 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %53)
br label %71
55: ; preds = %44
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 3
%59 = load i8*, i8** %58
%60 = call i64 @strstr(i8* %56, i8* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %55
%63 = load i32*, i32** %9
%64 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %63, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %64)
br label %70
66: ; preds = %55
%67 = load i32*, i32** %10
%68 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%69 = call i32 (i32*, i8*, ...) @fprintf(i32* %67, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %66, %62
br label %71
71: ; preds = %70, %51
br label %39
72: ; preds = %39
%73 = load i32*, i32** %8
%74 = call i32 @fclose(i32* %73)
%75 = load i32*, i32** %9
%76 = call i32 @fclose(i32* %75)
%77 = load i32*, i32** %10
%78 = call i32 @fclose(i32* %77)
store i32 0, i32* %3
br label %79
79: ; preds = %72, %21, %13
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"You need to give 5 arguments.\0A\00"
@.str.1 = [11 x i8] c"spooky.csv\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"Cannot open the file.\0A\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [9 x i8] c"%79[^\0A]\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 6
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = sext i32 %7 to i64
%9 = inttoptr i64 %8 to i32*
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i64 30, i64 1, i32* %9)
br label %52
11: ; preds = %2
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i64 22, i64 1, i32* %17)
br label %52
19: ; preds = %11
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = getelementptr inbounds i8*, i8** %1, i64 4
%24 = load i8*, i8** %23
%25 = tail call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = getelementptr inbounds i8*, i8** %1, i64 5
%27 = load i8*, i8** %26
%28 = tail call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %48
31: ; preds = %19
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = getelementptr inbounds i8*, i8** %1, i64 3
br label %34
34: ; preds = %31, %43
%35 = load i8*, i8** %32
%36 = call i64 @strstr(i8* %4, i8* %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i8*, i8** %33
%40 = call i64 @strstr(i8* %4, i8* %39)
%41 = icmp eq i64 %40, 0
%42 = select i1 %41, i32* %28, i32* %25
br label %43
43: ; preds = %38, %34
%44 = phi i32* [ %22, %34 ], [ %42, %38 ]
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%46 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%47 = icmp eq i32 %46, 1
br i1 %47, label %34, label %48
48: ; preds = %43, %19
%49 = call i32 @fclose(i32* %22)
%50 = call i32 @fclose(i32* %25)
%51 = call i32 @fclose(i32* %28)
br label %52
52: ; preds = %14, %48, %6
%53 = phi i32 [ 1, %6 ], [ 0, %48 ], [ 1, %14 ]
ret i32 %53
}