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

/* Variables and functions */
int /*<<< orphan*/ _adjustHeap(struct DynArr *, int, int /*<<< orphan*/);
int /*<<< orphan*/ getDynArr(struct DynArr *, int);
int /*<<< orphan*/ putDynArr(struct DynArr *, int /*<<< orphan*/,
                             int /*<<< orphan*/);
int /*<<< orphan*/ removeAtDynArr(struct DynArr *, int);
int sizeDynArr(struct DynArr *);
void HeapRemoveFirst(struct DynArr *heap) {
  int last = sizeDynArr(heap) - 1;
  if (last > 0) {
    putDynArr(heap, 0, getDynArr(heap, last));
    removeAtDynArr(heap, last);
    _adjustHeap(heap, last, 0);
  } else {
    removeAtDynArr(heap, last);
  }
}


x86 assembly (clang, -O0):
<HeapRemoveFirst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <sizeDynArr@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11b5 <HeapRemoveFirst+0x65>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <getDynArr@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1030 <putDynArr@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <removeAtDynArr@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
xor    %edx,%edx
call   1050 <_adjustHeap@plt>
jmp    11c1 <HeapRemoveFirst+0x71>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <removeAtDynArr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HeapRemoveFirst>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <sizeDynArr@plt>
lea    -0x1(%rax),%ebp
cmp    $0x2,%eax
jl     1195 <HeapRemoveFirst+0x45>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <getDynArr@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1030 <putDynArr@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <removeAtDynArr@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <_adjustHeap@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <removeAtDynArr@plt>

LLVM IR (-O0):
%struct.DynArr = type { i32 }
define void @HeapRemoveFirst(%struct.DynArr* %0) {
%2 = alloca %struct.DynArr*
%3 = alloca i32
store %struct.DynArr* %0, %struct.DynArr** %2
%4 = load %struct.DynArr*, %struct.DynArr** %2
%5 = call i32 @sizeDynArr(%struct.DynArr* %4)
%6 = sub nsw i32 %5, 1
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %1
%10 = load %struct.DynArr*, %struct.DynArr** %2
%11 = load %struct.DynArr*, %struct.DynArr** %2
%12 = load i32, i32* %3
%13 = call i32 @getDynArr(%struct.DynArr* %11, i32 %12)
%14 = call i32 @putDynArr(%struct.DynArr* %10, i32 0, i32 %13)
%15 = load %struct.DynArr*, %struct.DynArr** %2
%16 = load i32, i32* %3
%17 = call i32 @removeAtDynArr(%struct.DynArr* %15, i32 %16)
%18 = load %struct.DynArr*, %struct.DynArr** %2
%19 = load i32, i32* %3
%20 = call i32 @_adjustHeap(%struct.DynArr* %18, i32 %19, i32 0)
br label %25
21: ; preds = %1
%22 = load %struct.DynArr*, %struct.DynArr** %2
%23 = load i32, i32* %3
%24 = call i32 @removeAtDynArr(%struct.DynArr* %22, i32 %23)
br label %25
25: ; preds = %21, %9
ret void
}

LLVM IR (-O2):
%struct.DynArr = type { i32 }
define void @HeapRemoveFirst(%struct.DynArr* %0) {
%2 = tail call i32 @sizeDynArr(%struct.DynArr* %0)
%3 = add nsw i32 %2, -1
%4 = icmp sgt i32 %2, 1
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %3)
%7 = tail call i32 @putDynArr(%struct.DynArr* %0, i32 0, i32 %6)
%8 = tail call i32 @removeAtDynArr(%struct.DynArr* %0, i32 %3)
%9 = tail call i32 @_adjustHeap(%struct.DynArr* %0, i32 %3, i32 0)
br label %12
10: ; preds = %1
%11 = tail call i32 @removeAtDynArr(%struct.DynArr* %0, i32 %3)
br label %12
12: ; preds = %10, %5
ret void
}