#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 */
typedef double uint8_t;
typedef long const uint64_t;
typedef int uint16_t;
typedef scalar_t__ int64_t;

/* Variables and functions */
double cos(double);
scalar_t__ floor(double);
double log(double);
int /*<<< orphan*/ rng_uint64(long const *);
double sin(double);
double const sqrt(double);
void DGS(int64_t *v, const uint16_t dim, const uint8_t stdev) {
  uint16_t d2 = dim / 2;
  uint16_t i;
  uint64_t t;
  static double const Pi = 3.141592653589793238462643383279502884L;
  static long const bignum = 0xfffffff;
  double r1, r2, theta, rr;
  for (i = 0; i < d2; i++) {
    rng_uint64(&t);
    r1 = (1 + (t & bignum)) / ((double)bignum + 1);
    r2 = (1 + ((t >> 32) & bignum)) / ((double)bignum + 1);
    theta = 2 * Pi * r1;
    rr = sqrt(-2.0 * log(r2)) * stdev;
    v[2 * i] = (int64_t)floor(rr * sin(theta) + 0.5);
    v[2 * i + 1] = (int64_t)floor(rr * cos(theta) + 0.5);
  }
  if (dim % 2 == 1) {
    rng_uint64(&t);
    r1 = (1 + (t & bignum)) / ((double)bignum + 1);
    r2 = (1 + ((t >> 32) & bignum)) / ((double)bignum + 1);
    theta = 2 * Pi * r1;
    rr = sqrt(-2.0 * log(r2)) * stdev;
    v[dim - 1] = (int64_t)floor(rr * sin(theta) + 0.5);
  }
}


x86 assembly (clang, -O0):
<DGS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12bf <DGS+0x15f>
lea    -0x28(%rbp),%rdi
call   1030 <rng_uint64@plt>
mov    -0x28(%rbp),%rax
and    $0xfffffff,%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
movsd  0xe5f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
sar    $0x20,%rax
and    $0xfffffff,%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
movsd  0xe37(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe1e(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdf7(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xdb4(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1080 <floor@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd6f(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1080 <floor@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1189 <DGS+0x29>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    13a7 <DGS+0x247>
lea    -0x28(%rbp),%rdi
call   1030 <rng_uint64@plt>
mov    -0x28(%rbp),%rax
and    $0xfffffff,%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
movsd  0xd21(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
sar    $0x20,%rax
and    $0xfffffff,%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
movsd  0xcf9(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xce0(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  0xcb9(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xc76(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1080 <floor@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DGS>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x18(%rsp)
mov    %esi,%r14d
mov    %rdi,%rbx
cmp    $0x2,%esi
jl     1274 <DGS+0x114>
mov    %r14d,%r12d
shr    %r12d
shl    $0x4,%r12
xor    %ebp,%ebp
lea    0x10(%rsp),%r15
jmp    1200 <DGS+0xa0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1070 <sqrt@plt>
mulsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
mulsd  (%rsp),%xmm0
movsd  0xe50(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1080 <floor@plt>
mov    %rax,(%rbx,%rbp,1)
movsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
addsd  0xe2b(%rip),%xmm0
call   1080 <floor@plt>
mov    %rax,0x8(%rbx,%rbp,1)
add    $0x10,%rbp
cmp    %rbp,%r12
je     1274 <DGS+0x114>
mov    %r15,%rdi
call   1030 <rng_uint64@plt>
mov    0x10(%rsp),%rax
mov    %eax,%ecx
and    $0xfffffff,%ecx
add    $0x1,%ecx
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
movsd  0xdd9(%rip),%xmm1
mulsd  %xmm1,%xmm2
shr    $0x20,%rax
and    $0xfffffff,%eax
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0xdbe(%rip),%xmm2
movsd  %xmm2,0x8(%rsp)
call   1060 <log@plt>
mulsd  0xdb3(%rip),%xmm0
ucomisd 0xdbb(%rip),%xmm0
jb     11a0 <DGS+0x40>
sqrtsd %xmm0,%xmm0
jmp    11a5 <DGS+0x45>
mov    %r14d,%eax
shr    $0x1f,%eax
add    %r14d,%eax
and    $0xfffffffe,%eax
mov    %r14d,%ecx
sub    %eax,%ecx
cmp    $0x1,%ecx
jne    1332 <DGS+0x1d2>
lea    0x10(%rsp),%rdi
call   1030 <rng_uint64@plt>
mov    0x10(%rsp),%rax
mov    %eax,%ecx
and    $0xfffffff,%ecx
add    $0x1,%ecx
xorps  %xmm2,%xmm2
cvtsi2sd %ecx,%xmm2
movsd  0xd49(%rip),%xmm1
shr    $0x20,%rax
and    $0xfffffff,%eax
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm0
mulsd  0xd2e(%rip),%xmm2
movsd  %xmm2,0x8(%rsp)
call   1060 <log@plt>
mulsd  0xd23(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12fd <DGS+0x19d>
sqrtsd %xmm0,%xmm0
jmp    1302 <DGS+0x1a2>
call   1070 <sqrt@plt>
mulsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
mulsd  (%rsp),%xmm0
addsd  0xcf3(%rip),%xmm0
call   1080 <floor@plt>
movslq %r14d,%rcx
mov    %rax,-0x8(%rbx,%rcx,8)
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@DGS.Pi = internal constant double 0x400921FB54442D18
@DGS.bignum = internal constant i64 268435455
define void @DGS(i64* %0, i32 %1, double %2) {
%4 = alloca i64*
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i64* %0, i64** %4
store i32 %1, i32* %5
store double %2, double* %6
%14 = load i32, i32* %5
%15 = sdiv i32 %14, 2
store i32 %15, i32* %7
store i32 0, i32* %8
br label %16
16: ; preds = %62, %3
%17 = load i32, i32* %8
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %65
20: ; preds = %16
%21 = call i32 @rng_uint64(i64* %9)
%22 = load i64, i64* %9
%23 = and i64 %22, 268435455
%24 = add nsw i64 1, %23
%25 = sitofp i64 %24 to double
%26 = fdiv double %25, 0x41B0000000000000
store double %26, double* %10
%27 = load i64, i64* %9
%28 = ashr i64 %27, 32
%29 = and i64 %28, 268435455
%30 = add nsw i64 1, %29
%31 = sitofp i64 %30 to double
%32 = fdiv double %31, 0x41B0000000000000
store double %32, double* %11
%33 = load double, double* %10
%34 = fmul double 0x401921FB54442D18, %33
store double %34, double* %12
%35 = load double, double* %11
%36 = call double @log(double %35)
%37 = fmul double -2.000000e+00, %36
%38 = call double @sqrt(double %37)
%39 = load double, double* %6
%40 = fmul double %38, %39
store double %40, double* %13
%41 = load double, double* %13
%42 = load double, double* %12
%43 = call double @sin(double %42)
%44 = call double @llvm.fmuladd.f64(double %41, double %43, double 5.000000e-01)
%45 = call i64 @floor(double %44)
%46 = load i64*, i64** %4
%47 = load i32, i32* %8
%48 = mul nsw i32 2, %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i64, i64* %46, i64 %49
store i64 %45, i64* %50
%51 = load double, double* %13
%52 = load double, double* %12
%53 = call double @cos(double %52)
%54 = call double @llvm.fmuladd.f64(double %51, double %53, double 5.000000e-01)
%55 = call i64 @floor(double %54)
%56 = load i64*, i64** %4
%57 = load i32, i32* %8
%58 = mul nsw i32 2, %57
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i64, i64* %56, i64 %60
store i64 %55, i64* %61
br label %62
62: ; preds = %20
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
store i32 %64, i32* %8
br label %16
65: ; preds = %16
%66 = load i32, i32* %5
%67 = srem i32 %66, 2
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %100
69: ; preds = %65
%70 = call i32 @rng_uint64(i64* %9)
%71 = load i64, i64* %9
%72 = and i64 %71, 268435455
%73 = add nsw i64 1, %72
%74 = sitofp i64 %73 to double
%75 = fdiv double %74, 0x41B0000000000000
store double %75, double* %10
%76 = load i64, i64* %9
%77 = ashr i64 %76, 32
%78 = and i64 %77, 268435455
%79 = add nsw i64 1, %78
%80 = sitofp i64 %79 to double
%81 = fdiv double %80, 0x41B0000000000000
store double %81, double* %11
%82 = load double, double* %10
%83 = fmul double 0x401921FB54442D18, %82
store double %83, double* %12
%84 = load double, double* %11
%85 = call double @log(double %84)
%86 = fmul double -2.000000e+00, %85
%87 = call double @sqrt(double %86)
%88 = load double, double* %6
%89 = fmul double %87, %88
store double %89, double* %13
%90 = load double, double* %13
%91 = load double, double* %12
%92 = call double @sin(double %91)
%93 = call double @llvm.fmuladd.f64(double %90, double %92, double 5.000000e-01)
%94 = call i64 @floor(double %93)
%95 = load i64*, i64** %4
%96 = load i32, i32* %5
%97 = sub nsw i32 %96, 1
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i64, i64* %95, i64 %98
store i64 %94, i64* %99
br label %100
100: ; preds = %69, %65
ret void
}

LLVM IR (-O2):
define void @DGS(i64* nocapture writeonly %0, i32 %1, double %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = icmp sgt i32 %1, 1
br i1 %6, label %7, label %40
7: ; preds = %3
%8 = lshr i32 %1, 1
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %7, %10
%11 = phi i64 [ 0, %7 ], [ %38, %10 ]
%12 = call i32 @rng_uint64(i64* %4)
%13 = load i64, i64* %4
%14 = and i64 %13, 268435455
%15 = add nuw nsw i64 %14, 1
%16 = sitofp i64 %15 to double
%17 = fmul double %16, 0x3E30000000000000
%18 = lshr i64 %13, 32
%19 = and i64 %18, 268435455
%20 = add nuw nsw i64 %19, 1
%21 = sitofp i64 %20 to double
%22 = fmul double %21, 0x3E30000000000000
%23 = fmul double %17, 0x401921FB54442D18
%24 = call double @log(double %22)
%25 = fmul double %24, -2.000000e+00
%26 = call double @sqrt(double %25)
%27 = fmul double %26, %2
%28 = call double @sin(double %23)
%29 = call double @llvm.fmuladd.f64(double %27, double %28, double 5.000000e-01)
%30 = call i64 @floor(double %29)
%31 = shl nuw nsw i64 %11, 1
%32 = getelementptr inbounds i64, i64* %0, i64 %31
store i64 %30, i64* %32
%33 = call double @cos(double %23)
%34 = call double @llvm.fmuladd.f64(double %27, double %33, double 5.000000e-01)
%35 = call i64 @floor(double %34)
%36 = or i64 %31, 1
%37 = getelementptr inbounds i64, i64* %0, i64 %36
store i64 %35, i64* %37
%38 = add nuw nsw i64 %11, 1
%39 = icmp eq i64 %38, %9
br i1 %39, label %40, label %10
40: ; preds = %10, %3
%41 = srem i32 %1, 2
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %66
43: ; preds = %40
%44 = call i32 @rng_uint64(i64* %4)
%45 = load i64, i64* %4
%46 = and i64 %45, 268435455
%47 = add nuw nsw i64 %46, 1
%48 = sitofp i64 %47 to double
%49 = fmul double %48, 0x3E30000000000000
%50 = lshr i64 %45, 32
%51 = and i64 %50, 268435455
%52 = add nuw nsw i64 %51, 1
%53 = sitofp i64 %52 to double
%54 = fmul double %53, 0x3E30000000000000
%55 = fmul double %49, 0x401921FB54442D18
%56 = call double @log(double %54)
%57 = fmul double %56, -2.000000e+00
%58 = call double @sqrt(double %57)
%59 = fmul double %58, %2
%60 = call double @sin(double %55)
%61 = call double @llvm.fmuladd.f64(double %59, double %60, double 5.000000e-01)
%62 = call i64 @floor(double %61)
%63 = add nsw i32 %1, -1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i64, i64* %0, i64 %64
store i64 %62, i64* %65
br label %66
66: ; preds = %43, %40
ret void
}