#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 char FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(char *);
char *fopen(char *, char *);
int /*<<< orphan*/ fprintf(char *, char *, ...);
int fscanf(char *, char *, char *);
int /*<<< orphan*/ fseek(char *, int /*<<< orphan*/, int /*<<< orphan*/);
char getopt(int, char **, char *);
scalar_t__ optind;
char *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 = fopen(argv[count], "w");
    fprintf(stdout, "Initial location: %p\n", out_file);
    if (append) {
      out_file = fopen(argv[count], "a");
      fseek(out_file, 0, SEEK_END);
      fprintf(stdout, "Appended location: %p\n", out_file);
    }
    fprintf(stdout, "Current location: %p\n", out_file);
    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    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe55(%rip),%rdx
call   1080 <getopt@plt>
mov    %al,-0x69(%rbp)
movsbl %al,%eax
mov    0x2e21(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1227 <main+0xc7>
mov    -0x69(%rbp),%al
sub    $0x61,%al
jne    11fe <main+0x9e>
jmp    11da <main+0x7a>
movl   $0x1,-0x68(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%rdi
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1222 <main+0xc2>
mov    0x2dc3(%rip),%rax
mov    (%rax),%rdi
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1389 <main+0x229>
jmp    119f <main+0x3f>
mov    0x2daa(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2d96(%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    1379 <main+0x219>
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdc8(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x80(%rbp)
mov    0x2d41(%rip),%rax
mov    (%rax),%rdi
mov    -0x80(%rbp),%rdx
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0x68(%rbp)
je     12f2 <main+0x192>
mov    -0x10(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd49(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
mov    0x2d1b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%rdi
mov    -0x80(%rbp),%rdx
lea    0xd6c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2ccf(%rip),%rax
mov    (%rax),%rdi
mov    -0x80(%rbp),%rdx
lea    0xd67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x78(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xd67(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1362 <main+0x202>
mov    -0x80(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%rdi
lea    -0x60(%rbp),%rdx
lea    0xd37(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    130e <main+0x1ae>
mov    -0x80(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1258 <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,%r14
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe65(%rip),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
call   1080 <getopt@plt>
mov    0x2e32(%rip),%r13
mov    0x0(%r13),%cl
mov    %al,0x6(%rsp)
mov    %cl,0x7(%rsp)
cmp    %cl,%al
je     1204 <main+0x94>
mov    0x2e03(%rip),%r15
lea    0xe36(%rip),%r12
mov    0x6(%rsp),%al
mov    (%r15),%rcx
cmp    $0x61,%al
jne    1346 <main+0x1d6>
mov    $0x1f,%esi
mov    $0x1,%edx
lea    0xe18(%rip),%rdi
call   1090 <fwrite@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   1080 <getopt@plt>
cmp    0x0(%r13),%al
jne    11d0 <main+0x60>
mov    0x2dcd(%rip),%rax
mov    (%rax),%rax
sub    %eax,%ebp
cmp    $0x2,%ebp
jl     133a <main+0x1ca>
lea    (%r14,%rax,8),%rax
mov    %rax,0x8(%rsp)
mov    %ebp,%eax
mov    %rax,0x18(%rsp)
mov    $0x1,%ecx
mov    0x2d93(%rip),%r13
lea    0xe48(%rip),%rbp
lea    0x20(%rsp),%r14
lea    0xe45(%rip),%r15
jmp    126c <main+0xfc>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    0x10(%rsp),%rcx
add    $0x1,%rcx
cmp    0x18(%rsp),%rcx
je     133a <main+0x1ca>
mov    0x8(%rsp),%rax
mov    %rcx,0x10(%rsp)
mov    (%rax,%rcx,8),%rdi
lea    0xdbe(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    0x0(%r13),%rdi
lea    0xdad(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x7(%rsp),%al
cmp    %al,0x6(%rsp)
je     12ed <main+0x17d>
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd45(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    0x2d1c(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
mov    0x0(%r13),%rdi
lea    0xd74(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%r13),%rdi
lea    0xd76(%rip),%rsi
mov    %r12,%rdx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1250 <main+0xe0>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%r13),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
jmp    1300 <main+0x190>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1361 <main+0x1f1>
lea    0xcd7(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
call   1090 <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 i8* 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 = [22 x i8] c"Initial location: %p\0A\00"
@SEEK_END = global i32 0
@.str.6 = [23 x i8] c"Appended location: %p\0A\00"
@.str.7 = [22 x i8] c"Current location: %p\0A\00"
@.str.8 = [9 x i8] c"%79[^\0A]\0A\00"
@.str.9 = [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 i8*
%11 = alloca i8*
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 i8* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %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 i8*, i8** @stdout
%29 = call i32 (i8*, i8*, ...) @fprintf(i8* %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %33
30: ; preds = %24
%31 = load i8*, i8** @stdout
%32 = call i32 (i8*, i8*, ...) @fprintf(i8* %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %97
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 = %91, %34
%44 = load i32, i32* %7
%45 = load i32, i32* %4
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %94
47: ; preds = %43
%48 = load i8**, i8*** %5
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i8* @fopen(i8* %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %53, i8** %11
%54 = load i8*, i8** @stdout
%55 = load i8*, i8** %11
%56 = call i32 (i8*, i8*, ...) @fprintf(i8* %54, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %55)
%57 = load i32, i32* %8
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %72
59: ; preds = %47
%60 = load i8**, i8*** %5
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
%64 = load i8*, i8** %63
%65 = call i8* @fopen(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %65, i8** %11
%66 = load i8*, i8** %11
%67 = load i32, i32* @SEEK_END
%68 = call i32 @fseek(i8* %66, i32 0, i32 %67)
%69 = load i8*, i8** @stdout
%70 = load i8*, i8** %11
%71 = call i32 (i8*, i8*, ...) @fprintf(i8* %69, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %59, %47
%73 = load i8*, i8** @stdout
%74 = load i8*, i8** %11
%75 = call i32 (i8*, i8*, ...) @fprintf(i8* %73, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %81, %72
%77 = load i8*, i8** %10
%78 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%79 = call i32 @fscanf(i8* %77, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %78)
%80 = icmp eq i32 %79, 1
br i1 %80, label %81, label %88
81: ; preds = %76
%82 = load i8*, i8** %11
%83 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%84 = call i32 (i8*, i8*, ...) @fprintf(i8* %82, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %83)
%85 = load i8*, i8** @stdout
%86 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%87 = call i32 (i8*, i8*, ...) @fprintf(i8* %85, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %86)
br label %76
88: ; preds = %76
%89 = load i8*, i8** %11
%90 = call i32 @fclose(i8* %89)
br label %91
91: ; preds = %88
%92 = load i32, i32* %7
%93 = add nsw i32 %92, 1
store i32 %93, i32* %7
br label %43
94: ; preds = %43
%95 = load i8*, i8** %10
%96 = call i32 @fclose(i8* %95)
store i32 0, i32* %3
br label %97
97: ; preds = %94, %30
%98 = load i32, i32* %3
ret i32 %98
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"a\00"
@EOF = global i8 0
@stdout = global i8* 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 = [22 x i8] c"Initial location: %p\0A\00"
@SEEK_END = global i32 0
@.str.6 = [23 x i8] c"Appended location: %p\0A\00"
@.str.7 = [22 x i8] c"Current location: %p\0A\00"
@.str.8 = [9 x i8] c"%79[^\0A]\0A\00"
@.str.9 = [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 i8* @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 i8*, i8** @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, i8* %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, i8* %14)
br label %62
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 %60
28: ; preds = %22
%29 = zext i32 %25 to i64
br label %30
30: ; preds = %28, %56
%31 = phi i64 [ 1, %28 ], [ %58, %56 ]
%32 = getelementptr inbounds i8*, i8** %26, i64 %31
%33 = load i8*, i8** %32
%34 = call i8* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%35 = load i8*, i8** @stdout
%36 = call i32 (i8*, i8*, ...) @fprintf(i8* %35, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %34)
br i1 %10, label %44, label %37
37: ; preds = %30
%38 = load i8*, i8** %32
%39 = call i8* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* @SEEK_END
%41 = call i32 @fseek(i8* %39, i32 0, i32 %40)
%42 = load i8*, i8** @stdout
%43 = call i32 (i8*, i8*, ...) @fprintf(i8* %42, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %39)
br label %44
44: ; preds = %37, %30
%45 = phi i8* [ %39, %37 ], [ %34, %30 ]
%46 = load i8*, i8** @stdout
%47 = call i32 (i8*, i8*, ...) @fprintf(i8* %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* %45)
%48 = call i32 @fscanf(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %4)
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %56
50: ; preds = %44, %50
%51 = call i32 (i8*, i8*, ...) @fprintf(i8* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %4)
%52 = load i8*, i8** @stdout
%53 = call i32 (i8*, i8*, ...) @fprintf(i8* %52, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %4)
%54 = call i32 @fscanf(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i8* %4)
%55 = icmp eq i32 %54, 1
br i1 %55, label %50, label %56
56: ; preds = %50, %44
%57 = call i32 @fclose(i8* %45)
%58 = add nuw nsw i64 %31, 1
%59 = icmp eq i64 %58, %29
br i1 %59, label %60, label %30
60: ; preds = %56, %22
%61 = call i32 @fclose(i8* %7)
br label %62
62: ; preds = %60, %20
%63 = phi i32 [ 1, %20 ], [ 0, %60 ]
ret i32 %63
}