#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 ran0(long *);
double sqrt(double);
double gasmin(long *idum) {
  double fac, rsq, v1, v2;
  do {
    v1 = 2.0 * ran0(idum) - 1.0;
    v2 = 2.0 * ran0(idum) - 1.0;
    rsq = v1 * v1 + v2 * v2;
  } while (rsq >= 1.0 || rsq == 0.0);
  fac = sqrt(-2.0 * log(rsq) / rsq);
  return (double)(v2 * fac);
}


x86 assembly (clang, -O0):
<gasmin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ran0@plt>
addsd  %xmm0,%xmm0
movsd  0xeaf(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ran0@plt>
addsd  %xmm0,%xmm0
movsd  0xe91(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    $0x1,%al
movsd  0xe60(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
jae    11cc <gasmin+0x9c>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    113c <gasmin+0xc>
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe24(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gasmin>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <ran0@plt>
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xea8(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %rbx,%rdi
call   1030 <ran0@plt>
addsd  %xmm0,%xmm0
addsd  0xe8b(%rip),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  (%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
ucomisd 0xe76(%rip),%xmm2
jae    1140 <gasmin+0x10>
movapd %xmm2,%xmm1
ucomisd 0xe78(%rip),%xmm2
jne    11a4 <gasmin+0x74>
jnp    1140 <gasmin+0x10>
movsd  %xmm0,0x8(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm1,(%rsp)
call   1040 <log@plt>
mulsd  0xe50(%rip),%xmm0
divsd  (%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11d5 <gasmin+0xa5>
sqrtsd %xmm0,%xmm0
jmp    11da <gasmin+0xaa>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @gasmin(i64* %0) {
%2 = alloca i64*
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store i64* %0, i64** %2
br label %7
7: ; preds = %26, %1
%8 = load i64*, i64** %2
%9 = call double @ran0(i64* %8)
%10 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %9, double -1.000000e+00)
store double %10, double* %5
%11 = load i64*, i64** %2
%12 = call double @ran0(i64* %11)
%13 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %12, double -1.000000e+00)
store double %13, double* %6
%14 = load double, double* %5
%15 = load double, double* %5
%16 = load double, double* %6
%17 = load double, double* %6
%18 = fmul double %16, %17
%19 = call double @llvm.fmuladd.f64(double %14, double %15, double %18)
store double %19, double* %4
br label %20
20: ; preds = %7
%21 = load double, double* %4
%22 = fcmp oge double %21, 1.000000e+00
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load double, double* %4
%25 = fcmp oeq double %24, 0.000000e+00
br label %26
26: ; preds = %23, %20
%27 = phi i1 [ true, %20 ], [ %25, %23 ]
br i1 %27, label %7, label %28
28: ; preds = %26
%29 = load double, double* %4
%30 = call double @log(double %29)
%31 = fmul double -2.000000e+00, %30
%32 = load double, double* %4
%33 = fdiv double %31, %32
%34 = call double @sqrt(double %33)
store double %34, double* %3
%35 = load double, double* %6
%36 = load double, double* %3
%37 = fmul double %35, %36
ret double %37
}

LLVM IR (-O2):
define double @gasmin(i64* %0) {
br label %2
2: ; preds = %2, %1
%3 = tail call double @ran0(i64* %0)
%4 = tail call double @llvm.fmuladd.f64(double %3, double 2.000000e+00, double -1.000000e+00)
%5 = tail call double @ran0(i64* %0)
%6 = tail call double @llvm.fmuladd.f64(double %5, double 2.000000e+00, double -1.000000e+00)
%7 = fmul double %6, %6
%8 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %7)
%9 = fcmp oge double %8, 1.000000e+00
%10 = fcmp oeq double %8, 0.000000e+00
%11 = or i1 %9, %10
br i1 %11, label %2, label %12
12: ; preds = %2
%13 = tail call double @log(double %8)
%14 = fmul double %13, -2.000000e+00
%15 = fdiv double %14, %8
%16 = tail call double @sqrt(double %15)
%17 = fmul double %6, %16
ret double %17
}