#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*/ siftdown(int *, int, int);
int extract_min(int *head, int *head_len) {
  int temp_len = *head_len;
  if (temp_len < 1) {
    return -1;
  }
  int res = head[1];
  head[1] = head[temp_len--];
  *head_len = temp_len;
  siftdown(head, *head_len, 1);
  return res;
}


x86 assembly (clang, -O0):
<extract_min>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    113f <extract_min+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <extract_min+0x78>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1030 <siftdown@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_min>:
push   %rbx
mov    (%rsi),%ecx
test   %ecx,%ecx
jle    1133 <extract_min+0x23>
mov    0x4(%rdi),%ebx
lea    -0x1(%rcx),%eax
mov    (%rdi,%rcx,4),%ecx
mov    %ecx,0x4(%rdi)
mov    %eax,(%rsi)
mov    %eax,%esi
mov    $0x1,%edx
call   1030 <siftdown@plt>
jmp    1138 <extract_min+0x28>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

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