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


x86 assembly (clang, -O0):
<select_part_beta_0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1144 <select_part_beta_0+0x34>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11ac <select_part_beta_0+0x9c>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cvtsi2sdq (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
movsd  0xe90(%rip),%xmm2
mov    0x2e71(%rip),%rax
addsd  (%rax),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<select_part_beta_0>:
push   %r14
push   %rbx
push   %rax
mov    (%rdx,%rdi,8),%rax
test   %rax,%rax
je     1167 <select_part_beta_0+0x57>
mov    %rsi,%r14
mov    %rdi,%rbx
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2ea5(%rip),%rax
movsd  (%rax),%xmm1
addsd  0xeb1(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  (%rsp),%xmm0
cvttsd2si %xmm0,%rax
mov    (%r14,%rbx,8),%rcx
mov    (%rcx,%rax,8),%rax
jmp    116e <select_part_beta_0+0x5e>
mov    $0xffffffffffffffff,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define i64 @select_part_beta_0(i64 %0, i64** %1, i64* %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64**
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i64
store i64 %0, i64* %5
store i64** %1, i64*** %6
store i64* %2, i64** %7
%10 = load i64*, i64** %7
%11 = load i64, i64* %5
%12 = getelementptr inbounds i64, i64* %10, i64 %11
%13 = load i64, i64* %12
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
store i64 -1, i64* %4
br label %37
16: ; preds = %3
%17 = load i64*, i64** %7
%18 = load i64, i64* %5
%19 = getelementptr inbounds i64, i64* %17, i64 %18
%20 = load i64, i64* %19
%21 = sitofp i64 %20 to double
%22 = call i64 (...) @rand()
%23 = sitofp i64 %22 to double
%24 = load double, double* @RAND_MAX
%25 = fadd double %24, 1.000000e+00
%26 = fdiv double %23, %25
%27 = fmul double %21, %26
%28 = fptosi double %27 to i64
store i64 %28, i64* %8
%29 = load i64**, i64*** %6
%30 = load i64, i64* %5
%31 = getelementptr inbounds i64*, i64** %29, i64 %30
%32 = load i64*, i64** %31
%33 = load i64, i64* %8
%34 = getelementptr inbounds i64, i64* %32, i64 %33
%35 = load i64, i64* %34
store i64 %35, i64* %9
%36 = load i64, i64* %9
store i64 %36, i64* %4
br label %37
37: ; preds = %16, %15
%38 = load i64, i64* %4
ret i64 %38
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define i64 @select_part_beta_0(i64 %0, i64** nocapture %1, i64* nocapture %2) {
%4 = getelementptr inbounds i64, i64* %2, i64 %0
%5 = load i64, i64* %4
%6 = icmp eq i64 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %3
%8 = sitofp i64 %5 to double
%9 = tail call i64 (...) @rand()
%10 = sitofp i64 %9 to double
%11 = load double, double* @RAND_MAX
%12 = fadd double %11, 1.000000e+00
%13 = fdiv double %10, %12
%14 = fmul double %13, %8
%15 = fptosi double %14 to i64
%16 = getelementptr inbounds i64*, i64** %1, i64 %0
%17 = load i64*, i64** %16
%18 = getelementptr inbounds i64, i64* %17, i64 %15
%19 = load i64, i64* %18
br label %20
20: ; preds = %3, %7
%21 = phi i64 [ %19, %7 ], [ -1, %3 ]
ret i64 %21
}