#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*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(double *, double *, int);
double qs_select(double *, int /*<<< orphan*/, size_t, size_t);
double quickselect(double *a, size_t n, size_t kth) {
  double *list, v;
  list = (double *)malloc(sizeof(double) * n);
  memcpy(list, a, sizeof(double) * n);
  v = qs_select(list, 0, n - 1, kth);
  free(list);
  return v;
}


x86 assembly (clang, -O0):
<quickselect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
mov    -0x18(%rbp),%rcx
xor    %esi,%esi
call   1060 <qs_select@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quickselect>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x0(,%rsi,8),%r12d
mov    %r12d,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
add    $0xffffffffffffffff,%rbx
mov    %rbp,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1060 <qs_select@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbp,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @quickselect(double* %0, i64 %1, i64 %2) {
%4 = alloca double*
%5 = alloca i64
%6 = alloca i64
%7 = alloca double*
%8 = alloca double
store double* %0, double** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i64, i64* %5
%10 = mul i64 8, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to double*
store double* %13, double** %7
%14 = load double*, double** %7
%15 = load double*, double** %4
%16 = load i64, i64* %5
%17 = mul i64 8, %16
%18 = trunc i64 %17 to i32
%19 = call i32 @memcpy(double* %14, double* %15, i32 %18)
%20 = load double*, double** %7
%21 = load i64, i64* %5
%22 = sub i64 %21, 1
%23 = load i64, i64* %6
%24 = call double @qs_select(double* %20, i32 0, i64 %22, i64 %23)
store double %24, double* %8
%25 = load double*, double** %7
%26 = call i32 @free(double* %25)
%27 = load double, double* %8
ret double %27
}

LLVM IR (-O2):
define double @quickselect(double* %0, i64 %1, i64 %2) {
%4 = trunc i64 %1 to i32
%5 = shl i32 %4, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to double*
%8 = tail call i32 @memcpy(double* %7, double* %0, i32 %5)
%9 = add i64 %1, -1
%10 = tail call double @qs_select(double* %7, i32 0, i64 %9, i64 %2)
%11 = tail call i32 @free(double* %7)
ret double %10
}