#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_trylock(int const);
int /*<<< orphan*/ node_data_unlock(int const);
int node_is_used_rd(int const);
scalar_t__ node_read(int const);
int /*<<< orphan*/ node_unlock(int const);
scalar_t__ node_write(int const);
int node_cleanup(const int id) {
  int is_used, ret = 1;
  if (node_read(id) != 0)
    goto exit;
  is_used = node_is_used_rd(id);
  node_unlock(id);
  if (is_used)
    goto exit;
  if (node_data_trylock(id) != 0)
    goto exit;
  if (node_write(id) != 0)
    goto unlock_data;
  if (node_is_used_rd(id))
    goto unlock_node;
  node_cleanup_fullwr(id);
  ret = 0;
unlock_node:
  node_unlock(id);
unlock_data:
  node_data_unlock(id);
exit:
  return ret;
}


x86 assembly (clang, -O0):
<node_cleanup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <node_read@plt>
cmp    $0x0,%rax
je     1199 <node_cleanup+0x29>
jmp    121e <node_cleanup+0xae>
mov    -0x4(%rbp),%edi
call   1040 <node_is_used_rd@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <node_unlock@plt>
cmpl   $0x0,-0x8(%rbp)
je     11bb <node_cleanup+0x4b>
jmp    121e <node_cleanup+0xae>
mov    -0x4(%rbp),%edi
call   1090 <node_data_trylock@plt>
cmp    $0x0,%rax
je     11d2 <node_cleanup+0x62>
jmp    121e <node_cleanup+0xae>
mov    -0x4(%rbp),%edi
call   1030 <node_write@plt>
cmp    $0x0,%rax
je     11e9 <node_cleanup+0x79>
jmp    1216 <node_cleanup+0xa6>
mov    -0x4(%rbp),%edi
call   1040 <node_is_used_rd@plt>
cmp    $0x0,%eax
je     11ff <node_cleanup+0x8f>
jmp    120e <node_cleanup+0x9e>
mov    -0x4(%rbp),%edi
call   1070 <node_cleanup_fullwr@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <node_unlock@plt>
mov    -0x4(%rbp),%edi
call   1080 <node_data_unlock@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<node_cleanup>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
call   1060 <node_read@plt>
mov    $0x1,%r14d
test   %rax,%rax
jne    11e1 <node_cleanup+0x71>
mov    %ebx,%edi
call   1040 <node_is_used_rd@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <node_unlock@plt>
test   %ebp,%ebp
jne    11e1 <node_cleanup+0x71>
mov    %ebx,%edi
call   1090 <node_data_trylock@plt>
test   %rax,%rax
jne    11e1 <node_cleanup+0x71>
mov    %ebx,%edi
call   1030 <node_write@plt>
mov    $0x1,%r14d
test   %rax,%rax
jne    11da <node_cleanup+0x6a>
mov    %ebx,%edi
call   1040 <node_is_used_rd@plt>
mov    $0x1,%r14d
test   %eax,%eax
jne    11d3 <node_cleanup+0x63>
mov    %ebx,%edi
call   1070 <node_cleanup_fullwr@plt>
xor    %r14d,%r14d
mov    %ebx,%edi
call   1050 <node_unlock@plt>
mov    %ebx,%edi
call   1080 <node_data_unlock@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @node_cleanup(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %4
%5 = load i32, i32* %2
%6 = call i64 @node_read(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
br label %41
9: ; preds = %1
%10 = load i32, i32* %2
%11 = call i32 @node_is_used_rd(i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %2
%13 = call i32 @node_unlock(i32 %12)
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %9
br label %41
17: ; preds = %9
%18 = load i32, i32* %2
%19 = call i64 @node_data_trylock(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
br label %41
22: ; preds = %17
%23 = load i32, i32* %2
%24 = call i64 @node_write(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
br label %38
27: ; preds = %22
%28 = load i32, i32* %2
%29 = call i32 @node_is_used_rd(i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
br label %35
32: ; preds = %27
%33 = load i32, i32* %2
%34 = call i32 @node_cleanup_fullwr(i32 %33)
store i32 0, i32* %4
br label %35
35: ; preds = %32, %31
%36 = load i32, i32* %2
%37 = call i32 @node_unlock(i32 %36)
br label %38
38: ; preds = %35, %26
%39 = load i32, i32* %2
%40 = call i32 @node_data_unlock(i32 %39)
br label %41
41: ; preds = %38, %21, %16, %8
%42 = load i32, i32* %4
ret i32 %42
}

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