#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
int main(int argc, char *argv[]) {
  char *outputFile;
  int aFlag = 0;
  int i;
  for (i = 0; i < argc; i++) {
    if (strcmp(argv[i], "-a") == 0) {
      aFlag = 1;
    } else {
      outputFile = argv[i];
    }
  }
  FILE *file;
  if (aFlag) {
    file = fopen(outputFile, "ab");
  } else {
    file = fopen(outputFile, "wb");
  }
  char in[80];
  int loop = 1;
  while (loop) {
    printf("Enter input (type quit to quit):\n");
    fgets(in, 80, stdin);
    if (strstr(in, "quit") != NULL) {
      fclose(file);
      loop = 0;
    } else {
      fprintf(file, "%s", in);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f4 <main+0x84>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe4a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <main+0x61>
movl   $0x1,-0x1c(%rbp)
jmp    11e1 <main+0x71>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
jmp    11e6 <main+0x76>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1197 <main+0x27>
cmpl   $0x0,-0x1c(%rbp)
je     1217 <main+0xa7>
mov    -0x18(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    122b <main+0xbb>
mov    -0x18(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
je     12b0 <main+0x140>
lea    0xdc0(%rip),%rdi
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2d8f(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1050 <fgets@plt>
lea    -0x80(%rbp),%rdi
lea    0xdbb(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     1297 <main+0x127>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x84(%rbp)
jmp    12ab <main+0x13b>
mov    -0x28(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xd8a(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1235 <main+0xc5>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r13
mov    %edi,%r12d
xor    %ebx,%ebx
lea    0xe73(%rip),%r15
xor    %ebp,%ebp
jmp    11ae <main+0x3e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,8),%r14
add    $0x1,%rbx
cmp    %rbx,%r12
je     11c7 <main+0x57>
mov    0x0(%r13,%rbx,8),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11a0 <main+0x30>
mov    $0x1,%ebp
jmp    11a5 <main+0x35>
test   %ebp,%ebp
lea    0xe36(%rip),%rax
lea    0xe2c(%rip),%rsi
cmove  %rax,%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
mov    0x2def(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1060 <fgets@plt>
lea    0xdf5(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
jne    1274 <main+0x104>
mov    %rsp,%rbx
lea    0xde3(%rip),%r15
lea    0xdd7(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x50,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     1240 <main+0xd0>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-a\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [34 x i8] c"Enter input (type quit to quit):\0A\00"
@stdin = global i32 0
@.str.4 = [5 x i8] c"quit\00"
@.str.5 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca [80 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
br label %12
12: ; preds = %32, %2
%13 = load i32, i32* %8
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %35
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = load i32, i32* %8
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %16
store i32 1, i32* %7
br label %31
25: ; preds = %16
%26 = load i8**, i8*** %5
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
store i8* %30, i8** %6
br label %31
31: ; preds = %25, %24
br label %32
32: ; preds = %31
%33 = load i32, i32* %8
%34 = add nsw i32 %33, 1
store i32 %34, i32* %8
br label %12
35: ; preds = %12
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i8*, i8** %6
%40 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %40, i32** %9
br label %44
41: ; preds = %35
%42 = load i8*, i8** %6
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %43, i32** %9
br label %44
44: ; preds = %41, %38
store i32 1, i32* %11
br label %45
45: ; preds = %63, %44
%46 = load i32, i32* %11
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %64
48: ; preds = %45
%49 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%50 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%51 = load i32, i32* @stdin
%52 = call i32 @fgets(i8* %50, i32 80, i32 %51)
%53 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%54 = call i32* @strstr(i8* %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%55 = icmp ne i32* %54, null
br i1 %55, label %56, label %59
56: ; preds = %48
%57 = load i32*, i32** %9
%58 = call i32 @fclose(i32* %57)
store i32 0, i32* %11
br label %63
59: ; preds = %48
%60 = load i32*, i32** %9
%61 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%62 = call i32 @fprintf(i32* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %59, %56
br label %45
64: ; preds = %45
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [3 x i8] c"-a\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.2 = [3 x i8] c"wb\00"
@stdin = global i32 0
@.str.4 = [5 x i8] c"quit\00"
@str = [33 x i8] c"Enter input (type quit to quit):\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = icmp sgt i32 %0, 0
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %2, %16
%7 = phi i64 [ 0, %2 ], [ %19, %16 ]
%8 = phi i32 [ 0, %2 ], [ %18, %16 ]
%9 = phi i8* [ undef, %2 ], [ %17, %16 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %7
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %6
%15 = load i8*, i8** %10
br label %16
16: ; preds = %6, %14
%17 = phi i8* [ %15, %14 ], [ %9, %6 ]
%18 = phi i32 [ %8, %14 ], [ 1, %6 ]
%19 = add nuw nsw i64 %7, 1
%20 = icmp eq i64 %19, %5
br i1 %20, label %21, label %6
21: ; preds = %16
%22 = icmp eq i32 %18, 0
%23 = select i1 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%24 = tail call i32* @fopen(i8* %17, i8* %23)
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%27 = load i32, i32* @stdin
%28 = call i32 @fgets(i8* %25, i32 80, i32 %27)
%29 = call i32* @strstr(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %38
31: ; preds = %21, %31
%32 = call i32 @fputs(i8* %25, i32* %24)
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%34 = load i32, i32* @stdin
%35 = call i32 @fgets(i8* %25, i32 80, i32 %34)
%36 = call i32* @strstr(i8* %25, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %31, label %38
38: ; preds = %31, %21
%39 = call i32 @fclose(i32* %24)
ret i32 0
}