#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*/ pq_downheap(int /*<<< orphan*/, int *, int);
int pq_remove(int *items, int *_size) {
  int item = items[0];
  int size = *_size;
  if (size > 1) {
    items[0] = items[size - 1];
    pq_downheap(0, items, size);
  }
  *_size = size - 1;
  return item;
}


x86 assembly (clang, -O0):
<pq_remove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jle    1160 <pq_remove+0x50>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
xor    %edi,%edi
call   1030 <pq_downheap@plt>
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pq_remove>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    (%rdi),%r14d
mov    (%rsi),%edx
lea    -0x1(%rdx),%ebp
cmp    $0x2,%edx
jl     1135 <pq_remove+0x25>
mov    %rdi,%rsi
mov    %ebp,%eax
mov    (%rdi,%rax,4),%eax
mov    %eax,(%rdi)
xor    %edi,%edi
call   1030 <pq_downheap@plt>
mov    %ebp,(%rbx)
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pq_remove(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %3
%8 = getelementptr inbounds i32, i32* %7, i64 0
%9 = load i32, i32* %8
store i32 %9, i32* %5
%10 = load i32*, i32** %4
%11 = load i32, i32* %10
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %26
14: ; preds = %2
%15 = load i32*, i32** %3
%16 = load i32, i32* %6
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %15, i64 %18
%20 = load i32, i32* %19
%21 = load i32*, i32** %3
%22 = getelementptr inbounds i32, i32* %21, i64 0
store i32 %20, i32* %22
%23 = load i32*, i32** %3
%24 = load i32, i32* %6
%25 = call i32 @pq_downheap(i32 0, i32* %23, i32 %24)
br label %26
26: ; preds = %14, %2
%27 = load i32, i32* %6
%28 = sub nsw i32 %27, 1
%29 = load i32*, i32** %4
store i32 %28, i32* %29
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
define i32 @pq_remove(i32* %0, i32* nocapture %1) {
%3 = load i32, i32* %0
%4 = load i32, i32* %1
%5 = icmp sgt i32 %4, 1
%6 = add nsw i32 %4, -1
br i1 %5, label %7, label %12
7: ; preds = %2
%8 = zext i32 %6 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
store i32 %10, i32* %0
%11 = tail call i32 @pq_downheap(i32 0, i32* %0, i32 %4)
br label %12
12: ; preds = %2, %7
store i32 %6, i32* %1
ret i32 %3
}