#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_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
char getopt(int, char **, char *);
size_t optind;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  char option = getopt(argc, argv, "a");
  FILE *file = NULL;
  if (argv[optind] != NULL) {
    file = fopen(argv[optind], "w");
  }
  char line[1024];
  while (fgets(line, 1024, stdin) != NULL) {
    fputs(line, stdout);
    if (file != NULL)
      fputs(line, file);
  }
  if (file != NULL) {
    fclose(file);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe79(%rip),%rdx
call   1070 <getopt@plt>
mov    %al,-0x11(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e3e(%rip),%rcx
mov    (%rcx),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11d2 <main+0x72>
mov    -0x10(%rbp),%rax
mov    0x2e25(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe39(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
jmp    11d7 <main+0x77>
lea    -0x420(%rbp),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1231 <main+0xd1>
lea    -0x420(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%rsi
call   1040 <fputs@plt>
cmpq   $0x0,-0x20(%rbp)
je     122c <main+0xcc>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fputs@plt>
jmp    11d7 <main+0x77>
cmpq   $0x0,-0x20(%rbp)
je     1245 <main+0xe5>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
lea    0xe88(%rip),%rdx
call   1070 <getopt@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rax
mov    (%rbx,%rax,8),%rdi
test   %rdi,%rdi
jne    1195 <main+0x35>
xor    %r14d,%r14d
jmp    11a4 <main+0x44>
lea    0xe66(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    0x2e3d(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1050 <fgets@plt>
test   %rax,%rax
jne    11db <main+0x7b>
test   %r14,%r14
je     11cd <main+0x6d>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2dee(%rip),%r12
mov    %rsp,%rbx
jmp    1205 <main+0xa5>
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11c0 <main+0x60>
mov    (%r12),%rsi
mov    %rbx,%rdi
call   1040 <fputs@plt>
test   %r14,%r14
je     11f0 <main+0x90>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
jmp    11f0 <main+0x90>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@optind = global i64 0
@.str.1 = [2 x i8] c"w\00"
@stdin = global i32 0
@stdout = global i32* null
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32*
%8 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call signext i8 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8 %11, i8* %6
store i32* null, i32** %7
%12 = load i8**, i8*** %5
%13 = load i64, i64* @optind
%14 = getelementptr inbounds i8*, i8** %12, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = load i64, i64* @optind
%20 = getelementptr inbounds i8*, i8** %18, i64 %19
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %7
br label %23
23: ; preds = %17, %2
br label %24
24: ; preds = %39, %23
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%26 = load i32, i32* @stdin
%27 = call i32* @fgets(i8* %25, i32 1024, i32 %26)
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %40
29: ; preds = %24
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%31 = load i32*, i32** @stdout
%32 = call i32 @fputs(i8* %30, i32* %31)
%33 = load i32*, i32** %7
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%37 = load i32*, i32** %7
%38 = call i32 @fputs(i8* %36, i32* %37)
br label %39
39: ; preds = %35, %29
br label %24
40: ; preds = %24
%41 = load i32*, i32** %7
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32*, i32** %7
%45 = call i32 @fclose(i32* %44)
br label %46
46: ; preds = %43, %40
%47 = load i32, i32* @EXIT_SUCCESS
%48 = call i32 @exit(i32 %47)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@optind = global i64 0
@.str.1 = [2 x i8] c"w\00"
@stdin = global i32 0
@stdout = global i32* null
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1024 x i8]
%4 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = load i64, i64* @optind
%6 = getelementptr inbounds i8*, i8** %1, i64 %5
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = phi i32* [ %10, %9 ], [ null, %2 ]
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32* @fgets(i8* %13, i32 1024, i32 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %28, label %17
17: ; preds = %11
%18 = icmp eq i32* %12, null
br label %19
19: ; preds = %17, %24
%20 = load i32*, i32** @stdout
%21 = call i32 @fputs(i8* %13, i32* %20)
br i1 %18, label %24, label %22
22: ; preds = %19
%23 = call i32 @fputs(i8* %13, i32* %12)
br label %24
24: ; preds = %22, %19
%25 = load i32, i32* @stdin
%26 = call i32* @fgets(i8* %13, i32 1024, i32 %25)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %19
28: ; preds = %24, %11
%29 = icmp eq i32* %12, null
br i1 %29, label %32, label %30
30: ; preds = %28
%31 = call i32 @fclose(i32* %12)
br label %32
32: ; preds = %30, %28
%33 = load i32, i32* @EXIT_SUCCESS
%34 = call i32 @exit(i32 %33)
unreachable
}