#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*/ assert(int);
int /*<<< orphan*/ fvec_k_max_hoare(float const *, int, int *, int);
int /*<<< orphan*/ fvec_k_max_maxheap(float const *, int, int *, int);
void fvec_k_max(const float *val, int n, int *idx, int k) {
  assert(k <= n);
  if (n == 0 || k == 0)
    return;
  if (n > 4 * k)
    fvec_k_max_maxheap(val, n, idx, k);
  else
    fvec_k_max_hoare(val, n, idx, k);
}


x86 assembly (clang, -O0):
<fvec_k_max>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
je     116d <fvec_k_max+0x3d>
cmpl   $0x0,-0x1c(%rbp)
jne    1172 <fvec_k_max+0x42>
jmp    11ae <fvec_k_max+0x7e>
mov    -0xc(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x2,%ecx
cmp    %ecx,%eax
jle    119b <fvec_k_max+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1050 <fvec_k_max_maxheap@plt>
jmp    11ae <fvec_k_max+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <fvec_k_max_hoare@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fvec_k_max>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
xor    %edi,%edi
cmp    %esi,%ecx
setle  %dil
call   1030 <assert@plt>
test   %ebp,%ebp
je     117a <fvec_k_max+0x4a>
test   %ebx,%ebx
je     117a <fvec_k_max+0x4a>
lea    0x0(,%rbx,4),%eax
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %ebx,%ecx
add    $0x8,%rsp
cmp    %ebp,%eax
jge    1185 <fvec_k_max+0x55>
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fvec_k_max_maxheap@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fvec_k_max_hoare@plt>

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

LLVM IR (-O2):
define void @fvec_k_max(float* %0, i32 %1, i32* %2, i32 %3) {
%5 = icmp sle i32 %3, %1
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp eq i32 %1, 0
%9 = icmp eq i32 %3, 0
%10 = or i1 %8, %9
br i1 %10, label %18, label %11
11: ; preds = %4
%12 = shl nsw i32 %3, 2
%13 = icmp slt i32 %12, %1
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @fvec_k_max_maxheap(float* %0, i32 %1, i32* %2, i32 %3)
br label %18
16: ; preds = %11
%17 = tail call i32 @fvec_k_max_hoare(float* %0, i32 %1, i32* %2, i32 %3)
br label %18
18: ; preds = %4, %16, %14
ret void
}