#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 */
int /*<<< orphan*/ node_cleanup_fullwr(int const);
scalar_t__ node_data_lock(int const);
int /*<<< orphan*/ node_data_unlock(int const);
scalar_t__ node_is_used_rd(int const);
int /*<<< orphan*/ node_unlock(int const);
scalar_t__ node_write(int const);
int tree_node_cleanup(const int id) {
  int ret = -3;
  if (node_data_lock(id) != 0)
    goto exit;
  if (node_write(id) != 0)
    goto unlock_data;
  if (node_is_used_rd(id)) {
    ret = -2;
    goto unlock;
  }
  node_cleanup_fullwr(id);
  ret = 0;
unlock:
  node_unlock(id);
unlock_data:
  node_data_unlock(id);
exit:
  return ret;
}


x86 assembly (clang, -O0):
<tree_node_cleanup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xfffffffd,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <node_data_lock@plt>
cmp    $0x0,%rax
je     1189 <tree_node_cleanup+0x29>
jmp    11dd <tree_node_cleanup+0x7d>
mov    -0x4(%rbp),%edi
call   1030 <node_write@plt>
cmp    $0x0,%rax
je     11a0 <tree_node_cleanup+0x40>
jmp    11d5 <tree_node_cleanup+0x75>
mov    -0x4(%rbp),%edi
call   1040 <node_is_used_rd@plt>
cmp    $0x0,%rax
je     11be <tree_node_cleanup+0x5e>
movl   $0xfffffffe,-0x8(%rbp)
jmp    11cd <tree_node_cleanup+0x6d>
mov    -0x4(%rbp),%edi
call   1070 <node_cleanup_fullwr@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <node_unlock@plt>
mov    -0x4(%rbp),%edi
call   1080 <node_data_unlock@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tree_node_cleanup>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
call   1050 <node_data_lock@plt>
mov    $0xfffffffd,%ebp
test   %rax,%rax
jne    11ad <tree_node_cleanup+0x4d>
mov    %ebx,%edi
call   1030 <node_write@plt>
mov    $0xfffffffd,%ebp
test   %rax,%rax
jne    11a6 <tree_node_cleanup+0x46>
mov    %ebx,%edi
call   1040 <node_is_used_rd@plt>
mov    $0xfffffffe,%ebp
test   %rax,%rax
jne    119f <tree_node_cleanup+0x3f>
mov    %ebx,%edi
call   1070 <node_cleanup_fullwr@plt>
xor    %ebp,%ebp
mov    %ebx,%edi
call   1060 <node_unlock@plt>
mov    %ebx,%edi
call   1080 <node_data_unlock@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @tree_node_cleanup(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 -3, i32* %3
%4 = load i32, i32* %2
%5 = call i64 @node_data_lock(i32 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
br label %27
8: ; preds = %1
%9 = load i32, i32* %2
%10 = call i64 @node_write(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
br label %24
13: ; preds = %8
%14 = load i32, i32* %2
%15 = call i64 @node_is_used_rd(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -2, i32* %3
br label %21
18: ; preds = %13
%19 = load i32, i32* %2
%20 = call i32 @node_cleanup_fullwr(i32 %19)
store i32 0, i32* %3
br label %21
21: ; preds = %18, %17
%22 = load i32, i32* %2
%23 = call i32 @node_unlock(i32 %22)
br label %24
24: ; preds = %21, %12
%25 = load i32, i32* %2
%26 = call i32 @node_data_unlock(i32 %25)
br label %27
27: ; preds = %24, %7
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @tree_node_cleanup(i32 %0) {
%2 = tail call i64 @node_data_lock(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %18
4: ; preds = %1
%5 = tail call i64 @node_write(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = tail call i64 @node_is_used_rd(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @node_cleanup_fullwr(i32 %0)
br label %12
12: ; preds = %7, %10
%13 = phi i32 [ 0, %10 ], [ -2, %7 ]
%14 = tail call i32 @node_unlock(i32 %0)
br label %15
15: ; preds = %4, %12
%16 = phi i32 [ -3, %4 ], [ %13, %12 ]
%17 = tail call i32 @node_data_unlock(i32 %0)
br label %18
18: ; preds = %1, %15
%19 = phi i32 [ -3, %1 ], [ %16, %15 ]
ret i32 %19
}