#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ free(char *);
char *read_optional_parameter(int, char **, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
FILE *get_output(int argc, char *argv[]) {
  FILE *out = stdout;
  char *strout = read_optional_parameter(argc, argv, "--output");
  if (strout == NULL) {
    strout = read_optional_parameter(argc, argv, "--O");
  }
  if (strout != NULL) {
    out = fopen(strout, "w");
    if (out == NULL) {
      fprintf(stderr, "%s: Can't open output file: %s\n", argv[0], strout);
      exit(2);
    }
    free(strout);
  }
  return out;
}


x86 assembly (clang, -O0):
<get_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdx
call   1060 <read_optional_parameter@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a6 <get_output+0x56>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdx
call   1060 <read_optional_parameter@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1203 <get_output+0xb3>
mov    -0x20(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fa <get_output+0xaa>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe24(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_output>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e75(%rip),%rax
mov    (%rax),%r15
lea    0xe93(%rip),%rdx
call   1060 <read_optional_parameter@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1193 <get_output+0x43>
lea    0xe88(%rip),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
call   1060 <read_optional_parameter@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11b2 <get_output+0x62>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c0 <get_output+0x70>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe3c(%rip),%rsi
mov    %rbx,%rcx
call   1040 <fprintf@plt>
mov    $0x2,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdout = global i32* null
@.str = [9 x i8] c"--output\00"
@.str.1 = [4 x i8] c"--O\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"%s: Can't open output file: %s\0A\00"
define i32* @get_output(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32*, i32** @stdout
store i32* %7, i32** %5
%8 = load i32, i32* %3
%9 = load i8**, i8*** %4
%10 = call i8* @read_optional_parameter(i32 %8, i8** %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* %3
%15 = load i8**, i8*** %4
%16 = call i8* @read_optional_parameter(i32 %14, i8** %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %6
br label %17
17: ; preds = %13, %2
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load i8*, i8** %6
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %5
%23 = load i32*, i32** %5
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = load i8*, i8** %6
%31 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %29, i8* %30)
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %20
%34 = load i8*, i8** %6
%35 = call i32 @free(i8* %34)
br label %36
36: ; preds = %33, %17
%37 = load i32*, i32** %5
ret i32* %37
}

LLVM IR (-O2):
@stdout = global i32* null
@.str = [9 x i8] c"--output\00"
@.str.1 = [4 x i8] c"--O\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"%s: Can't open output file: %s\0A\00"
define i32* @get_output(i32 %0, i8** %1) {
%3 = load i32*, i32** @stdout
%4 = tail call i8* @read_optional_parameter(i32 %0, i8** %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i8* @read_optional_parameter(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %20, label %9
9: ; preds = %2, %6
%10 = phi i8* [ %7, %6 ], [ %4, %2 ]
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %10)
%17 = tail call i32 @exit(i32 2)
unreachable
18: ; preds = %9
%19 = tail call i32 @free(i8* %10)
br label %20
20: ; preds = %18, %6
%21 = phi i32* [ %11, %18 ], [ %3, %6 ]
ret i32* %21
}