#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 sqrt(double);
double box_muller() {
  double u1, u2;
  u1 = ((double)(rand() + 1)) / ((double)RAND_MAX);
  u2 = ((double)(rand() + 1)) / ((double)RAND_MAX);
  return sqrt(-2.0 * log(u1)) * cos(2 * 3.141592653589793 * u2);
}


x86 assembly (clang, -O0):
<box_muller>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <rand@plt>
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
mov    0x2e89(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
mov    0x2e64(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe61(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xe43(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<box_muller>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1060 <rand@plt>
add    $0x1,%rax
cvtsi2sd %rax,%xmm1
mov    0x2e8c(%rip),%rbx
cvtsi2sdq (%rbx),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
add    $0x1,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq (%rbx),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1040 <log@plt>
mulsd  0xe5f(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11b1 <box_muller+0x71>
sqrtsd %xmm0,%xmm0
jmp    11b6 <box_muller+0x76>
call   1050 <sqrt@plt>
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe3f(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
mulsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define double @box_muller() {
%1 = alloca double
%2 = alloca double
%3 = call i64 (...) @rand()
%4 = add nsw i64 %3, 1
%5 = sitofp i64 %4 to double
%6 = load i64, i64* @RAND_MAX
%7 = sitofp i64 %6 to double
%8 = fdiv double %5, %7
store double %8, double* %1
%9 = call i64 (...) @rand()
%10 = add nsw i64 %9, 1
%11 = sitofp i64 %10 to double
%12 = load i64, i64* @RAND_MAX
%13 = sitofp i64 %12 to double
%14 = fdiv double %11, %13
store double %14, double* %2
%15 = load double, double* %1
%16 = call double @log(double %15)
%17 = fmul double -2.000000e+00, %16
%18 = call double @sqrt(double %17)
%19 = load double, double* %2
%20 = fmul double 0x401921FB54442D18, %19
%21 = fptosi double %20 to i32
%22 = call double @cos(i32 %21)
%23 = fmul double %18, %22
ret double %23
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define double @box_muller() {
%1 = tail call i64 (...) @rand()
%2 = add nsw i64 %1, 1
%3 = sitofp i64 %2 to double
%4 = load i64, i64* @RAND_MAX
%5 = sitofp i64 %4 to double
%6 = fdiv double %3, %5
%7 = tail call i64 (...) @rand()
%8 = add nsw i64 %7, 1
%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 %6)
%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
ret double %19
}