#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 log(double);
double myrandom(int);
int /*<<< orphan*/ printf(char *);
double random_erlang(int sn, double m, double s) {
  int i, k;
  double z;
  if (s > m)
    printf("erlang argument error: s > m");
  z = m / s;
  k = (int)z * z;
  z = 1.0;
  for (i = 0; i < k; i++)
    z *= myrandom(sn);
  return (-(m / k) * log(z));
}


x86 assembly (clang, -O0):
<random_erlang>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1161 <random_erlang+0x31>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvttsd2si -0x28(%rbp),%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
movsd  0xe73(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11c5 <random_erlang+0x95>
mov    -0x4(%rbp),%edi
call   1040 <myrandom@plt>
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <random_erlang+0x69>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_erlang>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
ucomisd %xmm0,%xmm1
movapd %xmm0,0x10(%rsp)
jbe    1164 <random_erlang+0x34>
lea    0xed3(%rip),%rdi
movsd  %xmm1,0x8(%rsp)
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm1
movapd 0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%r14d
movsd  0xe7f(%rip),%xmm1
test   %r14d,%r14d
jle    11ac <random_erlang+0x7c>
mov    %r14d,%ebp
nopl   0x0(%rax)
movsd  %xmm1,0x8(%rsp)
mov    %ebx,%edi
call   1040 <myrandom@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
add    $0xffffffff,%ebp
jne    1190 <random_erlang+0x60>
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movapd 0x10(%rsp),%xmm2
xorpd  0xe4e(%rip),%xmm2
divsd  %xmm0,%xmm2
movapd %xmm2,0x10(%rsp)
movapd %xmm1,%xmm0
call   1050 <log@plt>
mulsd  0x10(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"erlang argument error: s > m\00"
define double @random_erlang(i32 %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store i32 %0, i32* %4
store double %1, double* %5
store double %2, double* %6
%10 = load double, double* %6
%11 = load double, double* %5
%12 = fcmp ogt double %10, %11
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %3
%16 = load double, double* %5
%17 = load double, double* %6
%18 = fdiv double %16, %17
store double %18, double* %9
%19 = load double, double* %9
%20 = fptosi double %19 to i32
%21 = sitofp i32 %20 to double
%22 = load double, double* %9
%23 = fmul double %21, %22
%24 = fptosi double %23 to i32
store i32 %24, i32* %8
store double 1.000000e+00, double* %9
store i32 0, i32* %7
br label %25
25: ; preds = %34, %15
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %37
29: ; preds = %25
%30 = load i32, i32* %4
%31 = call double @myrandom(i32 %30)
%32 = load double, double* %9
%33 = fmul double %32, %31
store double %33, double* %9
br label %34
34: ; preds = %29
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %25
37: ; preds = %25
%38 = load double, double* %5
%39 = load i32, i32* %8
%40 = sitofp i32 %39 to double
%41 = fdiv double %38, %40
%42 = fneg double %41
%43 = load double, double* %9
%44 = call double @log(double %43)
%45 = fmul double %42, %44
ret double %45
}

LLVM IR (-O2):
@.str = [29 x i8] c"erlang argument error: s > m\00"
define double @random_erlang(i32 %0, double %1, double %2) {
%4 = fcmp ogt double %2, %1
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = fdiv double %1, %2
%9 = fptosi double %8 to i32
%10 = sitofp i32 %9 to double
%11 = fmul double %8, %10
%12 = fptosi double %11 to i32
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %7, %14
%15 = phi double [ %18, %14 ], [ 1.000000e+00, %7 ]
%16 = phi i32 [ %19, %14 ], [ 0, %7 ]
%17 = tail call double @myrandom(i32 %0)
%18 = fmul double %15, %17
%19 = add nuw nsw i32 %16, 1
%20 = icmp eq i32 %19, %12
br i1 %20, label %21, label %14
21: ; preds = %14, %7
%22 = phi double [ 1.000000e+00, %7 ], [ %18, %14 ]
%23 = sitofp i32 %12 to double
%24 = fneg double %1
%25 = fdiv double %24, %23
%26 = tail call double @log(double %22)
%27 = fmul double %25, %26
ret double %27
}