#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int scanf(char *, char *);
int main(int argc, char *argv[]) {
  char info[80];
  FILE *output_file;
  if (argv[1] == NULL) {
    output_file = fopen("output_file.txt", "w");
  } else {
    output_file = fopen(argv[1], "w");
  }
  while (scanf("%s\n", info) == 1) {
    fprintf(output_file, "%s\n", info);
    printf("%s\n", info);
  }
  fclose(output_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1191 <main+0x41>
lea    0xe84(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x68(%rbp)
jmp    11a9 <main+0x59>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe70(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x68(%rbp)
jmp    11ae <main+0x5e>
lea    -0x60(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11f0 <main+0xa0>
mov    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x60(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
jmp    11ae <main+0x5e>
mov    -0x68(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
jne    1169 <main+0x19>
lea    0xe97(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe93(%rip),%rdi
mov    %rsp,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    11c9 <main+0x79>
lea    0xe7f(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     11a0 <main+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"output_file.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %7
br label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %7
br label %19
19: ; preds = %14, %12
br label %20
20: ; preds = %24, %19
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%22 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i32*, i32** %7
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%27 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%29 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %20
30: ; preds = %20
%31 = load i32*, i32** %7
%32 = call i32 @fclose(i32* %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"output_file.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %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 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %12
10: ; preds = %2
%11 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
%13 = phi i32* [ %9, %8 ], [ %11, %10 ]
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %21
16: ; preds = %12, %16
%17 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%19 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%20 = icmp eq i32 %19, 1
br i1 %20, label %16, label %21
21: ; preds = %16, %12
%22 = call i32 @fclose(i32* %13)
ret i32 0
}