#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 */
int /*<<< orphan*/ error(int /*<<< orphan*/, char *);
double log(double);
double ranf();
double erlang(double x, double s) {
  int i, k;
  double z;
  if (s > x)
    error(0, "erlang Argument Error: s > x");
  z = x / s;
  k = (int)(z * z);
  z = 1.0;
  for (i = 0; i < k; i++)
    z *= ranf();
  return (-(x / k) * log(z));
}


x86 assembly (clang, -O0):
<erlang>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1160 <erlang+0x30>
xor    %edi,%edi
lea    0xead(%rip),%rsi
call   1040 <error@plt>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
movsd  0xe78(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11bf <erlang+0x8f>
mov    $0x0,%al
call   1030 <ranf@plt>
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1194 <erlang+0x64>
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<erlang>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
ucomisd %xmm0,%xmm1
movapd %xmm0,0x10(%rsp)
jbe    1162 <erlang+0x32>
lea    0xed7(%rip),%rsi
xor    %edi,%edi
movsd  %xmm1,0x8(%rsp)
call   1040 <error@plt>
movsd  0x8(%rsp),%xmm1
movapd 0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
cvttsd2si %xmm0,%ebx
movsd  0xe8a(%rip),%xmm1
test   %ebx,%ebx
jle    119c <erlang+0x6c>
mov    %ebx,%ebp
nopl   0x0(%rax)
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <ranf@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
add    $0xffffffff,%ebp
jne    1180 <erlang+0x50>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movapd 0x10(%rsp),%xmm2
xorpd  0xe5f(%rip),%xmm2
divsd  %xmm0,%xmm2
movapd %xmm2,0x10(%rsp)
movapd %xmm1,%xmm0
call   1050 <log@plt>
mulsd  0x10(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

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

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