#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
char getopt(int, char **, char *);
int /*<<< orphan*/ printf(char *, char *);
int scanf(char *, char *);
int main(int argc, char *argv[]) {
  int i;
  char ch;
  char *write_type;
  char word[80] = "";
  FILE *filename;
  while ((ch = getopt(argc, argv, "a:w:")) != EOF) {
    switch (ch) {
    case 'a': {
      write_type = "a";
      break;
    }
    case 'w': {
      write_type = "w";
      break;
    }
    default: {
      write_type = "w";
      break;
    }
    }
  }
  while (scanf("%[^\n]%*c", word) == 1) {
    filename = fopen(argv[2], write_type);
    fprintf(filename, "%s\n", word);
    printf("%s\n", word);
    fclose(filename);
  }
  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    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe59(%rip),%rdx
call   1090 <getopt@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%eax
mov    0x2e2f(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     121a <main+0xaa>
movsbl -0x15(%rbp),%eax
mov    %eax,-0x7c(%rbp)
sub    $0x61,%eax
je     11ea <main+0x7a>
jmp    11d9 <main+0x69>
mov    -0x7c(%rbp),%eax
sub    $0x77,%eax
je     11fa <main+0x8a>
jmp    120a <main+0x9a>
lea    0xe14(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1215 <main+0xa5>
lea    0xe06(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1215 <main+0xa5>
lea    0xdf6(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1199 <main+0x29>
jmp    121f <main+0xaf>
lea    -0x70(%rbp),%rsi
lea    0xddf(%rip),%rdi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    127f <main+0x10f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    0xdb6(%rip),%rsi
call   1060 <fprintf@plt>
lea    -0x70(%rbp),%rsi
lea    0xda6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x78(%rbp),%rdi
call   1030 <fclose@plt>
jmp    121f <main+0xaf>
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    $0x58,%rsp
mov    %rsi,%r13
mov    %edi,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe6b(%rip),%rdx
call   1080 <getopt@plt>
mov    0x2e47(%rip),%r15
cmp    (%r15),%al
je     11d9 <main+0x79>
lea    0xe53(%rip),%r14
nopl   (%rax)
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r14,%rdx
call   1080 <getopt@plt>
cmp    (%r15),%al
jne    11b0 <main+0x50>
cmp    $0x61,%bl
lea    0xe37(%rip),%rax
lea    0xe32(%rip),%r14
cmove  %rax,%r14
lea    0xe29(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1240 <main+0xe0>
lea    0xe1e(%rip),%r15
mov    %rsp,%rbp
lea    0xe0b(%rip),%r12
xchg   %ax,%ax
mov    0x10(%r13),%rdi
mov    %r14,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1050 <fprintf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     1200 <main+0xa0>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"a:w:\00"
@EOF = global i8 0
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [9 x i8] c"%[^\0A]%*c\00"
@.str.4 = [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 i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca [80 x i8]
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [80 x i8]* %9 to i8*
br label %12
12: ; preds = %26, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call signext i8 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8 %15, i8* %7
%16 = sext i8 %15 to i32
%17 = load i8, i8* @EOF
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %27
20: ; preds = %12
%21 = load i8, i8* %7
%22 = sext i8 %21 to i32
switch i32 %22, label %25 [
i32 97, label %23
i32 119, label %24
]
23: ; preds = %20
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %26
24: ; preds = %20
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %26
25: ; preds = %20
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %26
26: ; preds = %25, %24, %23
br label %12
27: ; preds = %12
br label %28
28: ; preds = %32, %27
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%30 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %45
32: ; preds = %28
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = load i8*, i8** %8
%37 = call i32* @fopen(i8* %35, i8* %36)
store i32* %37, i32** %10
%38 = load i32*, i32** %10
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%40 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%42 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = load i32*, i32** %10
%44 = call i32 @fclose(i32* %43)
br label %28
45: ; preds = %28
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"a:w:\00"
@EOF = global i8 0
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [9 x i8] c"%[^\0A]%*c\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
br i1 %7, label %11, label %17
8: ; preds = %17
%9 = icmp eq i8 %18, 97
%10 = select i1 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
br label %11
11: ; preds = %8, %2
%12 = phi i8* [ %10, %8 ], [ undef, %2 ]
%13 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = getelementptr inbounds i8*, i8** %1, i64 2
br label %22
17: ; preds = %2, %17
%18 = phi i8 [ %19, %17 ], [ %5, %2 ]
%19 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = load i8, i8* @EOF
%21 = icmp eq i8 %19, %20
br i1 %21, label %8, label %17
22: ; preds = %15, %22
%23 = load i8*, i8** %16
%24 = call i32* @fopen(i8* %23, i8* %12)
%25 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%27 = call i32 @fclose(i32* %24)
%28 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%29 = icmp eq i32 %28, 1
br i1 %29, label %22, label %30
30: ; preds = %22, %11
ret i32 0
}