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

/* Variables and functions */
int /*<<< orphan*/ prioq__lock(struct prioq *);
int /*<<< orphan*/ prioq__unlock(struct prioq *);
int /*<<< orphan*/ prioq_clear(struct prioq *);
int prioq_copy(struct prioq *, struct prioq *);
int prioq_move(struct prioq *dst, struct prioq *src) {
  int rc;
  prioq__lock(dst);
  prioq__lock(src);
  rc = prioq_copy(dst, src);
  if (rc < 0)
    goto done;
  prioq_clear(src);
  rc = 0;
done:
  prioq__unlock(src);
  prioq__unlock(dst);
  return rc;
}


x86 assembly (clang, -O0):
<prioq_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <prioq__lock@plt>
mov    -0x10(%rbp),%rdi
call   1040 <prioq__lock@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <prioq_copy@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1181 <prioq_move+0x41>
jmp    1191 <prioq_move+0x51>
mov    -0x10(%rbp),%rdi
call   1030 <prioq_clear@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <prioq__unlock@plt>
mov    -0x8(%rbp),%rdi
call   1050 <prioq__unlock@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prioq_move>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <prioq__lock@plt>
mov    %rbx,%rdi
call   1040 <prioq__lock@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <prioq_copy@plt>
test   %eax,%eax
js     1172 <prioq_move+0x32>
mov    %rbx,%rdi
call   1030 <prioq_clear@plt>
xor    %ebp,%ebp
jmp    1174 <prioq_move+0x34>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <prioq__unlock@plt>
mov    %r14,%rdi
call   1050 <prioq__unlock@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.prioq = type { i32 }
define i32 @prioq_move(%struct.prioq* %0, %struct.prioq* %1) {
%3 = alloca %struct.prioq*
%4 = alloca %struct.prioq*
%5 = alloca i32
store %struct.prioq* %0, %struct.prioq** %3
store %struct.prioq* %1, %struct.prioq** %4
%6 = load %struct.prioq*, %struct.prioq** %3
%7 = call i32 @prioq__lock(%struct.prioq* %6)
%8 = load %struct.prioq*, %struct.prioq** %4
%9 = call i32 @prioq__lock(%struct.prioq* %8)
%10 = load %struct.prioq*, %struct.prioq** %3
%11 = load %struct.prioq*, %struct.prioq** %4
%12 = call i32 @prioq_copy(%struct.prioq* %10, %struct.prioq* %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
br label %19
16: ; preds = %2
%17 = load %struct.prioq*, %struct.prioq** %4
%18 = call i32 @prioq_clear(%struct.prioq* %17)
store i32 0, i32* %5
br label %19
19: ; preds = %16, %15
%20 = load %struct.prioq*, %struct.prioq** %4
%21 = call i32 @prioq__unlock(%struct.prioq* %20)
%22 = load %struct.prioq*, %struct.prioq** %3
%23 = call i32 @prioq__unlock(%struct.prioq* %22)
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
%struct.prioq = type { i32 }
define i32 @prioq_move(%struct.prioq* %0, %struct.prioq* %1) {
%3 = tail call i32 @prioq__lock(%struct.prioq* %0)
%4 = tail call i32 @prioq__lock(%struct.prioq* %1)
%5 = tail call i32 @prioq_copy(%struct.prioq* %0, %struct.prioq* %1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 @prioq_clear(%struct.prioq* %1)
br label %9
9: ; preds = %2, %7
%10 = phi i32 [ %5, %2 ], [ 0, %7 ]
%11 = tail call i32 @prioq__unlock(%struct.prioq* %1)
%12 = tail call i32 @prioq__unlock(%struct.prioq* %0)
ret i32 %10
}