#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 uint64_t;
typedef long const uint32_t;
typedef int uint16_t;
typedef scalar_t__ int64_t;

/* Variables and functions */
double cos(double);
int /*<<< orphan*/ crypto_hash_sha512(unsigned char *, unsigned char *, int);
scalar_t__ floor(double);
double log(double);
double sin(double);
double const sqrt(double);
void DDGS(int64_t *v, const uint16_t dim, const uint64_t stdev,
          unsigned char *seed, size_t seed_len) {
  uint16_t i, j;
  uint32_t *t;
  static double const Pi = 3.141592653589793238462643383279502884L;
  static long const bignum = 0xfffffff;
  double r1, r2, theta, rr;
  unsigned char pool[64];
  crypto_hash_sha512(pool, seed, seed_len);
  t = (uint32_t *)pool;
  for (i = 0; i < 64; i++) {
    for (j = 0; j < 8; j++) {
      r1 = (1 + (t[j * 2] & bignum)) / ((double)bignum + 1);
      r2 = (1 + (t[j * 2 + 1] & bignum)) / ((double)bignum + 1);
      theta = 2 * Pi * r1;
      rr = sqrt(-2.0 * log(r2)) * stdev;
      v[i * 16 + j * 2] = (int64_t)floor(rr * sin(theta) + 0.5);
      v[i * 16 + j * 2 + 1] = (int64_t)floor(rr * cos(theta) + 0.5);
    }
    crypto_hash_sha512(pool, pool, 64);
  }
}


x86 assembly (clang, -O0):
<DDGS>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
call   1030 <crypto_hash_sha512@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x40,-0x2c(%rbp)
jge    133e <DDGS+0x1de>
movl   $0x0,-0x30(%rbp)
cmpl   $0x8,-0x30(%rbp)
jge    1318 <DDGS+0x1b8>
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
and    $0xfffffff,%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
movsd  0xe2e(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
and    $0xfffffff,%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm0
movsd  0xdfa(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xde1(%rip),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdba(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0xb0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  0xd71(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1080 <floor@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
shl    $0x4,%ecx
mov    -0x30(%rbp),%esi
shl    $0x1,%esi
add    %esi,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0xa8(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
movsd  0xd1e(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1080 <floor@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
shl    $0x4,%ecx
mov    -0x30(%rbp),%esi
shl    $0x1,%esi
add    %esi,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11b8 <DDGS+0x58>
lea    -0xa0(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    $0x40,%edx
call   1030 <crypto_hash_sha512@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a7 <DDGS+0x47>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DDGS>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
movsd  %xmm0,0x18(%rsp)
mov    %rdi,%rbx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1030 <crypto_hash_sha512@plt>
add    $0x8,%rbx
xor    %r15d,%r15d
mov    $0xfffffff,%r12d
jmp    11c2 <DDGS+0x62>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r14,%rsi
mov    $0x40,%edx
call   1030 <crypto_hash_sha512@plt>
add    $0x1,%r15
sub    $0xffffffffffffff80,%rbx
cmp    $0x40,%r15
je     129f <DDGS+0x13f>
xor    %ebp,%ebp
jmp    123b <DDGS+0xdb>
cs nopw 0x0(%rax,%rax,1)
call   1070 <sqrt@plt>
mulsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <sin@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0xe1e(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1080 <floor@plt>
mov    %rax,-0x8(%rbx,%rbp,1)
movsd  0x10(%rsp),%xmm0
call   1050 <cos@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0xdf7(%rip),%xmm0
call   1080 <floor@plt>
mov    %rax,(%rbx,%rbp,1)
add    $0x10,%rbp
cmp    $0x80,%rbp
je     11a0 <DDGS+0x40>
mov    0x20(%rsp,%rbp,1),%eax
and    %r12d,%eax
add    $0x1,%eax
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movsd  0xdac(%rip),%xmm1
mulsd  %xmm1,%xmm2
mov    0x28(%rsp,%rbp,1),%eax
and    %r12d,%eax
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm1,%xmm0
mulsd  0xd93(%rip),%xmm2
movsd  %xmm2,0x10(%rsp)
call   1060 <log@plt>
mulsd  0xd88(%rip),%xmm0
ucomisd 0xd90(%rip),%xmm0
jb     11d0 <DDGS+0x70>
sqrtsd %xmm0,%xmm0
jmp    11d5 <DDGS+0x75>
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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