#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*/ erro(char *);
double log(double);
double ranf();
double erlang(double x, double s) {
  int i, k;
  double z;
  if (s > x)
    erro("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    115e <erlang+0x2e>
lea    0xeaf(%rip),%rdi
call   1030 <erro@plt>
movsd  -0x8(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x20(%rbp),%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
movsd  0xe76(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c1 <erlang+0x91>
mov    $0x0,%al
call   1040 <ranf@plt>
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1196 <erlang+0x66>
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    1160 <erlang+0x30>
lea    0xed7(%rip),%rdi
movsd  %xmm1,0x8(%rsp)
call   1030 <erro@plt>
movsd  0x8(%rsp),%xmm1
movapd 0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%ebx
movsd  0xe84(%rip),%xmm1
test   %ebx,%ebx
jle    11ac <erlang+0x7c>
mov    %ebx,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1040 <ranf@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
add    $0xffffffff,%ebp
jne    1190 <erlang+0x60>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movapd 0x10(%rsp),%xmm2
xorpd  0xe4f(%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 @erro(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 = fptosi double %17 to i32
%19 = sitofp i32 %18 to double
%20 = load double, double* %7
%21 = fmul double %19, %20
%22 = fptosi double %21 to i32
store i32 %22, i32* %6
store double 1.000000e+00, double* %7
store i32 0, i32* %5
br label %23
23: ; preds = %31, %13
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %34
27: ; preds = %23
%28 = call double (...) @ranf()
%29 = load double, double* %7
%30 = fmul double %29, %28
store double %30, double* %7
br label %31
31: ; preds = %27
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %23
34: ; preds = %23
%35 = load double, double* %3
%36 = load i32, i32* %6
%37 = sitofp i32 %36 to double
%38 = fdiv double %35, %37
%39 = fneg double %38
%40 = load double, double* %7
%41 = call double @log(double %40)
%42 = fmul double %39, %41
ret double %42
}

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 @erro(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 = fptosi double %7 to i32
%9 = sitofp i32 %8 to double
%10 = fmul double %7, %9
%11 = fptosi double %10 to i32
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %6, %13
%14 = phi double [ %17, %13 ], [ 1.000000e+00, %6 ]
%15 = phi i32 [ %18, %13 ], [ 0, %6 ]
%16 = tail call double (...) @ranf()
%17 = fmul double %14, %16
%18 = add nuw nsw i32 %15, 1
%19 = icmp eq i32 %18, %11
br i1 %19, label %20, label %13
20: ; preds = %13, %6
%21 = phi double [ 1.000000e+00, %6 ], [ %17, %13 ]
%22 = sitofp i32 %11 to double
%23 = fneg double %0
%24 = fdiv double %23, %22
%25 = tail call double @log(double %21)
%26 = fmul double %24, %25
ret double %26
}