#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stderr;
int main() {
  FILE *in, *out;
  char buffer[80 + 1];
  char infilename[40];
  char outfilename[40];
  printf("Please enter an input file name -- ");
  scanf("%s", infilename);
  printf("Please enter an output file name -- ");
  scanf("%s", outfilename);
  if ((in = fopen(infilename, "r")) == NULL) {
    fprintf(stderr, "Cannot open input file - exiting!\n");
    exit(1);
  }
  if ((out = fopen(outfilename, "w")) == NULL) {
    fprintf(stderr, "Cannot open output file - exiting!\n");
    exit(1);
  }
  fgets(buffer, 80, in);
  int i = 1;
  while (!feof(in)) {
    printf(" - %s", buffer);
    fputs(buffer, out);
    fgets(buffer, 80, in);
  }
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xa0(%rbp),%rsi
lea    0xed9(%rip),%rdi
call   1090 <scanf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xd0(%rbp),%rsi
lea    0xeb8(%rip),%rdi
call   1090 <scanf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1224 <main+0x94>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0xd0(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1264 <main+0xd4>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
movl   $0x1,-0xd4(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    129e <main+0x10e>
jmp    12d4 <main+0x144>
lea    -0x70(%rbp),%rsi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fputs@plt>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
jmp    1280 <main+0xf0>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb8,%rsp
lea    0xe5b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xee4(%rip),%rbx
lea    0x30(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <scanf@plt>
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1090 <scanf@plt>
lea    0xe66(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1295 <main+0x105>
mov    %rax,%r12
lea    0xe70(%rip),%rsi
mov    %rsp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12a7 <main+0x117>
mov    %rax,%r14
lea    0x60(%rsp),%rdi
mov    $0x50,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
mov    %r12,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    1274 <main+0xe4>
lea    0xe5d(%rip),%r15
lea    0x60(%rsp),%rbx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fputs@plt>
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
mov    %r12,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1240 <main+0xb0>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
jmp    12b7 <main+0x127>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Please enter an input file name -- \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [37 x i8] c"Please enter an output file name -- \00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [35 x i8] c"Cannot open input file - exiting!\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [36 x i8] c"Cannot open output file - exiting!\0A\00"
@.str.7 = [6 x i8] c" - %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [81 x i8]
%5 = alloca [40 x i8]
%6 = alloca [40 x i8]
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%12 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %15, i32** %2
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %0
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %0
%22 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %23, i32** %3
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%31 = load i32*, i32** %2
%32 = call i32 @fgets(i8* %30, i32 80, i32* %31)
store i32 1, i32* %7
br label %33
33: ; preds = %38, %29
%34 = load i32*, i32** %2
%35 = call i32 @feof(i32* %34)
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br i1 %37, label %38, label %47
38: ; preds = %33
%39 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %39)
%41 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%42 = load i32*, i32** %3
%43 = call i32 @fputs(i8* %41, i32* %42)
%44 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%45 = load i32*, i32** %2
%46 = call i32 @fgets(i8* %44, i32 80, i32* %45)
br label %33
47: ; preds = %33
%48 = load i32*, i32** %2
%49 = call i32 @fclose(i32* %48)
%50 = load i32*, i32** %3
%51 = call i32 @fclose(i32* %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Please enter an input file name -- \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [37 x i8] c"Please enter an output file name -- \00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [35 x i8] c"Cannot open input file - exiting!\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [36 x i8] c"Cannot open output file - exiting!\0A\00"
@.str.7 = [6 x i8] c" - %s\00"
define i32 @main() {
%1 = alloca [81 x i8]
%2 = alloca [40 x i8]
%3 = alloca [40 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %0
%18 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %17
%25 = call i32 @fgets(i8* %4, i32 80, i32* %11)
%26 = call i32 @feof(i32* %11)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %24, %28
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %4)
%30 = call i32 @fputs(i8* %4, i32* %18)
%31 = call i32 @fgets(i8* %4, i32 80, i32* %11)
%32 = call i32 @feof(i32* %11)
%33 = icmp eq i32 %32, 0
br i1 %33, label %28, label %34
34: ; preds = %28, %24
%35 = call i32 @fclose(i32* %11)
%36 = call i32 @fclose(i32* %18)
ret i32 0
}