#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;
scalar_t__ rand();
long select_part(long ijk, long **ListOfPart, long *NPartPerCell) {
  long i_rnd, ipart;
  i_rnd = (long)(NPartPerCell[ijk] * ((double)rand() / (RAND_MAX + 1.0)));
  ipart = ListOfPart[ijk][i_rnd];
  return ipart;
}


x86 assembly (clang, -O0):
<select_part>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
cvtsi2sdq (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
movsd  0xeb0(%rip),%xmm2
mov    0x2e91(%rip),%rax
addsd  (%rax),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_part>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
cvtsi2sdq (%rdx,%rdi,8),%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2ead(%rip),%rax
movsd  (%rax),%xmm1
addsd  0xeb9(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%rax
mov    (%r14,%rbx,8),%rcx
mov    (%rcx,%rax,8),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define i64 @select_part(i64 %0, i64** %1, i64* %2) {
%4 = alloca i64
%5 = alloca i64**
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i64
store i64 %0, i64* %4
store i64** %1, i64*** %5
store i64* %2, i64** %6
%9 = load i64*, i64** %6
%10 = load i64, i64* %4
%11 = getelementptr inbounds i64, i64* %9, i64 %10
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to double
%14 = call i64 (...) @rand()
%15 = sitofp i64 %14 to double
%16 = load double, double* @RAND_MAX
%17 = fadd double %16, 1.000000e+00
%18 = fdiv double %15, %17
%19 = fmul double %13, %18
%20 = fptosi double %19 to i64
store i64 %20, i64* %7
%21 = load i64**, i64*** %5
%22 = load i64, i64* %4
%23 = getelementptr inbounds i64*, i64** %21, i64 %22
%24 = load i64*, i64** %23
%25 = load i64, i64* %7
%26 = getelementptr inbounds i64, i64* %24, i64 %25
%27 = load i64, i64* %26
store i64 %27, i64* %8
%28 = load i64, i64* %8
ret i64 %28
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define i64 @select_part(i64 %0, i64** nocapture %1, i64* nocapture %2) {
%4 = getelementptr inbounds i64, i64* %2, i64 %0
%5 = load i64, i64* %4
%6 = sitofp i64 %5 to double
%7 = tail call i64 (...) @rand()
%8 = sitofp i64 %7 to double
%9 = load double, double* @RAND_MAX
%10 = fadd double %9, 1.000000e+00
%11 = fdiv double %8, %10
%12 = fmul double %11, %6
%13 = fptosi double %12 to i64
%14 = getelementptr inbounds i64*, i64** %1, i64 %0
%15 = load i64*, i64** %14
%16 = getelementptr inbounds i64, i64* %15, i64 %13
%17 = load i64, i64* %16
ret i64 %17
}