#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*/ *fopen(char *, char *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcmp(char *, char *);
FILE *open_read(char *fname) {
  if (!fname[0])
    return NULL;
  if (!strcmp(fname, "stdout"))
    return stdout;
  else if (!strcmp(fname, "stderr"))
    return stderr;
  else
    return fopen(fname, "rt");
}


x86 assembly (clang, -O0):
<open_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1146 <open_read+0x26>
movq   $0x0,-0x8(%rbp)
jmp    11b2 <open_read+0x92>
mov    -0x10(%rbp),%rdi
lea    0xeaf(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1172 <open_read+0x52>
mov    0x2e72(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11b2 <open_read+0x92>
mov    -0x10(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    119e <open_read+0x7e>
mov    0x2e4e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11b2 <open_read+0x92>
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_read>:
push   %rbx
cmpb   $0x0,(%rdi)
je     115c <open_read+0x3c>
mov    %rdi,%rbx
lea    0xed0(%rip),%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1160 <open_read+0x40>
lea    0xec7(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1169 <open_read+0x49>
lea    0xebb(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <fopen@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e71(%rip),%rax
jmp    1170 <open_read+0x50>
mov    0x2e70(%rip),%rax
mov    (%rax),%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"stdout\00"
@stdout = global i32* null
@.str.1 = [7 x i8] c"stderr\00"
@stderr = global i32* null
@.str.2 = [3 x i8] c"rt\00"
define i32* @open_read(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %1
store i32* null, i32** %2
br label %24
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = load i32*, i32** @stdout
store i32* %14, i32** %2
br label %24
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = call i32 @strcmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = load i32*, i32** @stderr
store i32* %20, i32** %2
br label %24
21: ; preds = %15
%22 = load i8*, i8** %3
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %2
br label %24
24: ; preds = %21, %19, %13, %8
%25 = load i32*, i32** %2
ret i32* %25
}

LLVM IR (-O2):
@.str = [7 x i8] c"stdout\00"
@stdout = global i32* null
@.str.1 = [7 x i8] c"stderr\00"
@stderr = global i32* null
@.str.2 = [3 x i8] c"rt\00"
define i32* @open_read(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = load i32*, i32** @stdout
br label %16
9: ; preds = %4
%10 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = load i32*, i32** @stderr
br label %16
14: ; preds = %9
%15 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %1, %14, %12, %7
%17 = phi i32* [ %15, %14 ], [ %13, %12 ], [ %8, %7 ], [ null, %1 ]
ret i32* %17
}