#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;
int cos(int);
int log(double);
scalar_t__ rand();
int sqrt(int);
double random_addition() {
  double r1 = (double)rand() / (double)RAND_MAX;
  double r2 = (double)rand() / (double)RAND_MAX;
  return sqrt(-2 * log(r1)) * cos(2 * 3.14159265359 * r2) / 10000;
}


x86 assembly (clang, -O0):
<random_addition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e8d(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e6c(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <log@plt>
imul   $0xfffffffe,%eax,%edi
call   1050 <sqrt@plt>
mov    %eax,-0x14(%rbp)
movsd  0xe56(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   %ecx,%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_addition>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm1
mov    0x2e90(%rip),%rbx
cvtsi2sdq (%rbx),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1060 <rand@plt>
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>
lea    (%rax,%rax,1),%edi
neg    %edi
call   1050 <sqrt@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
mulsd  0xe55(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
imul   %ebx,%eax
cltq
imul   $0x68db8bad,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define double @random_addition() {
%1 = alloca double
%2 = alloca double
%3 = 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
store double %7, double* %1
%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* %2
%13 = load double, double* %1
%14 = call i32 @log(double %13)
%15 = mul nsw i32 -2, %14
%16 = call i32 @sqrt(i32 %15)
%17 = load double, double* %2
%18 = fmul double 0x401921FB54442EEA, %17
%19 = fptosi double %18 to i32
%20 = call i32 @cos(i32 %19)
%21 = mul nsw i32 %16, %20
%22 = sdiv i32 %21, 10000
%23 = sitofp i32 %22 to double
ret double %23
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define double @random_addition() {
%1 = tail call i64 (...) @rand()
%2 = sitofp i64 %1 to double
%3 = load i64, i64* @RAND_MAX
%4 = sitofp i64 %3 to double
%5 = fdiv double %2, %4
%6 = tail call i64 (...) @rand()
%7 = sitofp i64 %6 to double
%8 = load i64, i64* @RAND_MAX
%9 = sitofp i64 %8 to double
%10 = fdiv double %7, %9
%11 = tail call i32 @log(double %5)
%12 = mul nsw i32 %11, -2
%13 = tail call i32 @sqrt(i32 %12)
%14 = fmul double %10, 0x401921FB54442EEA
%15 = fptosi double %14 to i32
%16 = tail call i32 @cos(i32 %15)
%17 = mul nsw i32 %16, %13
%18 = sdiv i32 %17, 10000
%19 = sitofp i32 %18 to double
ret double %19
}