#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
FILE *get_datafile(int argc, char *argv[]) {
  char *default_datafile_name = "default.sdc";
  char *datafile_name = NULL;
  if (argv[1] != NULL) {
    datafile_name = argv[1];
  } else {
    datafile_name = default_datafile_name;
  }
  FILE *datafile = fopen(datafile_name, "r");
  printf("\nOpening %s...\n", datafile_name);
  if (datafile_name == NULL) {
    printf("Couldn't open file %s\n", datafile_name);
    exit(EXIT_FAILURE);
  }
  return datafile;
}


x86 assembly (clang, -O0):
<get_datafile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1172 <get_datafile+0x42>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    117a <get_datafile+0x4a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11c7 <get_datafile+0x97>
mov    -0x20(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_datafile>:
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rax
test   %rax,%rax
lea    0xece(%rip),%rbx
cmovne %rax,%rbx
lea    0xecf(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
mov    %rax,%r14
lea    0xebf(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"default.sdc\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"\0AOpening %s...\0A\00"
@.str.3 = [23 x i8] c"Couldn't open file %s\0A\00"
@EXIT_FAILURE = global i32 0
define i32* @get_datafile(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* null, i8** %6
%8 = load i8**, i8*** %4
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %6
br label %18
16: ; preds = %2
%17 = load i8*, i8** %5
store i8* %17, i8** %6
br label %18
18: ; preds = %16, %12
%19 = load i8*, i8** %6
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i8*, i8** %6
%22 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %6
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i8*, i8** %6
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %18
%31 = load i32*, i32** %7
ret i32* %31
}

LLVM IR (-O2):
@.str = [12 x i8] c"default.sdc\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [16 x i8] c"\0AOpening %s...\0A\00"
@EXIT_FAILURE = global i32 0
define noalias i32* @get_datafile(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
%6 = select i1 %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %4
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %6)
ret i32* %7
}