#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*/ seep(int, int, int *);
int /*<<< orphan*/ swap(int, int /*<<< orphan*/, int *);
void heapsort(int *x, int len) {
  int start = (len - 2) / 2;
  int end = len - 1;
  while (start >= 0) {
    seep(start, end, x);
    start -= 1;
  }
  while (end > 0) {
    swap(end, 0, x);
    end -= 1;
    seep(0, end, x);
  }
}


x86 assembly (clang, -O0):
<heapsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1170 <heapsort+0x50>
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rdx
call   1030 <seep@plt>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1149 <heapsort+0x29>
jmp    1175 <heapsort+0x55>
cmpl   $0x0,-0x14(%rbp)
jle    11a9 <heapsort+0x89>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rdx
xor    %esi,%esi
call   1040 <swap@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rdx
xor    %edi,%edi
call   1030 <seep@plt>
jmp    1175 <heapsort+0x55>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapsort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1192 <heapsort+0x72>
mov    %esi,%r15d
mov    %rdi,%r14
lea    -0x1(%r15),%ebx
lea    -0x2(%r15),%eax
shr    $0x1f,%eax
lea    (%r15,%rax,1),%ebp
add    $0xfffffffe,%ebp
sar    %ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <seep@plt>
add    $0xffffffff,%ebp
jb     1150 <heapsort+0x30>
cmp    $0x2,%r15d
jl     1192 <heapsort+0x72>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <swap@plt>
lea    -0x1(%rbx),%ebp
xor    %edi,%edi
mov    %ebp,%esi
mov    %r14,%rdx
call   1030 <seep@plt>
cmp    $0x1,%ebx
mov    %ebp,%ebx
ja     1170 <heapsort+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @heapsort(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* %4
%8 = sub nsw i32 %7, 2
%9 = sdiv i32 %8, 2
store i32 %9, i32* %5
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %6
br label %12
12: ; preds = %15, %2
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = load i32*, i32** %3
%19 = call i32 @seep(i32 %16, i32 %17, i32* %18)
%20 = load i32, i32* %5
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %5
br label %12
22: ; preds = %12
br label %23
23: ; preds = %26, %22
%24 = load i32, i32* %6
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* %6
%28 = load i32*, i32** %3
%29 = call i32 @swap(i32 %27, i32 0, i32* %28)
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = load i32*, i32** %3
%34 = call i32 @seep(i32 0, i32 %32, i32* %33)
br label %23
35: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @heapsort(i32* %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %21
5: ; preds = %2
%6 = add nsw i32 %1, -2
%7 = sdiv i32 %6, 2
br label %10
8: ; preds = %10
%9 = icmp sgt i32 %1, 1
br i1 %9, label %15, label %21
10: ; preds = %5, %10
%11 = phi i32 [ %13, %10 ], [ %7, %5 ]
%12 = tail call i32 @seep(i32 %11, i32 %3, i32* %0)
%13 = add nsw i32 %11, -1
%14 = icmp eq i32 %11, 0
br i1 %14, label %8, label %10
15: ; preds = %8, %15
%16 = phi i32 [ %18, %15 ], [ %3, %8 ]
%17 = tail call i32 @swap(i32 %16, i32 0, i32* %0)
%18 = add nsw i32 %16, -1
%19 = tail call i32 @seep(i32 0, i32 %18, i32* %0)
%20 = icmp ugt i32 %16, 1
br i1 %20, label %15, label %21
21: ; preds = %15, %2, %8
ret void
}