#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 */
scalar_t__ RAND_MAX;
double cos(int);
double log(double);
scalar_t__ rand();
double sin(int);
double sqrt(double);
void box_muller2(double *x, double *y) {
  double u1, u2;
  double p1;
  u1 = ((double)rand()) / ((double)RAND_MAX);
  u2 = ((double)rand()) / ((double)RAND_MAX);
  p1 = sqrt(-2.0 * log(u1));
  (*x) = p1 * cos(2 * 3.141592653589793 * u2);
  (*y) = p1 * sin(2 * 3.141592653589793 * u2);
}


x86 assembly (clang, -O0):
<box_muller2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e75(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e54(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe51(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe29(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xdf5(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<box_muller2>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm1
mov    0x2e77(%rip),%rbp
cvtsi2sdq 0x0(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq 0x0(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1050 <log@plt>
mulsd  0xe4c(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11c4 <box_muller2+0x74>
sqrtsd %xmm0,%xmm0
jmp    11c9 <box_muller2+0x79>
call   1060 <sqrt@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe2c(%rip),%xmm0
cvttsd2si %xmm0,%ebp
mov    %ebp,%edi
call   1040 <cos@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx)
mov    %ebp,%edi
call   1030 <sin@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define void @box_muller2(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double* %0, double** %3
store double* %1, double** %4
%8 = call i64 (...) @rand()
%9 = sitofp i64 %8 to double
%10 = load i64, i64* @RAND_MAX
%11 = sitofp i64 %10 to double
%12 = fdiv double %9, %11
store double %12, double* %5
%13 = call i64 (...) @rand()
%14 = sitofp i64 %13 to double
%15 = load i64, i64* @RAND_MAX
%16 = sitofp i64 %15 to double
%17 = fdiv double %14, %16
store double %17, double* %6
%18 = load double, double* %5
%19 = call double @log(double %18)
%20 = fmul double -2.000000e+00, %19
%21 = call double @sqrt(double %20)
store double %21, double* %7
%22 = load double, double* %7
%23 = load double, double* %6
%24 = fmul double 0x401921FB54442D18, %23
%25 = fptosi double %24 to i32
%26 = call double @cos(i32 %25)
%27 = fmul double %22, %26
%28 = load double*, double** %3
store double %27, double* %28
%29 = load double, double* %7
%30 = load double, double* %6
%31 = fmul double 0x401921FB54442D18, %30
%32 = fptosi double %31 to i32
%33 = call double @sin(i32 %32)
%34 = fmul double %29, %33
%35 = load double*, double** %4
store double %34, double* %35
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define void @box_muller2(double* nocapture writeonly %0, double* nocapture writeonly %1) {
%3 = tail call i64 (...) @rand()
%4 = sitofp i64 %3 to double
%5 = load i64, i64* @RAND_MAX
%6 = sitofp i64 %5 to double
%7 = fdiv double %4, %6
%8 = tail call i64 (...) @rand()
%9 = sitofp i64 %8 to double
%10 = load i64, i64* @RAND_MAX
%11 = sitofp i64 %10 to double
%12 = fdiv double %9, %11
%13 = tail call double @log(double %7)
%14 = fmul double %13, -2.000000e+00
%15 = tail call double @sqrt(double %14)
%16 = fmul double %12, 0x401921FB54442D18
%17 = fptosi double %16 to i32
%18 = tail call double @cos(i32 %17)
%19 = fmul double %15, %18
store double %19, double* %0
%20 = tail call double @sin(i32 %17)
%21 = fmul double %15, %20
store double %21, double* %1
ret void
}