#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 extent_buffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ BUG();
int /*<<< orphan*/ btrfs_tree_read_unlock(struct extent_buffer *);
int /*<<< orphan*/ btrfs_tree_read_unlock_blocking(struct extent_buffer *);
int /*<<< orphan*/ btrfs_tree_unlock(struct extent_buffer *);
void btrfs_tree_unlock_rw(struct extent_buffer *eb, int rw) {
  if (rw == 1 || rw == 3) {
    btrfs_tree_unlock(eb);
  } else if (rw == 4) {
    btrfs_tree_read_unlock_blocking(eb);
  } else if (rw == 2) {
    btrfs_tree_read_unlock(eb);
  } else {
    BUG();
  }
}


x86 assembly (clang, -O0):
<btrfs_tree_unlock_rw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
je     1163 <btrfs_tree_unlock_rw+0x23>
cmpl   $0x3,-0xc(%rbp)
jne    1171 <btrfs_tree_unlock_rw+0x31>
mov    -0x8(%rbp),%rdi
call   1050 <btrfs_tree_unlock@plt>
jmp    11b2 <btrfs_tree_unlock_rw+0x72>
cmpl   $0x4,-0xc(%rbp)
jne    1189 <btrfs_tree_unlock_rw+0x49>
mov    -0x8(%rbp),%rdi
call   1040 <btrfs_tree_read_unlock_blocking@plt>
jmp    11ad <btrfs_tree_unlock_rw+0x6d>
cmpl   $0x2,-0xc(%rbp)
jne    11a1 <btrfs_tree_unlock_rw+0x61>
mov    -0x8(%rbp),%rdi
call   1060 <btrfs_tree_read_unlock@plt>
jmp    11a8 <btrfs_tree_unlock_rw+0x68>
mov    $0x0,%al
call   1030 <BUG@plt>
jmp    11ad <btrfs_tree_unlock_rw+0x6d>
jmp    11b2 <btrfs_tree_unlock_rw+0x72>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<btrfs_tree_unlock_rw>:
mov    %esi,%eax
and    $0xfffffffd,%eax
cmp    $0x1,%eax
jne    114f <btrfs_tree_unlock_rw+0xf>
jmp    1050 <btrfs_tree_unlock@plt>
cmp    $0x2,%esi
je     115e <btrfs_tree_unlock_rw+0x1e>
cmp    $0x4,%esi
jne    1163 <btrfs_tree_unlock_rw+0x23>
jmp    1040 <btrfs_tree_read_unlock_blocking@plt>
jmp    1060 <btrfs_tree_read_unlock@plt>
xor    %eax,%eax
jmp    1030 <BUG@plt>

LLVM IR (-O0):
%struct.extent_buffer = type { i32 }
define void @btrfs_tree_unlock_rw(%struct.extent_buffer* %0, i32 %1) {
%3 = alloca %struct.extent_buffer*
%4 = alloca i32
store %struct.extent_buffer* %0, %struct.extent_buffer** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 1
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 3
br i1 %9, label %10, label %13
10: ; preds = %7, %2
%11 = load %struct.extent_buffer*, %struct.extent_buffer** %3
%12 = call i32 @btrfs_tree_unlock(%struct.extent_buffer* %11)
br label %29
13: ; preds = %7
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 4
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load %struct.extent_buffer*, %struct.extent_buffer** %3
%18 = call i32 @btrfs_tree_read_unlock_blocking(%struct.extent_buffer* %17)
br label %28
19: ; preds = %13
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load %struct.extent_buffer*, %struct.extent_buffer** %3
%24 = call i32 @btrfs_tree_read_unlock(%struct.extent_buffer* %23)
br label %27
25: ; preds = %19
%26 = call i32 (...) @BUG()
br label %27
27: ; preds = %25, %22
br label %28
28: ; preds = %27, %16
br label %29
29: ; preds = %28, %10
ret void
}

LLVM IR (-O2):
%struct.extent_buffer = type { i32 }
define void @btrfs_tree_unlock_rw(%struct.extent_buffer* %0, i32 %1) {
%3 = and i32 %1, -3
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @btrfs_tree_unlock(%struct.extent_buffer* %0)
br label %14
7: ; preds = %2
switch i32 %1, label %12 [
i32 4, label %8
i32 2, label %10
]
8: ; preds = %7
%9 = tail call i32 @btrfs_tree_read_unlock_blocking(%struct.extent_buffer* %0)
br label %14
10: ; preds = %7
%11 = tail call i32 @btrfs_tree_read_unlock(%struct.extent_buffer* %0)
br label %14
12: ; preds = %7
%13 = tail call i32 (...) @BUG()
br label %14
14: ; preds = %8, %12, %10, %5
ret void
}