#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 *);
char *optarg;
scalar_t__ optind;
int /*<<< orphan*/ printf(char *, char *);
int scanf(char *, char *);
int /*<<< orphan*/ *stderr;
int main(int argc, char **argv) {
  char line[80];
  char ch;
  char opt = 'w';
  int count;
  while ((ch = getopt(argc, argv, "a:")) != EOF) {
    switch (ch) {
    case 'a':
      opt = ch;
      optind--;
      break;
    default:
      fprintf(stderr, "Unkown option: %s\n", optarg);
      return 1;
    }
  }
  argc -= optind;
  argv += optind;
  FILE *files[argc];
  while (scanf("%79[^\n]\n", line) == 1) {
    printf("%s\n", line);
    for (count = 0; count < argc; count++) {
      if (opt == 'a') {
        files[count] = fopen(argv[count], "a");
      } else {
        files[count] = fopen(argv[count], "w");
      }
      fprintf(files[count], "%s\n", line);
      fclose(files[count]);
    }
  }
  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)
movb   $0x77,-0x62(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe75(%rip),%rdx
call   1080 <getopt@plt>
mov    %al,-0x61(%rbp)
movsbl %al,%eax
mov    0x2e43(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     120c <main+0xac>
mov    -0x61(%rbp),%al
sub    $0x61,%al
jne    11db <main+0x7b>
jmp    11b8 <main+0x58>
mov    -0x61(%rbp),%al
mov    %al,-0x62(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    0x2e05(%rip),%rax
mov    %rcx,(%rax)
jmp    1207 <main+0xa7>
mov    0x2de6(%rip),%rax
mov    (%rax),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%rdx
lea    0xe0d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    133d <main+0x1dd>
jmp    117d <main+0x1d>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%ecx
sub    %edx,%ecx
mov    %ecx,-0x8(%rbp)
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
lea    (%rax,%rcx,8),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x70(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x78(%rbp)
lea    -0x60(%rbp),%rsi
lea    0xdb8(%rip),%rdi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    132f <main+0x1cf>
lea    -0x60(%rbp),%rsi
lea    0xd9b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    132a <main+0x1ca>
movsbl -0x62(%rbp),%eax
cmp    $0x61,%eax
jne    12c8 <main+0x168>
mov    -0x10(%rbp),%rax
movslq -0x68(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd70(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rdx
mov    -0x80(%rbp),%rax
movslq -0x68(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    12ef <main+0x18f>
mov    -0x10(%rbp),%rax
movslq -0x68(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd46(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rdx
mov    -0x80(%rbp),%rax
movslq -0x68(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x80(%rbp),%rax
movslq -0x68(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x60(%rbp),%rdx
lea    0xd0c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x80(%rbp),%rax
movslq -0x68(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <fclose@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1283 <main+0x123>
jmp    1253 <main+0xf3>
movl   $0x0,-0x4(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe86(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,%r13d
mov    0x2e57(%rip),%r15
mov    (%r15),%al
mov    %al,0x8(%rsp)
cmp    %al,%r13b
je     11cf <main+0x6f>
mov    0x2e3c(%rip),%r12
lea    0xe5d(%rip),%rbx
mov    %r13d,%eax
cs nopw 0x0(%rax,%rax,1)
cmp    $0x61,%al
jne    12bd <main+0x15d>
addq   $0xffffffffffffffff,(%r12)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1080 <getopt@plt>
cmp    (%r15),%al
jne    11b0 <main+0x50>
mov    %rbp,0x10(%rsp)
mov    %rsp,0x18(%rsp)
mov    0x2df8(%rip),%rax
mov    (%rax),%rbp
lea    0xe2c(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    12b4 <main+0x154>
mov    0x10(%rsp),%rax
sub    %ebp,%eax
mov    %rax,0x10(%rsp)
cmp    0x8(%rsp),%r13b
lea    0xe0c(%rip),%rax
lea    0xe03(%rip),%rcx
cmove  %rax,%rcx
mov    %rcx,0x8(%rsp)
lea    (%r14,%rbp,8),%r12
lea    0xde2(%rip),%rdi
lea    0x20(%rsp),%r15
mov    0x10(%rsp),%rbx
mov    0x8(%rsp),%r13
jmp    126b <main+0x10b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xdbf(%rip),%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
lea    0xda9(%rip),%rdi
jne    12b4 <main+0x154>
mov    %r15,%rsi
call   1040 <printf@plt>
test   %ebx,%ebx
jle    1250 <main+0xf0>
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    (%r12,%r14,8),%rdi
mov    %r13,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xd79(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
add    $0x1,%r14
cmp    %r14,%rbx
jne    1280 <main+0x120>
jmp    1250 <main+0xf0>
mov    0x18(%rsp),%rsp
xor    %eax,%eax
jmp    12e2 <main+0x182>
mov    0x2d04(%rip),%rax
mov    (%rax),%rdi
mov    0x2d2a(%rip),%rax
mov    (%rax),%rdx
lea    0xd2b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"a:\00"
@EOF = global i8 0
@optind = global i64 0
@stderr = global i32* null
@.str.1 = [19 x i8] c"Unkown option: %s\0A\00"
@optarg = global i8* null
@.str.2 = [9 x i8] c"%79[^\0A]\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca i8
%8 = alloca i8
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 119, i8* %8
br label %12
12: ; preds = %31, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call signext i8 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([3 x i8], [3 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 %32
20: ; preds = %12
%21 = load i8, i8* %7
%22 = sext i8 %21 to i32
switch i32 %22, label %27 [
i32 97, label %23
]
23: ; preds = %20
%24 = load i8, i8* %7
store i8 %24, i8* %8
%25 = load i64, i64* @optind
%26 = add nsw i64 %25, -1
store i64 %26, i64* @optind
br label %31
27: ; preds = %20
%28 = load i32*, i32** @stderr
%29 = load i8*, i8** @optarg
%30 = call i32 @fprintf(i32* %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32 1, i32* %3
br label %98
31: ; preds = %23
br label %12
32: ; preds = %12
%33 = load i64, i64* @optind
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = sub nsw i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %4
%38 = load i64, i64* @optind
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 %38
store i8** %40, i8*** %5
%41 = load i32, i32* %4
%42 = zext i32 %41 to i64
%43 = call i8* @llvm.stacksave()
store i8* %43, i8** %10
%44 = alloca i32*, i64 %42
store i64 %42, i64* %11
br label %45
45: ; preds = %95, %32
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%47 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %46)
%48 = icmp eq i32 %47, 1
br i1 %48, label %49, label %96
49: ; preds = %45
%50 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %50)
store i32 0, i32* %9
br label %52
52: ; preds = %92, %49
%53 = load i32, i32* %9
%54 = load i32, i32* %4
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %95
56: ; preds = %52
%57 = load i8, i8* %8
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 97
br i1 %59, label %60, label %70
60: ; preds = %56
%61 = load i8**, i8*** %5
%62 = load i32, i32* %9
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i32* @fopen(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%67 = load i32, i32* %9
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32*, i32** %44, i64 %68
store i32* %66, i32** %69
br label %80
70: ; preds = %56
%71 = load i8**, i8*** %5
%72 = load i32, i32* %9
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = call i32* @fopen(i8* %75, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%77 = load i32, i32* %9
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i32*, i32** %44, i64 %78
store i32* %76, i32** %79
br label %80
80: ; preds = %70, %60
%81 = load i32, i32* %9
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i32*, i32** %44, i64 %82
%84 = load i32*, i32** %83
%85 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%86 = call i32 @fprintf(i32* %84, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %85)
%87 = load i32, i32* %9
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i32*, i32** %44, i64 %88
%90 = load i32*, i32** %89
%91 = call i32 @fclose(i32* %90)
br label %92
92: ; preds = %80
%93 = load i32, i32* %9
%94 = add nsw i32 %93, 1
store i32 %94, i32* %9
br label %52
95: ; preds = %52
br label %45
96: ; preds = %45
store i32 0, i32* %3
%97 = load i8*, i8** %10
br label %98
98: ; preds = %96, %27
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
@.str = [3 x i8] c"a:\00"
@EOF = global i8 0
@optind = global i64 0
@stderr = global i32* null
@.str.1 = [19 x i8] c"Unkown option: %s\0A\00"
@optarg = global i8* null
@.str.2 = [9 x i8] c"%79[^\0A]\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [2 x i8] c"w\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 ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = load i8, i8* @EOF
%7 = icmp eq i8 %5, %6
br i1 %7, label %21, label %8
8: ; preds = %2, %11
%9 = phi i8 [ %14, %11 ], [ %5, %2 ]
%10 = icmp eq i8 %9, 97
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i64, i64* @optind
%13 = add nsw i64 %12, -1
store i64 %13, i64* @optind
%14 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = load i8, i8* @EOF
%16 = icmp eq i8 %14, %15
br i1 %16, label %21, label %8
17: ; preds = %8
%18 = load i32*, i32** @stderr
%19 = load i8*, i8** @optarg
%20 = tail call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %48
21: ; preds = %11, %2
%22 = load i64, i64* @optind
%23 = trunc i64 %22 to i32
%24 = sub i32 %0, %23
%25 = getelementptr inbounds i8*, i8** %1, i64 %22
%26 = zext i32 %24 to i64
%27 = tail call i8* @llvm.stacksave()
%28 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %47
30: ; preds = %21
%31 = icmp sgt i32 %24, 0
%32 = select i1 %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
br label %36
33: ; preds = %38, %36
%34 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %47
36: ; preds = %30, %33
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br i1 %31, label %38, label %33
38: ; preds = %36, %38
%39 = phi i64 [ %45, %38 ], [ 0, %36 ]
%40 = getelementptr inbounds i8*, i8** %25, i64 %39
%41 = load i8*, i8** %40
%42 = call i32* @fopen(i8* %41, i8* %32)
%43 = call i32 @fprintf(i32* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%44 = call i32 @fclose(i32* %42)
%45 = add nuw nsw i64 %39, 1
%46 = icmp eq i64 %45, %26
br i1 %46, label %33, label %38
47: ; preds = %33, %21
br label %48
48: ; preds = %47, %17
%49 = phi i32 [ 1, %17 ], [ 0, %47 ]
ret i32 %49
}