#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 *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
FILE *open_file_std(char *fname, char *mode) {
  if (strcmp(fname, "-") == 0) {
    switch (mode[0]) {
    case 'r': {
      return stdin;
    }
    case 'w': {
      return stdout;
    }
    default: {
      fprintf(stderr, "Bad mode passed to open_file_std: %s\n", mode);
      exit(1);
    }
    }
  } else {
    return fopen(fname, mode);
  }
}


x86 assembly (clang, -O0):
<open_file_std>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11dc <open_file_std+0x9c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x72,%eax
je     1193 <open_file_std+0x53>
jmp    1182 <open_file_std+0x42>
mov    -0x1c(%rbp),%eax
sub    $0x77,%eax
je     11a6 <open_file_std+0x66>
jmp    11b9 <open_file_std+0x79>
mov    0x2e4e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11ed <open_file_std+0xad>
mov    0x2e23(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11ed <open_file_std+0xad>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe35(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file_std>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeaf(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     116d <open_file_std+0x2d>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <fopen@plt>
movsbl (%r14),%eax
cmp    $0x77,%eax
je     1184 <open_file_std+0x44>
cmp    $0x72,%eax
jne    1196 <open_file_std+0x56>
mov    0x2e66(%rip),%rax
jmp    118b <open_file_std+0x4b>
mov    0x2e45(%rip),%rax
mov    (%rax),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@stdout = global i32* null
@stderr = global i32 0
@.str.1 = [38 x i8] c"Bad mode passed to open_file_std: %s\0A\00"
define i32* @open_file_std(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
switch i32 %13, label %18 [
i32 114, label %14
i32 119, label %16
]
14: ; preds = %9
%15 = load i32*, i32** @stdin
store i32* %15, i32** %3
br label %27
16: ; preds = %9
%17 = load i32*, i32** @stdout
store i32* %17, i32** %3
br label %27
18: ; preds = %9
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %5
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = call i32* @fopen(i8* %24, i8* %25)
store i32* %26, i32** %3
br label %27
27: ; preds = %23, %16, %14
%28 = load i32*, i32** %3
ret i32* %28
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@stdout = global i32* null
@stderr = global i32 0
@.str.1 = [38 x i8] c"Bad mode passed to open_file_std: %s\0A\00"
define i32* @open_file_std(i8* %0, i8* %1) {
%3 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = load i8, i8* %1
%7 = sext i8 %6 to i32
switch i32 %7, label %12 [
i32 114, label %8
i32 119, label %10
]
8: ; preds = %5
%9 = load i32*, i32** @stdin
br label %18
10: ; preds = %5
%11 = load i32*, i32** @stdout
br label %18
12: ; preds = %5
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = tail call i32* @fopen(i8* %0, i8* %1)
br label %18
18: ; preds = %16, %10, %8
%19 = phi i32* [ %11, %10 ], [ %9, %8 ], [ %17, %16 ]
ret i32* %19
}