#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*/ fatal(char *, char const *);
int /*<<< orphan*/ *fdopen(int /*<<< orphan*/, char const *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char const *, char const *);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char const *, char *);
FILE *open_input(const char **filename, const char *mode) {
  FILE *f;
  if (*filename == NULL || strcmp(*filename, "-") == 0) {
    f = fdopen(fileno(stdin), mode);
    *filename = "<stdin>";
  } else {
    f = fopen(*filename, mode);
  }
  if (f == NULL)
    fatal("can't open %s", *filename);
  return f;
}


x86 assembly (clang, -O0):
<open_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     118b <open_input+0x3b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xe84(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11bb <open_input+0x6b>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1050 <fdopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
lea    0xe4f(%rip),%rcx
mov    %rcx,(%rax)
jmp    11cf <open_input+0x7f>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ed <open_input+0x9d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
lea    0xe22(%rip),%rdi
call   1070 <fatal@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_input>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1189 <open_input+0x39>
lea    0xe96(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1189 <open_input+0x39>
mov    (%r15),%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
jne    11c2 <open_input+0x72>
jmp    11b3 <open_input+0x63>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <fdopen@plt>
mov    %rax,%rbx
lea    0xe57(%rip),%rax
mov    %rax,(%r15)
test   %rbx,%rbx
jne    11c2 <open_input+0x72>
mov    (%r15),%rsi
lea    0xe4d(%rip),%rdi
call   1070 <fatal@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdin = global i32 0
@.str.1 = [8 x i8] c"<stdin>\00"
@.str.2 = [14 x i8] c"can't open %s\00"
define i32* @open_input(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%6 = load i8**, i8*** %3
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i8**, i8*** %3
%11 = load i8*, i8** %10
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %9, %2
%15 = load i32, i32* @stdin
%16 = call i32 @fileno(i32 %15)
%17 = load i8*, i8** %4
%18 = call i32* @fdopen(i32 %16, i8* %17)
store i32* %18, i32** %5
%19 = load i8**, i8*** %3
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %19
br label %25
20: ; preds = %9
%21 = load i8**, i8*** %3
%22 = load i8*, i8** %21
%23 = load i8*, i8** %4
%24 = call i32* @fopen(i8* %22, i8* %23)
store i32* %24, i32** %5
br label %25
25: ; preds = %20, %14
%26 = load i32*, i32** %5
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i8**, i8*** %3
%30 = load i8*, i8** %29
%31 = call i32 @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %28, %25
%33 = load i32*, i32** %5
ret i32* %33
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdin = global i32 0
@.str.1 = [8 x i8] c"<stdin>\00"
@.str.2 = [14 x i8] c"can't open %s\00"
define i32* @open_input(i8** nocapture %0, i8* nocapture %1) {
%3 = load i8*, i8** %0
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %5, %2
%9 = load i32, i32* @stdin
%10 = tail call i32 @fileno(i32 %9)
%11 = tail call i32* @fdopen(i32 %10, i8* %1)
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %0
br label %15
12: ; preds = %5
%13 = load i8*, i8** %0
%14 = tail call i32* @fopen(i8* %13, i8* %1)
br label %15
15: ; preds = %12, %8
%16 = phi i32* [ %11, %8 ], [ %14, %12 ]
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i8*, i8** %0
%20 = tail call i32 @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %15
ret i32* %16
}