#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 mode_t;

/* Variables and functions */
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int /*<<< orphan*/ is_mkv(char const *);
int real_open(char const *, int, int);
int open(const char *path, int flags, mode_t mode) {
  if (!is_mkv(path))
    return real_open(path, flags, mode);
  return real_open(path, flags,
                   S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
}


x86 assembly (clang, -O0):
<open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <is_mkv@plt>
cmp    $0x0,%eax
jne    115b <open+0x3b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <real_open@plt>
mov    %eax,-0x4(%rbp)
jmp    11a0 <open+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
mov    0x2e6e(%rip),%rax
or     (%rax),%edx
mov    0x2e55(%rip),%rax
or     (%rax),%edx
mov    0x2e64(%rip),%rax
or     (%rax),%edx
mov    0x2e3b(%rip),%rax
or     (%rax),%edx
mov    0x2e1a(%rip),%rax
or     (%rax),%edx
call   1030 <real_open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
call   1040 <is_mkv@plt>
test   %eax,%eax
je     116b <open+0x4b>
mov    0x2e84(%rip),%rax
mov    0x2e9d(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    0x2e82(%rip),%rax
or     (%rax),%ebp
mov    0x2e91(%rip),%rax
or     (%rax),%ebp
mov    0x2e68(%rip),%rax
or     (%rax),%ebp
mov    0x2e47(%rip),%rax
or     (%rax),%ebp
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <real_open@plt>

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
define i32 @open(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = call i32 @is_mkv(i8* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = call i32 @real_open(i8* %12, i32 %13, i32 %14)
store i32 %15, i32* %4
br label %31
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = load i32, i32* @S_IRUSR
%20 = load i32, i32* @S_IWUSR
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IRGRP
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IWGRP
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IROTH
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IWOTH
%29 = or i32 %27, %28
%30 = call i32 @real_open(i8* %17, i32 %18, i32 %29)
store i32 %30, i32* %4
br label %31
31: ; preds = %16, %11
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
define i32 @open(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @is_mkv(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRGRP
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IWGRP
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IROTH
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IWOTH
%17 = or i32 %15, %16
br label %18
18: ; preds = %3, %6
%19 = phi i32 [ %17, %6 ], [ %2, %3 ]
%20 = tail call i32 @real_open(i8* %0, i32 %1, i32 %19)
ret i32 %20
}