#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__ perf_i915_open(int, int);
int perf_open(unsigned *flags) {
  int fd;
  fd = perf_i915_open(40, -1);
  if (fd < 0)
    return -1;
  *flags |= (1 << 0);
  if (perf_i915_open(41, fd) >= 0)
    *flags |= (1 << 1);
  if (perf_i915_open(42, fd) >= 0)
    *flags |= (1 << 2);
  return fd;
}


x86 assembly (clang, -O0):
<perf_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x28,%edi
mov    $0xffffffff,%esi
call   1030 <perf_i915_open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1144 <perf_open+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <perf_open+0x89>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
or     $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%esi
mov    $0x29,%edi
call   1030 <perf_i915_open@plt>
cmp    $0x0,%rax
jl     1171 <perf_open+0x61>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
or     $0x2,%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%esi
mov    $0x2a,%edi
call   1030 <perf_i915_open@plt>
cmp    $0x0,%rax
jl     1193 <perf_open+0x83>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
or     $0x4,%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perf_open>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0xffffffff,%ebp
mov    $0x28,%edi
mov    $0xffffffff,%esi
call   1030 <perf_i915_open@plt>
mov    %rax,%rbx
test   %ebx,%ebx
js     1162 <perf_open+0x52>
orb    $0x1,(%r14)
mov    $0x29,%edi
mov    %ebx,%esi
call   1030 <perf_i915_open@plt>
test   %rax,%rax
js     114b <perf_open+0x3b>
orb    $0x2,(%r14)
mov    $0x2a,%edi
mov    %ebx,%esi
call   1030 <perf_i915_open@plt>
test   %rax,%rax
js     1160 <perf_open+0x50>
orb    $0x4,(%r14)
mov    %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @perf_open(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = call i64 @perf_i915_open(i32 40, i32 -1)
%6 = trunc i64 %5 to i32
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %31
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = load i32, i32* %11
%13 = or i32 %12, 1
store i32 %13, i32* %11
%14 = load i32, i32* %4
%15 = call i64 @perf_i915_open(i32 41, i32 %14)
%16 = icmp sge i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i32*, i32** %3
%19 = load i32, i32* %18
%20 = or i32 %19, 2
store i32 %20, i32* %18
br label %21
21: ; preds = %17, %10
%22 = load i32, i32* %4
%23 = call i64 @perf_i915_open(i32 42, i32 %22)
%24 = icmp sge i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32*, i32** %3
%27 = load i32, i32* %26
%28 = or i32 %27, 4
store i32 %28, i32* %26
br label %29
29: ; preds = %25, %21
%30 = load i32, i32* %4
store i32 %30, i32* %2
br label %31
31: ; preds = %29, %9
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
define i32 @perf_open(i32* nocapture %0) {
%2 = tail call i64 @perf_i915_open(i32 40, i32 -1)
%3 = trunc i64 %2 to i32
%4 = icmp slt i32 %3, 0
br i1 %4, label %19, label %5
5: ; preds = %1
%6 = load i32, i32* %0
%7 = or i32 %6, 1
store i32 %7, i32* %0
%8 = tail call i64 @perf_i915_open(i32 41, i32 %3)
%9 = icmp sgt i64 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* %0
%12 = or i32 %11, 2
store i32 %12, i32* %0
br label %13
13: ; preds = %10, %5
%14 = tail call i64 @perf_i915_open(i32 42, i32 %3)
%15 = icmp sgt i64 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %0
%18 = or i32 %17, 4
store i32 %18, i32* %0
br label %19
19: ; preds = %13, %16, %1
%20 = phi i32 [ -1, %1 ], [ %3, %16 ], [ %3, %13 ]
ret i32 %20
}