#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 */

/* Variables and functions */
scalar_t__ strchr(char const *, char);
int /*<<< orphan*/ strcmp(char const *, char *);
int begets_stdio(const char *name, const char *mode) {
  if ((strchr(mode, 'r') && !strcmp(name, "-")) ||
      ((strchr(mode, 'w') || strchr(mode, 'a')) &&
       (!strcmp(name, "-") || !strcmp(name, "stderr"))))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<begets_stdio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x72,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1161 <begets_stdio+0x41>
mov    -0x10(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     11c3 <begets_stdio+0xa3>
mov    -0x18(%rbp),%rdi
mov    $0x77,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    1191 <begets_stdio+0x71>
mov    -0x18(%rbp),%rdi
mov    $0x61,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11cf <begets_stdio+0xaf>
mov    -0x10(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     11c3 <begets_stdio+0xa3>
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11cf <begets_stdio+0xaf>
movl   $0x1,-0x4(%rbp)
jmp    11d6 <begets_stdio+0xb6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<begets_stdio>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
mov    $0x72,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     114f <begets_stdio+0x2f>
lea    0xebd(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11a2 <begets_stdio+0x82>
mov    %rbx,%rdi
mov    $0x77,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1173 <begets_stdio+0x53>
mov    %rbx,%rdi
mov    $0x61,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     119e <begets_stdio+0x7e>
lea    0xe86(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
mov    $0x1,%ebx
test   %eax,%eax
je     11a7 <begets_stdio+0x87>
lea    0xe70(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11a7 <begets_stdio+0x87>
xor    %ebx,%ebx
jmp    11a7 <begets_stdio+0x87>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [7 x i8] c"stderr\00"
define i32 @begets_stdio(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** %5
%7 = call i64 @strchr(i8* %6, i8 signext 114)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %9, %2
%14 = load i8*, i8** %5
%15 = call i64 @strchr(i8* %14, i8 signext 119)
%16 = icmp ne i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = call i64 @strchr(i8* %18, i8 signext 97)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %17, %13
%22 = load i8*, i8** %4
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %25, %21, %9
store i32 1, i32* %3
br label %31
30: ; preds = %25, %17
store i32 0, i32* %3
br label %31
31: ; preds = %30, %29
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@.str.1 = [7 x i8] c"stderr\00"
define i32 @begets_stdio(i8* nocapture %0, i8* %1) {
%3 = tail call i64 @strchr(i8* %1, i8 signext 114)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %5, %2
%9 = tail call i64 @strchr(i8* %1, i8 signext 119)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i64 @strchr(i8* %1, i8 signext 97)
%13 = icmp eq i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %11, %8
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %17, %11
br label %21
21: ; preds = %5, %14, %17, %20
%22 = phi i32 [ 0, %20 ], [ 1, %17 ], [ 1, %14 ], [ 1, %5 ]
ret i32 %22
}