#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*/ *stdin;
void fileopenr(FILE **filep, char *name) {
  switch (name[0]) {
  case 0:
    *filep = (FILE *)NULL;
    break;
  case '-':
    *filep = stdin;
    break;
  default:
    *filep = fopen(name, "r");
    break;
  }
}


x86 assembly (clang, -O0):
<fileopenr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     1148 <fileopenr+0x38>
jmp    1137 <fileopenr+0x27>
mov    -0x14(%rbp),%eax
sub    $0x2d,%eax
je     1158 <fileopenr+0x48>
jmp    116e <fileopenr+0x5e>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
jmp    1188 <fileopenr+0x78>
mov    0x2e89(%rip),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    1188 <fileopenr+0x78>
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileopenr>:
push   %rbx
mov    %rdi,%rbx
movsbl (%rsi),%eax
test   %eax,%eax
je     112c <fileopenr+0x1c>
cmp    $0x2d,%eax
jne    1130 <fileopenr+0x20>
mov    0x2ec1(%rip),%rax
mov    (%rax),%rax
jmp    1142 <fileopenr+0x32>
xor    %eax,%eax
jmp    1142 <fileopenr+0x32>
lea    0xec9(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1030 <fopen@plt>
mov    %rax,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
define void @fileopenr(i32** %0, i8* %1) {
%3 = alloca i32**
%4 = alloca i8*
store i32** %0, i32*** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
switch i32 %8, label %14 [
i32 0, label %9
i32 45, label %11
]
9: ; preds = %2
%10 = load i32**, i32*** %3
store i32* null, i32** %10
br label %18
11: ; preds = %2
%12 = load i32*, i32** @stdin
%13 = load i32**, i32*** %3
store i32* %12, i32** %13
br label %18
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = load i32**, i32*** %3
store i32* %16, i32** %17
br label %18
18: ; preds = %14, %11, %9
ret void
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
define void @fileopenr(i32** nocapture writeonly %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = sext i8 %3 to i32
switch i32 %4, label %7 [
i32 0, label %9
i32 45, label %5
]
5: ; preds = %2
%6 = load i32*, i32** @stdin
br label %9
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %2, %7, %5
%10 = phi i32* [ %8, %7 ], [ %6, %5 ], [ null, %2 ]
store i32* %10, i32** %0
ret void
}