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

/* Variables and functions */
int /*<<< orphan*/ _gheap_pop_max_item(struct gheap_ctx const *const,
                                       void *const, size_t const);
int /*<<< orphan*/ assert(int);
int gheap_is_heap(struct gheap_ctx const *const, void *const, size_t const);
void gheap_pop_heap(const struct gheap_ctx *const ctx, void *const base,
                    const size_t heap_size) {
  assert(heap_size > 0);
  assert(gheap_is_heap(ctx, base, heap_size));
  if (heap_size > 1) {
    _gheap_pop_max_item(ctx, base, heap_size - 1);
  }
  assert(gheap_is_heap(ctx, base, heap_size - 1));
}


x86 assembly (clang, -O0):
<gheap_pop_heap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <gheap_is_heap@plt>
mov    %eax,%edi
call   1030 <assert@plt>
cmpq   $0x1,-0x18(%rbp)
jbe    118e <gheap_pop_heap+0x5e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <_gheap_pop_max_item@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
call   1050 <gheap_is_heap@plt>
mov    %eax,%edi
call   1030 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gheap_pop_heap>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
mov    %rdx,%r12
add    $0xffffffffffffffff,%r12
setb   %dil
call   1030 <assert@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <gheap_is_heap@plt>
mov    %eax,%edi
call   1030 <assert@plt>
cmp    $0x2,%rbx
jb     117c <gheap_pop_heap+0x4c>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <_gheap_pop_max_item@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <gheap_is_heap@plt>
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <assert@plt>

LLVM IR (-O0):
%struct.gheap_ctx = type { i32 }
define void @gheap_pop_heap(%struct.gheap_ctx* %0, i8* %1, i64 %2) {
%4 = alloca %struct.gheap_ctx*
%5 = alloca i8*
%6 = alloca i64
store %struct.gheap_ctx* %0, %struct.gheap_ctx** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%7 = load i64, i64* %6
%8 = icmp ugt i64 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load %struct.gheap_ctx*, %struct.gheap_ctx** %4
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = call i32 @gheap_is_heap(%struct.gheap_ctx* %11, i8* %12, i64 %13)
%15 = call i32 @assert(i32 %14)
%16 = load i64, i64* %6
%17 = icmp ugt i64 %16, 1
br i1 %17, label %18, label %24
18: ; preds = %3
%19 = load %struct.gheap_ctx*, %struct.gheap_ctx** %4
%20 = load i8*, i8** %5
%21 = load i64, i64* %6
%22 = sub i64 %21, 1
%23 = call i32 @_gheap_pop_max_item(%struct.gheap_ctx* %19, i8* %20, i64 %22)
br label %24
24: ; preds = %18, %3
%25 = load %struct.gheap_ctx*, %struct.gheap_ctx** %4
%26 = load i8*, i8** %5
%27 = load i64, i64* %6
%28 = sub i64 %27, 1
%29 = call i32 @gheap_is_heap(%struct.gheap_ctx* %25, i8* %26, i64 %28)
%30 = call i32 @assert(i32 %29)
ret void
}

LLVM IR (-O2):
%struct.gheap_ctx = type { i32 }
define void @gheap_pop_heap(%struct.gheap_ctx* %0, i8* %1, i64 %2) {
%4 = icmp ne i64 %2, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 @gheap_is_heap(%struct.gheap_ctx* %0, i8* %1, i64 %2)
%8 = tail call i32 @assert(i32 %7)
%9 = icmp ugt i64 %2, 1
%10 = add i64 %2, -1
br i1 %9, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @_gheap_pop_max_item(%struct.gheap_ctx* %0, i8* %1, i64 %10)
br label %13
13: ; preds = %3, %11
%14 = tail call i32 @gheap_is_heap(%struct.gheap_ctx* %0, i8* %1, i64 %10)
%15 = tail call i32 @assert(i32 %14)
ret void
}