#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 myrand();
int beatProbability(double power) {
  int result;
  double p;
  if (power > 0.0)
    result = 1;
  else {
    p = exp(power);
    if (p >= 1)
      result = 1;
    else {
      result = myrand() < p * 32767;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<beatProbability>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    114b <beatProbability+0x2b>
movl   $0x1,-0xc(%rbp)
jmp    11a8 <beatProbability+0x88>
movsd  -0x8(%rbp),%xmm0
call   1040 <exp@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe99(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     117d <beatProbability+0x5d>
movl   $0x1,-0xc(%rbp)
jmp    11a3 <beatProbability+0x83>
mov    $0x0,%al
call   1030 <myrand@plt>
movaps %xmm0,%xmm1
movsd  0xe79(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
jmp    11a8 <beatProbability+0x88>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<beatProbability>:
push   %rbx
sub    $0x10,%rsp
mov    $0x1,%ebx
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
ja     1167 <beatProbability+0x47>
call   1040 <exp@plt>
ucomisd 0xebf(%rip),%xmm0
jae    1167 <beatProbability+0x47>
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1030 <myrand@plt>
movsd  0x8(%rsp),%xmm1
mulsd  0xeaa(%rip),%xmm1
xor    %ebx,%ebx
ucomisd %xmm0,%xmm1
seta   %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @beatProbability(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca double
store double %0, double* %2
%5 = load double, double* %2
%6 = fcmp ogt double %5, 0.000000e+00
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 1, i32* %3
br label %21
8: ; preds = %1
%9 = load double, double* %2
%10 = call double @exp(double %9)
store double %10, double* %4
%11 = load double, double* %4
%12 = fcmp oge double %11, 1.000000e+00
br i1 %12, label %13, label %14
13: ; preds = %8
store i32 1, i32* %3
br label %20
14: ; preds = %8
%15 = call double (...) @myrand()
%16 = load double, double* %4
%17 = fmul double %16, 3.276700e+04
%18 = fcmp olt double %15, %17
%19 = zext i1 %18 to i32
store i32 %19, i32* %3
br label %20
20: ; preds = %14, %13
br label %21
21: ; preds = %20, %7
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
define i32 @beatProbability(double %0) {
%2 = fcmp ogt double %0, 0.000000e+00
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = tail call double @exp(double %0)
%5 = fcmp ult double %4, 1.000000e+00
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = tail call double (...) @myrand()
%8 = fmul double %4, 3.276700e+04
%9 = fcmp olt double %7, %8
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %3, %1, %6
%12 = phi i32 [ %10, %6 ], [ 1, %1 ], [ 1, %3 ]
ret i32 %12
}