#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 */
struct _XTreeHandle {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ __xregion_lockop(struct _XTreeHandle *, int, int);
scalar_t__ __xregion_refcnt(struct _XTreeHandle *, int);
void _xregion_cap_th(int rgc, int wc, int rc, struct _XTreeHandle *t) {
  if (__xregion_refcnt(t, rgc) && (wc || rc))
    __xregion_lockop(t, wc, rc);
}


x86 assembly (clang, -O0):
<_xregion_cap_th>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1030 <__xregion_refcnt@plt>
cmp    $0x0,%rax
je     116e <_xregion_cap_th+0x4e>
cmpl   $0x0,-0x8(%rbp)
jne    115f <_xregion_cap_th+0x3f>
cmpl   $0x0,-0xc(%rbp)
je     116e <_xregion_cap_th+0x4e>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <__xregion_lockop@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_xregion_cap_th>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%esi
mov    %rcx,%rdi
call   1030 <__xregion_refcnt@plt>
mov    %r14d,%ecx
or     %ebp,%ecx
je     1153 <_xregion_cap_th+0x33>
test   %rax,%rax
je     1153 <_xregion_cap_th+0x33>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <__xregion_lockop@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct._XTreeHandle = type { i32 }
define void @_xregion_cap_th(i32 %0, i32 %1, i32 %2, %struct._XTreeHandle* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct._XTreeHandle*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store %struct._XTreeHandle* %3, %struct._XTreeHandle** %8
%9 = load %struct._XTreeHandle*, %struct._XTreeHandle** %8
%10 = load i32, i32* %5
%11 = call i64 @__xregion_refcnt(%struct._XTreeHandle* %9, i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %4
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16, %13
%20 = load %struct._XTreeHandle*, %struct._XTreeHandle** %8
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = call i32 @__xregion_lockop(%struct._XTreeHandle* %20, i32 %21, i32 %22)
br label %24
24: ; preds = %19, %16, %4
ret void
}

LLVM IR (-O2):
%struct._XTreeHandle = type { i32 }
define void @_xregion_cap_th(i32 %0, i32 %1, i32 %2, %struct._XTreeHandle* %3) {
%5 = tail call i64 @__xregion_refcnt(%struct._XTreeHandle* %3, i32 %0)
%6 = icmp eq i64 %5, 0
%7 = or i32 %2, %1
%8 = icmp eq i32 %7, 0
%9 = or i1 %8, %6
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = tail call i32 @__xregion_lockop(%struct._XTreeHandle* %3, i32 %1, i32 %2)
br label %12
12: ; preds = %10, %4
ret void
}