#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);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
double rnd();
int /*<<< orphan*/ stderr;
int poison(double av) {
  double c, x, w;
  int rn;
  if (av <= 0.) {
    fprintf(stderr, "Error : av <= 0.  in poison()\n");
    return 0.;
  }
  if (av >= 10.) {
    fprintf(stderr,
            "Warning : av >= 10.  in poison(). Use normal Random number!\n");
    return 0.;
  }
  c = exp(-av);
  x = 1.;
  rn = -1;
  while (x > c) {
    w = rnd();
    x *= w;
    rn++;
  }
  return rn;
}


x86 assembly (clang, -O0):
<poison>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     116c <poison+0x3c>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xeb5(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121d <poison+0xed>
movsd  -0x10(%rbp),%xmm0
movsd  0xe87(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11a4 <poison+0x74>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121d <poison+0xed>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xe36(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1217 <poison+0xe7>
mov    $0x0,%al
call   1030 <rnd@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11de <poison+0xae>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<poison>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    11a7 <poison+0x77>
ucomisd 0xeb9(%rip),%xmm0
jae    11b0 <poison+0x80>
xorpd  0xebf(%rip),%xmm0
call   1050 <exp@plt>
mov    $0xffffffff,%ebx
movsd  0xea5(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11c7 <poison+0x97>
mov    $0xffffffff,%ebx
movsd  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <rnd@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  (%rsp),%xmm0
add    $0x1,%ebx
ucomisd %xmm0,%xmm1
ja     1180 <poison+0x50>
jmp    11c7 <poison+0x97>
lea    0xe72(%rip),%rsi
jmp    11b7 <poison+0x87>
lea    0xe88(%rip),%rsi
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1040 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Error : av <= 0. in poison()\0A\00"
@.str.1 = [61 x i8] c"Warning : av >= 10. in poison(). Use normal Random number!\0A\00"
define i32 @poison(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store double %0, double* %3
%8 = load double, double* %3
%9 = fcmp ole double %8, 0.000000e+00
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %36
13: ; preds = %1
%14 = load double, double* %3
%15 = fcmp oge double %14, 1.000000e+01
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %36
19: ; preds = %13
%20 = load double, double* %3
%21 = fneg double %20
%22 = call double @exp(double %21)
store double %22, double* %4
store double 1.000000e+00, double* %5
store i32 -1, i32* %7
br label %23
23: ; preds = %27, %19
%24 = load double, double* %5
%25 = load double, double* %4
%26 = fcmp ogt double %24, %25
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = call double (...) @rnd()
store double %28, double* %6
%29 = load double, double* %6
%30 = load double, double* %5
%31 = fmul double %30, %29
store double %31, double* %5
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %23
34: ; preds = %23
%35 = load i32, i32* %7
store i32 %35, i32* %2
br label %36
36: ; preds = %34, %16, %10
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Error : av <= 0. in poison()\0A\00"
@.str.1 = [61 x i8] c"Warning : av >= 10. in poison(). Use normal Random number!\0A\00"
define i32 @poison(double %0) {
%2 = fcmp ugt double %0, 0.000000e+00
br i1 %2, label %3, label %16
3: ; preds = %1
%4 = fcmp ult double %0, 1.000000e+01
br i1 %4, label %5, label %16
5: ; preds = %3
%6 = fneg double %0
%7 = tail call double @exp(double %6)
%8 = fcmp olt double %7, 1.000000e+00
br i1 %8, label %9, label %20
9: ; preds = %5, %9
%10 = phi i32 [ %14, %9 ], [ -1, %5 ]
%11 = phi double [ %13, %9 ], [ 1.000000e+00, %5 ]
%12 = tail call double (...) @rnd()
%13 = fmul double %11, %12
%14 = add nsw i32 %10, 1
%15 = fcmp ogt double %13, %7
br i1 %15, label %9, label %20
16: ; preds = %3, %1
%17 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), %3 ]
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* %17)
br label %20
20: ; preds = %9, %16, %5
%21 = phi i32 [ -1, %5 ], [ 0, %16 ], [ %14, %9 ]
ret i32 %21
}