#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 exp(double);
double rand_double(double, double);
int rand_range32(int /*<<< orphan*/, int);
int gen_prob_rand_untabbed(int start, int end, double prob) {
  int rend = end - start;
  double frend = (double)rend;
  if (rend < 2)
    return start;
  while (1) {
    double fx = rand_double(0.0, 1.0);
    int ix = rand_range32(0, rend + 1);
    double x = (ix * 2) / (double)frend;
    if (fx <= exp(-prob * x * x))
      return start + ix;
  }
}


x86 assembly (clang, -O0):
<gen_prob_rand_untabbed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    116b <gen_prob_rand_untabbed+0x3b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1200 <gen_prob_rand_untabbed+0xd0>
jmp    1170 <gen_prob_rand_untabbed+0x40>
xorps  %xmm0,%xmm0
movsd  0xe85(%rip),%xmm1
call   1030 <rand_double@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
xor    %edi,%edi
call   1050 <rand_range32@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
call   1040 <exp@plt>
movsd  -0x48(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     11fb <gen_prob_rand_untabbed+0xcb>
mov    -0x8(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1200 <gen_prob_rand_untabbed+0xd0>
jmp    1170 <gen_prob_rand_untabbed+0x40>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_prob_rand_untabbed>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,(%rsp)
mov    %esi,%ebp
mov    %edi,%r14d
sub    %edi,%ebp
cmp    $0x2,%ebp
jl     11c2 <gen_prob_rand_untabbed+0x92>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x10(%rsp)
add    $0x1,%ebp
movapd (%rsp),%xmm0
xorpd  0xe9a(%rip),%xmm0
movapd %xmm0,(%rsp)
nopl   0x0(%rax,%rax,1)
xorpd  %xmm0,%xmm0
movsd  0xe94(%rip),%xmm1
call   1030 <rand_double@plt>
movsd  %xmm0,0x18(%rsp)
xor    %edi,%edi
mov    %ebp,%esi
call   1050 <rand_range32@plt>
mov    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
mulsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <exp@plt>
ucomisd 0x18(%rsp),%xmm0
jb     1170 <gen_prob_rand_untabbed+0x40>
add    %r14d,%ebx
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gen_prob_rand_untabbed(i32 %0, i32 %1, double %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca double
store i32 %0, i32* %5
store i32 %1, i32* %6
store double %2, double* %7
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = sub nsw i32 %13, %14
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = sitofp i32 %16 to double
store double %17, double* %9
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = load i32, i32* %5
store i32 %21, i32* %4
br label %47
22: ; preds = %3
br label %23
23: ; preds = %22, %46
%24 = call double @rand_double(double 0.000000e+00, double 1.000000e+00)
store double %24, double* %10
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
%27 = call i32 @rand_range32(i32 0, i32 %26)
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = mul nsw i32 %28, 2
%30 = sitofp i32 %29 to double
%31 = load double, double* %9
%32 = fdiv double %30, %31
store double %32, double* %12
%33 = load double, double* %10
%34 = load double, double* %7
%35 = fneg double %34
%36 = load double, double* %12
%37 = fmul double %35, %36
%38 = load double, double* %12
%39 = fmul double %37, %38
%40 = call double @exp(double %39)
%41 = fcmp ole double %33, %40
br i1 %41, label %42, label %46
42: ; preds = %23
%43 = load i32, i32* %5
%44 = load i32, i32* %11
%45 = add nsw i32 %43, %44
store i32 %45, i32* %4
br label %47
46: ; preds = %23
br label %23
47: ; preds = %42, %20
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
define i32 @gen_prob_rand_untabbed(i32 %0, i32 %1, double %2) {
%4 = sub nsw i32 %1, %0
%5 = sitofp i32 %4 to double
%6 = icmp slt i32 %4, 2
br i1 %6, label %22, label %7
7: ; preds = %3
%8 = add nuw nsw i32 %4, 1
%9 = fneg double %2
br label %10
10: ; preds = %7, %10
%11 = tail call double @rand_double(double 0.000000e+00, double 1.000000e+00)
%12 = tail call i32 @rand_range32(i32 0, i32 %8)
%13 = shl nsw i32 %12, 1
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, %5
%16 = fmul double %15, %9
%17 = fmul double %15, %16
%18 = tail call double @exp(double %17)
%19 = fcmp ugt double %11, %18
br i1 %19, label %10, label %20
20: ; preds = %10
%21 = add nsw i32 %12, %0
br label %22
22: ; preds = %20, %3
%23 = phi i32 [ %0, %3 ], [ %21, %20 ]
ret i32 %23
}