#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*/ min_heapify(int *, int *, int, int);
int /*<<< orphan*/ swap_pos(int *, int /*<<< orphan*/, int);
void row_sort(int *row_len, int *reorder_map, int rows) {
  int i;
  for (i = (rows - 2) >> 1; i >= 0; i--) {
    min_heapify(row_len, reorder_map, rows, i);
  }
  for (i = rows - 1; i > 0; i--) {
    swap_pos(row_len, 0, i);
    swap_pos(reorder_map, 0, i);
    min_heapify(row_len, reorder_map, i, 0);
  }
}


x86 assembly (clang, -O0):
<row_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
sar    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     116a <row_sort+0x4a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <min_heapify@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    113f <row_sort+0x1f>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11b9 <row_sort+0x99>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1030 <swap_pos@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1030 <swap_pos@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
xor    %ecx,%ecx
call   1040 <min_heapify@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1173 <row_sort+0x53>
add    $0x20,%rsp
pop    %rbp
ret

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

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

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