#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 const *, char const *);
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char const *);
FILE *_ifp_open(const char *file_name, unsigned short *from_file) {
  FILE *fp;
  unsigned short _from_file;
  const char *mode = "r";
  _from_file = (strcmp("-", file_name) != 0);
  if (from_file) {
    *from_file = _from_file;
  }
  fp = (_from_file) ? fopen(file_name, mode) : stdin;
  return fp;
}


x86 assembly (clang, -O0):
<_ifp_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec9(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xebc(%rip),%rdi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %ax,-0x1a(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1171 <_ifp_open+0x51>
mov    -0x1a(%rbp),%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
movzwl -0x1a(%rbp),%eax
cmp    $0x0,%eax
je     1194 <_ifp_open+0x74>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x30(%rbp)
jmp    11a2 <_ifp_open+0x82>
mov    0x2e4d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ifp_open>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xed1(%rip),%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rbx,%rbx
je     1149 <_ifp_open+0x29>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %cx,(%rbx)
test   %rax,%rax
je     1164 <_ifp_open+0x44>
lea    0xeab(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fopen@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"-\00"
@stdin = global i32* null
define i32* @_ifp_open(i8* %0, i16* writeonly %1) {
%3 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%4 = icmp ne i64 %3, 0
%5 = icmp eq i16* %1, null
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = zext i1 %4 to i16
store i16 %7, i16* %1
br label %8
8: ; preds = %6, %2
br i1 %4, label %9, label %11
9: ; preds = %8
%10 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %13
11: ; preds = %8
%12 = load i32*, i32** @stdin
br label %13
13: ; preds = %11, %9
%14 = phi i32* [ %10, %9 ], [ %12, %11 ]
ret i32* %14
}