#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 Pair {
  int dummy;
};
struct Node_list {
  int dummy;
};
struct NetBucket {
  int dummy;
};
struct List {
  int dummy;
};

/* Variables and functions */
struct List *NetBucket_get_pairs(struct NetBucket *);
scalar_t__ Pair_comp(struct Pair *, struct Pair *);
int /*<<< orphan*/ Pair_free(struct Pair *);
struct Node_list *get_first_node(struct List *);
struct Node_list *get_next_node(struct Node_list *);
struct Pair *get_node_val(struct Node_list *);
scalar_t__ is_valid_node(struct Node_list *);
int /*<<< orphan*/ lock_list(struct List *);
int /*<<< orphan*/ push_onTop(struct List *, struct Pair *);
int /*<<< orphan*/ unlock_list(struct List *);
struct Pair *NetBucket_set_pairs(struct NetBucket *nbucket, struct Pair *pair) {
  struct List *list = NetBucket_get_pairs(nbucket);
  lock_list(list);
  struct Node_list *tmp = get_first_node(list);
  while (is_valid_node(tmp)) {
    if (Pair_comp(get_node_val(tmp), pair)) {
      Pair_free(pair);
      pair = get_node_val(tmp);
      unlock_list(list);
      return pair;
    } else {
      tmp = get_next_node(tmp);
    }
  }
  unlock_list(list);
  push_onTop(list, pair);
  return pair;
}


x86 assembly (clang, -O0):
<NetBucket_set_pairs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <NetBucket_get_pairs@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <lock_list@plt>
mov    -0x20(%rbp),%rdi
call   1080 <get_first_node@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <is_valid_node@plt>
cmp    $0x0,%rax
je     1243 <NetBucket_set_pairs+0xa3>
mov    -0x28(%rbp),%rdi
call   10a0 <get_node_val@plt>
mov    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <Pair_comp@plt>
cmp    $0x0,%rax
je     1231 <NetBucket_set_pairs+0x91>
mov    -0x18(%rbp),%rdi
call   10c0 <Pair_free@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <get_node_val@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <unlock_list@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1261 <NetBucket_set_pairs+0xc1>
mov    -0x28(%rbp),%rdi
call   1070 <get_next_node@plt>
mov    %rax,-0x28(%rbp)
jmp    11d3 <NetBucket_set_pairs+0x33>
mov    -0x20(%rbp),%rdi
call   1030 <unlock_list@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <push_onTop@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NetBucket_set_pairs>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
call   1050 <NetBucket_get_pairs@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <lock_list@plt>
mov    %r14,%rdi
call   1080 <get_first_node@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <is_valid_node@plt>
test   %rax,%rax
je     11f2 <NetBucket_set_pairs+0x52>
mov    %rbx,%rdi
call   10a0 <get_node_val@plt>
mov    %rax,%rdi
mov    %r15,%rsi
call   10b0 <Pair_comp@plt>
test   %rax,%rax
jne    120a <NetBucket_set_pairs+0x6a>
mov    %rbx,%rdi
call   1070 <get_next_node@plt>
jmp    11c0 <NetBucket_set_pairs+0x20>
mov    %r14,%rdi
call   1030 <unlock_list@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <push_onTop@plt>
mov    %r15,%rax
jmp    1228 <NetBucket_set_pairs+0x88>
mov    %r15,%rdi
call   10c0 <Pair_free@plt>
mov    %rbx,%rdi
call   10a0 <get_node_val@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <unlock_list@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.NetBucket = type { i32 }
%struct.Pair = type { i32 }
%struct.List = type { i32 }
%struct.Node_list = type { i32 }
define %struct.Pair* @NetBucket_set_pairs(%struct.NetBucket* %0, %struct.Pair* %1) {
%3 = alloca %struct.Pair*
%4 = alloca %struct.NetBucket*
%5 = alloca %struct.Pair*
%6 = alloca %struct.List*
%7 = alloca %struct.Node_list*
store %struct.NetBucket* %0, %struct.NetBucket** %4
store %struct.Pair* %1, %struct.Pair** %5
%8 = load %struct.NetBucket*, %struct.NetBucket** %4
%9 = call %struct.List* @NetBucket_get_pairs(%struct.NetBucket* %8)
store %struct.List* %9, %struct.List** %6
%10 = load %struct.List*, %struct.List** %6
%11 = call i32 @lock_list(%struct.List* %10)
%12 = load %struct.List*, %struct.List** %6
%13 = call %struct.Node_list* @get_first_node(%struct.List* %12)
store %struct.Node_list* %13, %struct.Node_list** %7
br label %14
14: ; preds = %35, %2
%15 = load %struct.Node_list*, %struct.Node_list** %7
%16 = call i64 @is_valid_node(%struct.Node_list* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load %struct.Node_list*, %struct.Node_list** %7
%20 = call %struct.Pair* @get_node_val(%struct.Node_list* %19)
%21 = load %struct.Pair*, %struct.Pair** %5
%22 = call i64 @Pair_comp(%struct.Pair* %20, %struct.Pair* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %18
%25 = load %struct.Pair*, %struct.Pair** %5
%26 = call i32 @Pair_free(%struct.Pair* %25)
%27 = load %struct.Node_list*, %struct.Node_list** %7
%28 = call %struct.Pair* @get_node_val(%struct.Node_list* %27)
store %struct.Pair* %28, %struct.Pair** %5
%29 = load %struct.List*, %struct.List** %6
%30 = call i32 @unlock_list(%struct.List* %29)
%31 = load %struct.Pair*, %struct.Pair** %5
store %struct.Pair* %31, %struct.Pair** %3
br label %43
32: ; preds = %18
%33 = load %struct.Node_list*, %struct.Node_list** %7
%34 = call %struct.Node_list* @get_next_node(%struct.Node_list* %33)
store %struct.Node_list* %34, %struct.Node_list** %7
br label %35
35: ; preds = %32
br label %14
36: ; preds = %14
%37 = load %struct.List*, %struct.List** %6
%38 = call i32 @unlock_list(%struct.List* %37)
%39 = load %struct.List*, %struct.List** %6
%40 = load %struct.Pair*, %struct.Pair** %5
%41 = call i32 @push_onTop(%struct.List* %39, %struct.Pair* %40)
%42 = load %struct.Pair*, %struct.Pair** %5
store %struct.Pair* %42, %struct.Pair** %3
br label %43
43: ; preds = %36, %24
%44 = load %struct.Pair*, %struct.Pair** %3
ret %struct.Pair* %44
}

LLVM IR (-O2):
%struct.NetBucket = type { i32 }
%struct.Pair = type { i32 }
%struct.List = type { i32 }
%struct.Node_list = type { i32 }
define %struct.Pair* @NetBucket_set_pairs(%struct.NetBucket* %0, %struct.Pair* %1) {
%3 = tail call %struct.List* @NetBucket_get_pairs(%struct.NetBucket* %0)
%4 = tail call i32 @lock_list(%struct.List* %3)
%5 = tail call %struct.Node_list* @get_first_node(%struct.List* %3)
%6 = tail call i64 @is_valid_node(%struct.Node_list* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %2, %17
%9 = phi %struct.Node_list* [ %18, %17 ], [ %5, %2 ]
%10 = tail call %struct.Pair* @get_node_val(%struct.Node_list* %9)
%11 = tail call i64 @Pair_comp(%struct.Pair* %10, %struct.Pair* %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = tail call i32 @Pair_free(%struct.Pair* %1)
%15 = tail call %struct.Pair* @get_node_val(%struct.Node_list* %9)
%16 = tail call i32 @unlock_list(%struct.List* %3)
br label %24
17: ; preds = %8
%18 = tail call %struct.Node_list* @get_next_node(%struct.Node_list* %9)
%19 = tail call i64 @is_valid_node(%struct.Node_list* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %8
21: ; preds = %17, %2
%22 = tail call i32 @unlock_list(%struct.List* %3)
%23 = tail call i32 @push_onTop(%struct.List* %3, %struct.Pair* %1)
br label %24
24: ; preds = %21, %13
%25 = phi %struct.Pair* [ %15, %13 ], [ %1, %21 ]
ret %struct.Pair* %25
}