#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 */
scalar_t__ RAND_MAX;
int /*<<< orphan*/ exchange_member(int *, int, int);
scalar_t__ rand();
scalar_t__ round(double);
void choose_pivot(int *arr, int start, int end) {
  int random_pos = start + (int)round((double)(end - start) * (double)rand() /
                                      (double)RAND_MAX);
  exchange_member(arr, start, random_pos);
  return;
}


x86 assembly (clang, -O0):
<choose_pivot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
movsd  -0x20(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
mov    0x2e75(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
call   1040 <round@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <exchange_member@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<choose_pivot>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
sub    %esi,%edx
cvtsi2sd %edx,%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mulsd  (%rsp),%xmm0
mov    0x2e89(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
call   1040 <round@plt>
lea    (%rax,%rbx,1),%edx
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <exchange_member@plt>

LLVM IR (-O0):
@RAND_MAX = global i64 0
define void @choose_pivot(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* %5
%9 = load i32, i32* %6
%10 = load i32, i32* %5
%11 = sub nsw i32 %9, %10
%12 = sitofp i32 %11 to double
%13 = call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = fmul double %12, %14
%16 = load i64, i64* @RAND_MAX
%17 = sitofp i64 %16 to double
%18 = fdiv double %15, %17
%19 = call i64 @round(double %18)
%20 = trunc i64 %19 to i32
%21 = add nsw i32 %8, %20
store i32 %21, i32* %7
%22 = load i32*, i32** %4
%23 = load i32, i32* %5
%24 = load i32, i32* %7
%25 = call i32 @exchange_member(i32* %22, i32 %23, i32 %24)
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define void @choose_pivot(i32* %0, i32 %1, i32 %2) {
%4 = sub nsw i32 %2, %1
%5 = sitofp i32 %4 to double
%6 = tail call i64 (...) @rand()
%7 = sitofp i64 %6 to double
%8 = fmul double %5, %7
%9 = load i64, i64* @RAND_MAX
%10 = sitofp i64 %9 to double
%11 = fdiv double %8, %10
%12 = tail call i64 @round(double %11)
%13 = trunc i64 %12 to i32
%14 = add nsw i32 %13, %1
%15 = tail call i32 @exchange_member(i32* %0, i32 %1, i32 %14)
ret void
}