#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_norm();
int sample_rect(double *prob, int nsample) {
  double xi;
  double normfac;
  normfac = prob[63] * (93 + 1) + prob[99] * (104 - 93) +
            prob[105] * (nsample - 1 - 104);
  xi = normfac * rand_norm();
  if (xi <= prob[63] * (93 + 1))
    return xi / prob[63];
  else if (xi <= prob[63] * (93 + 1) + prob[99] * (104 - 93))
    return (xi - prob[63] * (93 + 1)) / prob[99] + 93 + 1;
  else
    return (xi - prob[63] * (93 + 1) - prob[99] * (104 - 93)) / prob[105] +
           104 + 1;
}


x86 assembly (clang, -O0):
<sample_rect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x1f8(%rax),%xmm1
mov    -0x10(%rbp),%rax
movsd  0xed1(%rip),%xmm0
mulsd  0x318(%rax),%xmm0
movsd  0xeb9(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x348(%rax),%xmm0
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
sub    $0x68,%eax
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <rand_norm@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movsd  0xe58(%rip),%xmm0
mulsd  0x1f8(%rax),%xmm0
ucomisd %xmm1,%xmm0
jb     11d7 <sample_rect+0xc7>
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
divsd  0x1f8(%rax),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
jmp    1314 <sample_rect+0x204>
movsd  -0x20(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x1f8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0xe14(%rip),%xmm2
mulsd  0x318(%rax),%xmm2
movsd  0xdfc(%rip),%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     127e <sample_rect+0x16e>
movsd  -0x20(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movsd  0x1f8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdba(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
divsd  0x318(%rax),%xmm0
movsd  0xdbe(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xda2(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
jmp    1314 <sample_rect+0x204>
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x1f8(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xd52(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x318(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xd27(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
divsd  0x348(%rax),%xmm0
movsd  0xd1b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  0xd07(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sample_rect>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsd  0x318(%rdi),%xmm0
mulsd  0xed8(%rip),%xmm0
movsd  0x1f8(%rdi),%xmm1
mulsd  0xed0(%rip),%xmm1
add    $0xffffff97,%esi
cvtsi2sd %esi,%xmm2
addsd  %xmm0,%xmm1
mulsd  0x348(%rdi),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
xor    %eax,%eax
call   1030 <rand_norm@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0x1f8(%rbx),%xmm1
movsd  0xe96(%rip),%xmm2
mulsd  %xmm1,%xmm2
ucomisd %xmm0,%xmm2
jae    11c4 <sample_rect+0xb4>
movsd  0x318(%rbx),%xmm2
movsd  0xe74(%rip),%xmm3
mulsd  %xmm2,%xmm3
mulsd  0xe70(%rip),%xmm1
addsd  %xmm1,%xmm3
ucomisd %xmm0,%xmm3
subsd  %xmm1,%xmm0
jae    11ca <sample_rect+0xba>
mulsd  0xe72(%rip),%xmm2
addsd  %xmm2,%xmm0
divsd  0x348(%rbx),%xmm0
addsd  0xe66(%rip),%xmm0
jmp    11d6 <sample_rect+0xc6>
divsd  %xmm1,%xmm0
jmp    11de <sample_rect+0xce>
divsd  %xmm2,%xmm0
addsd  0xe3a(%rip),%xmm0
addsd  0xe3a(%rip),%xmm0
cvttsd2si %xmm0,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @sample_rect(double* %0, i32 %1) {
%3 = alloca i32
%4 = alloca double*
%5 = alloca i32
%6 = alloca double
%7 = alloca double
store double* %0, double** %4
store i32 %1, i32* %5
%8 = load double*, double** %4
%9 = getelementptr inbounds double, double* %8, i64 63
%10 = load double, double* %9
%11 = load double*, double** %4
%12 = getelementptr inbounds double, double* %11, i64 99
%13 = load double, double* %12
%14 = fmul double %13, 1.100000e+01
%15 = call double @llvm.fmuladd.f64(double %10, double 9.400000e+01, double %14)
%16 = load double*, double** %4
%17 = getelementptr inbounds double, double* %16, i64 105
%18 = load double, double* %17
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 1
%21 = sub nsw i32 %20, 104
%22 = sitofp i32 %21 to double
%23 = call double @llvm.fmuladd.f64(double %18, double %22, double %15)
store double %23, double* %7
%24 = load double, double* %7
%25 = call double (...) @rand_norm()
%26 = fmul double %24, %25
store double %26, double* %6
%27 = load double, double* %6
%28 = load double*, double** %4
%29 = getelementptr inbounds double, double* %28, i64 63
%30 = load double, double* %29
%31 = fmul double %30, 9.400000e+01
%32 = fcmp ole double %27, %31
br i1 %32, label %33, label %40
33: ; preds = %2
%34 = load double, double* %6
%35 = load double*, double** %4
%36 = getelementptr inbounds double, double* %35, i64 63
%37 = load double, double* %36
%38 = fdiv double %34, %37
%39 = fptosi double %38 to i32
store i32 %39, i32* %3
br label %84
40: ; preds = %2
%41 = load double, double* %6
%42 = load double*, double** %4
%43 = getelementptr inbounds double, double* %42, i64 63
%44 = load double, double* %43
%45 = load double*, double** %4
%46 = getelementptr inbounds double, double* %45, i64 99
%47 = load double, double* %46
%48 = fmul double %47, 1.100000e+01
%49 = call double @llvm.fmuladd.f64(double %44, double 9.400000e+01, double %48)
%50 = fcmp ole double %41, %49
br i1 %50, label %51, label %65
51: ; preds = %40
%52 = load double, double* %6
%53 = load double*, double** %4
%54 = getelementptr inbounds double, double* %53, i64 63
%55 = load double, double* %54
%56 = fneg double %55
%57 = call double @llvm.fmuladd.f64(double %56, double 9.400000e+01, double %52)
%58 = load double*, double** %4
%59 = getelementptr inbounds double, double* %58, i64 99
%60 = load double, double* %59
%61 = fdiv double %57, %60
%62 = fadd double %61, 9.300000e+01
%63 = fadd double %62, 1.000000e+00
%64 = fptosi double %63 to i32
store i32 %64, i32* %3
br label %84
65: ; preds = %40
%66 = load double, double* %6
%67 = load double*, double** %4
%68 = getelementptr inbounds double, double* %67, i64 63
%69 = load double, double* %68
%70 = fneg double %69
%71 = call double @llvm.fmuladd.f64(double %70, double 9.400000e+01, double %66)
%72 = load double*, double** %4
%73 = getelementptr inbounds double, double* %72, i64 99
%74 = load double, double* %73
%75 = fneg double %74
%76 = call double @llvm.fmuladd.f64(double %75, double 1.100000e+01, double %71)
%77 = load double*, double** %4
%78 = getelementptr inbounds double, double* %77, i64 105
%79 = load double, double* %78
%80 = fdiv double %76, %79
%81 = fadd double %80, 1.040000e+02
%82 = fadd double %81, 1.000000e+00
%83 = fptosi double %82 to i32
store i32 %83, i32* %3
br label %84
84: ; preds = %65, %51, %33
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
define i32 @sample_rect(double* nocapture %0, i32 %1) {
%3 = getelementptr inbounds double, double* %0, i64 63
%4 = load double, double* %3
%5 = getelementptr inbounds double, double* %0, i64 99
%6 = load double, double* %5
%7 = fmul double %6, 1.100000e+01
%8 = tail call double @llvm.fmuladd.f64(double %4, double 9.400000e+01, double %7)
%9 = getelementptr inbounds double, double* %0, i64 105
%10 = load double, double* %9
%11 = add nsw i32 %1, -105
%12 = sitofp i32 %11 to double
%13 = tail call double @llvm.fmuladd.f64(double %10, double %12, double %8)
%14 = tail call double (...) @rand_norm()
%15 = fmul double %14, %13
%16 = load double, double* %3
%17 = fmul double %16, 9.400000e+01
%18 = fcmp ugt double %15, %17
br i1 %18, label %21, label %19
19: ; preds = %2
%20 = fdiv double %15, %16
br label %39
21: ; preds = %2
%22 = load double, double* %5
%23 = fmul double %22, 1.100000e+01
%24 = tail call double @llvm.fmuladd.f64(double %16, double 9.400000e+01, double %23)
%25 = fcmp ugt double %15, %24
%26 = fneg double %16
%27 = tail call double @llvm.fmuladd.f64(double %26, double 9.400000e+01, double %15)
br i1 %25, label %32, label %28
28: ; preds = %21
%29 = fdiv double %27, %22
%30 = fadd double %29, 9.300000e+01
%31 = fadd double %30, 1.000000e+00
br label %39
32: ; preds = %21
%33 = fneg double %22
%34 = tail call double @llvm.fmuladd.f64(double %33, double 1.100000e+01, double %27)
%35 = load double, double* %9
%36 = fdiv double %34, %35
%37 = fadd double %36, 1.040000e+02
%38 = fadd double %37, 1.000000e+00
br label %39
39: ; preds = %32, %28, %19
%40 = phi double [ %20, %19 ], [ %31, %28 ], [ %38, %32 ]
%41 = fptosi double %40 to i32
ret i32 %41
}