#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*/ sift_int(int *, int *, int /*<<< orphan*/, int const);
int /*<<< orphan*/ swap(int *, int, int /*<<< orphan*/);
void idx_hsort_int(int a[], int idx[], const int N) {
  int s = (N / 2) - 1, e = N - 1;
  while (s >= 0) {
    sift_int(a, idx, s--, N);
  }
  while (e > 0) {
    swap(idx, e, 0);
    sift_int(a, idx, 0, e--);
  }
}


x86 assembly (clang, -O0):
<idx_hsort_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1177 <idx_hsort_int+0x57>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    %edx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
call   1030 <sift_int@plt>
jmp    114d <idx_hsort_int+0x2d>
jmp    117c <idx_hsort_int+0x5c>
cmpl   $0x0,-0x1c(%rbp)
jle    11b3 <idx_hsort_int+0x93>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
xor    %edx,%edx
call   1040 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
mov    %ecx,%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
xor    %edx,%edx
call   1030 <sift_int@plt>
jmp    117c <idx_hsort_int+0x5c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<idx_hsort_int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edx
jl     1186 <idx_hsort_int+0x66>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%ebx
shr    %ebx
add    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%edx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%ecx
call   1030 <sift_int@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1140 <idx_hsort_int+0x20>
cmp    $0x2,%ebp
jl     1186 <idx_hsort_int+0x66>
add    $0x1,%ebp
lea    -0x2(%rbp),%ebx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1040 <swap@plt>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    %ebx,%ecx
call   1030 <sift_int@plt>
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
ja     1160 <idx_hsort_int+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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