#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 */
double RAND_MAX;
double rand();
int /*<<< orphan*/ swap(double *, int, int);
int partition(double lyst[], int lo, int hi) {
  int b = lo;
  int r = (int)(lo + (hi - lo) * (1.0 * rand() / RAND_MAX));
  double pivot = lyst[r];
  swap(lyst, r, hi);
  for (int i = lo; i < hi; i++) {
    if (lyst[i] < pivot) {
      swap(lyst, i, b);
      b++;
    }
  }
  swap(lyst, hi, b);
  return b;
}


x86 assembly (clang, -O0):
<partition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x30(%rbp),%xmm0
movsd  0xe93(%rip),%xmm2
mulsd  %xmm3,%xmm2
mov    0x2e70(%rip),%rax
divsd  (%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <swap@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1205 <partition+0xe5>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11f2 <partition+0xd2>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f7 <partition+0xd7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b2 <partition+0x92>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<partition>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
cvtsi2sd %esi,%xmm0
movsd  %xmm0,(%rsp)
mov    %edx,%r15d
mov    %rdi,%r14
mov    %edx,%eax
sub    %esi,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <rand@plt>
mov    0x2e8c(%rip),%rax
divsd  (%rax),%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
cvttsd2si %xmm0,%eax
movslq %eax,%rsi
movsd  (%r14,%rsi,8),%xmm0
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
mov    %r15d,%edx
call   1030 <swap@plt>
cmp    %ebp,%r15d
jle    11ca <partition+0xaa>
movslq %ebp,%rax
lea    (%r14,%rax,8),%rbx
mov    %ebp,%r12d
jmp    11ac <partition+0x8c>
nopl   0x0(%rax)
add    $0x1,%ebp
add    $0x8,%rbx
cmp    %ebp,%r15d
je     11cd <partition+0xad>
movsd  (%rsp),%xmm0
ucomisd (%rbx),%xmm0
jbe    11a0 <partition+0x80>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
call   1030 <swap@plt>
add    $0x1,%r12d
jmp    11a0 <partition+0x80>
mov    %ebp,%r12d
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
call   1030 <swap@plt>
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define i32 @partition(double* %0, i32 %1, i32 %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
store double* %0, double** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
store i32 %11, i32* %7
%12 = load i32, i32* %5
%13 = sitofp i32 %12 to double
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = sub nsw i32 %14, %15
%17 = sitofp i32 %16 to double
%18 = call double (...) @rand()
%19 = fmul double 1.000000e+00, %18
%20 = load double, double* @RAND_MAX
%21 = fdiv double %19, %20
%22 = call double @llvm.fmuladd.f64(double %17, double %21, double %13)
%23 = fptosi double %22 to i32
store i32 %23, i32* %8
%24 = load double*, double** %4
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double, double* %27
store double %28, double* %9
%29 = load double*, double** %4
%30 = load i32, i32* %8
%31 = load i32, i32* %6
%32 = call i32 @swap(double* %29, i32 %30, i32 %31)
%33 = load i32, i32* %5
store i32 %33, i32* %10
br label %34
34: ; preds = %54, %3
%35 = load i32, i32* %10
%36 = load i32, i32* %6
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %57
38: ; preds = %34
%39 = load double*, double** %4
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = load double, double* %9
%45 = fcmp olt double %43, %44
br i1 %45, label %46, label %53
46: ; preds = %38
%47 = load double*, double** %4
%48 = load i32, i32* %10
%49 = load i32, i32* %7
%50 = call i32 @swap(double* %47, i32 %48, i32 %49)
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %53
53: ; preds = %46, %38
br label %54
54: ; preds = %53
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %34
57: ; preds = %34
%58 = load double*, double** %4
%59 = load i32, i32* %6
%60 = load i32, i32* %7
%61 = call i32 @swap(double* %58, i32 %59, i32 %60)
%62 = load i32, i32* %7
ret i32 %62
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define i32 @partition(double* %0, i32 %1, i32 %2) {
%4 = sitofp i32 %1 to double
%5 = sub nsw i32 %2, %1
%6 = sitofp i32 %5 to double
%7 = tail call double (...) @rand()
%8 = load double, double* @RAND_MAX
%9 = fdiv double %7, %8
%10 = tail call double @llvm.fmuladd.f64(double %6, double %9, double %4)
%11 = fptosi double %10 to i32
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds double, double* %0, i64 %12
%14 = load double, double* %13
%15 = tail call i32 @swap(double* %0, i32 %11, i32 %2)
%16 = icmp sgt i32 %2, %1
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = sext i32 %1 to i64
br label %22
19: ; preds = %32, %3
%20 = phi i32 [ %1, %3 ], [ %33, %32 ]
%21 = tail call i32 @swap(double* %0, i32 %2, i32 %20)
ret i32 %20
22: ; preds = %17, %32
%23 = phi i64 [ %18, %17 ], [ %34, %32 ]
%24 = phi i32 [ %1, %17 ], [ %33, %32 ]
%25 = getelementptr inbounds double, double* %0, i64 %23
%26 = load double, double* %25
%27 = fcmp olt double %26, %14
br i1 %27, label %28, label %32
28: ; preds = %22
%29 = trunc i64 %23 to i32
%30 = tail call i32 @swap(double* %0, i32 %29, i32 %24)
%31 = add nsw i32 %24, 1
br label %32
32: ; preds = %22, %28
%33 = phi i32 [ %31, %28 ], [ %24, %22 ]
%34 = add nsw i64 %23, 1
%35 = trunc i64 %34 to i32
%36 = icmp eq i32 %35, %2
br i1 %36, label %19, label %22
}