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


x86 assembly (clang, -O0):
<node_delete>:
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 <node_delete+0x29>
jmp    11d3 <node_delete+0x73>
mov    -0x4(%rbp),%edi
call   1030 <node_write@plt>
cmp    $0x0,%rax
je     11a8 <node_delete+0x48>
mov    -0x4(%rbp),%edi
call   1080 <node_data_unlock@plt>
jmp    11d3 <node_delete+0x73>
mov    -0x4(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <node_mark_unused_wr@plt>
mov    -0x4(%rbp),%edi
call   1070 <node_cleanup_fullwr@plt>
mov    -0x4(%rbp),%edi
call   1060 <node_unlock@plt>
mov    -0x4(%rbp),%edi
call   1080 <node_data_unlock@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<node_delete>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
call   1050 <node_data_lock@plt>
mov    $0xfffffffd,%r14d
test   %rax,%rax
jne    11a9 <node_delete+0x49>
mov    %ebx,%edi
call   1030 <node_write@plt>
mov    $0xfffffffd,%r14d
test   %rax,%rax
jne    11a2 <node_delete+0x42>
xor    %r14d,%r14d
xor    %edi,%edi
mov    %ebx,%esi
call   1040 <node_mark_unused_wr@plt>
mov    %ebx,%edi
call   1070 <node_cleanup_fullwr@plt>
mov    %ebx,%edi
call   1060 <node_unlock@plt>
mov    %ebx,%edi
call   1080 <node_data_unlock@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @node_delete(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 %24
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 %15
12: ; preds = %8
%13 = load i32, i32* %2
%14 = call i32 @node_data_unlock(i32 %13)
br label %24
15: ; preds = %8
%16 = load i32, i32* %2
%17 = call i32 @node_mark_unused_wr(i32* null, i32 %16)
%18 = load i32, i32* %2
%19 = call i32 @node_cleanup_fullwr(i32 %18)
%20 = load i32, i32* %2
%21 = call i32 @node_unlock(i32 %20)
%22 = load i32, i32* %2
%23 = call i32 @node_data_unlock(i32 %22)
store i32 0, i32* %3
br label %24
24: ; preds = %15, %12, %7
%25 = load i32, i32* %3
ret i32 %25
}

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