#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 *, ...);
int fscanf(int /*<<< orphan*/ *, char *, char *);
char getopt(int, char **, char *);
scalar_t__ optind;
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  char line[80];
  int count = 0;
  int append = 0;
  char ch;
  FILE *in = fopen(argv[1], "r");
  while ((ch = getopt(argc, argv, "a")) != EOF) {
    switch (ch) {
    case 'a':
      append = 1;
      fprintf(stdout, "Info will be appended to file \n");
      break;
    default:
      fprintf(stdout, "File will be overwritten \n");
      return 1;
    }
  }
  argc -= optind;
  argv += optind;
  for (count = 1; count < argc; count++) {
    FILE *out_file;
    if (append == 0)
      out_file = fopen(argv[count], "w");
    else if (append)
      out_file = fopen(argv[count], "a");
    while (fscanf(in, "%79[^\n]\n", line) == 1) {
      fprintf(out_file, "%s\n", line);
      fprintf(stdout, "%s\n", line);
    }
    fclose(out_file);
  }
  fclose(in);
  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)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe65(%rip),%rdx
call   1070 <getopt@plt>
mov    %al,-0x69(%rbp)
movsbl %al,%eax
mov    0x2e39(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1217 <main+0xc7>
mov    -0x69(%rbp),%al
sub    $0x61,%al
jne    11ee <main+0x9e>
jmp    11ca <main+0x7a>
movl   $0x1,-0x68(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%rdi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1212 <main+0xc2>
mov    0x2ddb(%rip),%rax
mov    (%rax),%rdi
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    132a <main+0x1da>
jmp    118f <main+0x3f>
mov    0x2dc2(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    131a <main+0x1ca>
cmpl   $0x0,-0x68(%rbp)
jne    127f <main+0x12f>
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdce(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x80(%rbp)
jmp    12aa <main+0x15a>
cmpl   $0x0,-0x68(%rbp)
je     12a5 <main+0x155>
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd66(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x80(%rbp)
jmp    12aa <main+0x15a>
jmp    12af <main+0x15f>
mov    -0x78(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xd83(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1303 <main+0x1b3>
mov    -0x80(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2ce7(%rip),%rax
mov    (%rax),%rdi
lea    -0x60(%rbp),%rdx
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12af <main+0x15f>
mov    -0x80(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1248 <main+0xf8>
mov    -0x78(%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    $0x78,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
lea    0xe75(%rip),%rdx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rdx,0x10(%rsp)
call   1070 <getopt@plt>
mov    0x2e45(%rip),%r14
mov    (%r14),%cl
mov    %al,(%rsp)
mov    %cl,0x8(%rsp)
cmp    %cl,%al
je     1203 <main+0xa3>
mov    0x2e18(%rip),%rbx
lea    0xe43(%rip),%r13
mov    (%rsp),%al
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx),%rcx
cmp    $0x61,%al
jne    12f1 <main+0x191>
mov    $0x1f,%esi
mov    $0x1,%edx
lea    0xe18(%rip),%rdi
call   1080 <fwrite@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r13,%rdx
call   1070 <getopt@plt>
cmp    (%r14),%al
jne    11d0 <main+0x70>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
sub    %eax,%ebp
cmp    $0x2,%ebp
jl     12e5 <main+0x185>
lea    (%r15,%rax,8),%rax
mov    %rax,0x18(%rsp)
mov    0x8(%rsp),%al
cmp    %al,(%rsp)
mov    %ebp,%eax
mov    %rax,0x8(%rsp)
lea    0xe09(%rip),%rax
mov    0x10(%rsp),%rcx
cmove  %rax,%rcx
mov    %rcx,0x10(%rsp)
mov    $0x1,%ecx
lea    0xdf1(%rip),%r15
lea    0x20(%rsp),%rbp
lea    0xdee(%rip),%r13
mov    0x2d6d(%rip),%r14
jmp    1287 <main+0x127>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%rsp),%rcx
add    $0x1,%rcx
cmp    0x8(%rsp),%rcx
je     12e5 <main+0x185>
mov    0x18(%rsp),%rax
mov    %rcx,(%rsp)
mov    (%rax,%rcx,8),%rdi
mov    0x10(%rsp),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1270 <main+0x110>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12b0 <main+0x150>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    130c <main+0x1ac>
lea    0xd2c(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    $0x1,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"a\00"
@EOF = global i8 0
@stdout = global i32* null
@.str.2 = [32 x i8] c"Info will be appended to file \0A\00"
@.str.3 = [27 x i8] c"File will be overwritten \0A\00"
@optind = global i64 0
@.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 i8
%10 = alloca i32*
%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
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %10
br label %16
16: ; preds = %33, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call signext i8 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8 %19, i8* %9
%20 = sext i8 %19 to i32
%21 = load i8, i8* @EOF
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %34
24: ; preds = %16
%25 = load i8, i8* %9
%26 = sext i8 %25 to i32
switch i32 %26, label %30 [
i32 97, label %27
]
27: ; preds = %24
store i32 1, i32* %8
%28 = load i32*, i32** @stdout
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %33
30: ; preds = %24
%31 = load i32*, i32** @stdout
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %90
33: ; preds = %27
br label %16
34: ; preds = %16
%35 = load i64, i64* @optind
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = sub nsw i64 %37, %35
%39 = trunc i64 %38 to i32
store i32 %39, i32* %4
%40 = load i64, i64* @optind
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 %40
store i8** %42, i8*** %5
store i32 1, i32* %7
br label %43
43: ; preds = %84, %34
%44 = load i32, i32* %7
%45 = load i32, i32* %4
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %87
47: ; preds = %43
%48 = load i32, i32* %8
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %47
%51 = load i8**, i8*** %5
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32* @fopen(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %56, i32** %11
br label %68
57: ; preds = %47
%58 = load i32, i32* %8
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %67
60: ; preds = %57
%61 = load i8**, i8*** %5
%62 = load i32, i32* %7
%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.1, i64 0, i64 0))
store i32* %66, i32** %11
br label %67
67: ; preds = %60, %57
br label %68
68: ; preds = %67, %50
br label %69
69: ; preds = %74, %68
%70 = load i32*, i32** %10
%71 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%72 = call i32 @fscanf(i32* %70, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %71)
%73 = icmp eq i32 %72, 1
br i1 %73, label %74, label %81
74: ; preds = %69
%75 = load i32*, i32** %11
%76 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%77 = call i32 (i32*, i8*, ...) @fprintf(i32* %75, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %76)
%78 = load i32*, i32** @stdout
%79 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%80 = call i32 (i32*, i8*, ...) @fprintf(i32* %78, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %79)
br label %69
81: ; preds = %69
%82 = load i32*, i32** %11
%83 = call i32 @fclose(i32* %82)
br label %84
84: ; preds = %81
%85 = load i32, i32* %7
%86 = add nsw i32 %85, 1
store i32 %86, i32* %7
br label %43
87: ; preds = %43
%88 = load i32*, i32** %10
%89 = call i32 @fclose(i32* %88)
store i32 0, i32* %3
br label %90
90: ; preds = %87, %30
%91 = load i32, i32* %3
ret i32 %91
}

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