#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 exp(double);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
double rand();
int /*<<< orphan*/ random_matrix(double *, int, int);
void gaussian_data(double *data, int K, int N, int D) {
  double *center = (double *)malloc(D * sizeof(double));
  for (int i = 0; i < N; i++) {
    if (i % (N / K) == 0) {
      random_matrix(center, N, 1);
    }
    for (int j = 0; j < D; j++) {
      double dx = center[j] - (rand() / (double)RAND_MAX - 0.5) / 2.0;
      data[i * D + j] = exp(-1.0 * dx * dx);
    }
  }
  free(center);
}


x86 assembly (clang, -O0):
<gaussian_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    126d <gaussian_data+0x11d>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ba <gaussian_data+0x6a>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    $0x1,%edx
call   1040 <random_matrix@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    125a <gaussian_data+0x10a>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mov    0x2df3(%rip),%rax
cvtsi2sdq (%rax),%xmm2
divsd  %xmm2,%xmm1
movsd  0xe0a(%rip),%xmm2
subsd  %xmm2,%xmm1
movsd  0xdf6(%rip),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xdd9(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
call   1060 <exp@plt>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c1 <gaussian_data+0x71>
jmp    125f <gaussian_data+0x10f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117f <gaussian_data+0x2f>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gaussian_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%rbp
mov    %rcx,0x8(%rsp)
lea    0x0(,%rcx,8),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,(%rsp)
test   %r14d,%r14d
jle    126f <gaussian_data+0x11f>
mov    (%rsp),%ecx
mov    %ecx,%eax
cltd
idiv   %r12d
mov    %eax,0x4(%rsp)
mov    0x8(%rsp),%rax
movslq %eax,%rdx
mov    %ecx,%ecx
mov    %rcx,0x10(%rsp)
mov    %eax,%r12d
shl    $0x3,%rdx
mov    %rdx,0x18(%rsp)
mov    0x2e31(%rip),%r15
xor    %r13d,%r13d
jmp    11d4 <gaussian_data+0x84>
nopl   0x0(%rax)
add    $0x1,%r13
add    0x18(%rsp),%rbp
cmp    0x10(%rsp),%r13
je     126f <gaussian_data+0x11f>
mov    %r13d,%eax
cltd
idivl  0x4(%rsp)
test   %edx,%edx
je     11f0 <gaussian_data+0xa0>
cmpl   $0x0,0x8(%rsp)
jg     1207 <gaussian_data+0xb7>
jmp    11c0 <gaussian_data+0x70>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    (%rsp),%esi
mov    $0x1,%edx
call   1040 <random_matrix@plt>
cmpl   $0x0,0x8(%rsp)
jle    11c0 <gaussian_data+0x70>
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
movsd  (%rbx,%r14,8),%xmm0
movsd  %xmm0,0x20(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
movsd  0xdc9(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  0x20(%rsp),%xmm0
movapd %xmm0,%xmm1
xorpd  0xdbf(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1060 <exp@plt>
movsd  %xmm0,0x0(%rbp,%r14,8)
add    $0x1,%r14
cmp    %r14,%r12
jne    1210 <gaussian_data+0xc0>
jmp    11c0 <gaussian_data+0x70>
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@RAND_MAX = global i64 0
define void @gaussian_data(double* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca double
store double* %0, double** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %8
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 8
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to double*
store double* %18, double** %9
store i32 0, i32* %10
br label %19
19: ; preds = %69, %4
%20 = load i32, i32* %10
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %72
23: ; preds = %19
%24 = load i32, i32* %10
%25 = load i32, i32* %7
%26 = load i32, i32* %6
%27 = sdiv i32 %25, %26
%28 = srem i32 %24, %27
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %23
%31 = load double*, double** %9
%32 = load i32, i32* %7
%33 = call i32 @random_matrix(double* %31, i32 %32, i32 1)
br label %34
34: ; preds = %30, %23
store i32 0, i32* %11
br label %35
35: ; preds = %65, %34
%36 = load i32, i32* %11
%37 = load i32, i32* %8
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %68
39: ; preds = %35
%40 = load double*, double** %9
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = call double (...) @rand()
%46 = load i64, i64* @RAND_MAX
%47 = sitofp i64 %46 to double
%48 = fdiv double %45, %47
%49 = fsub double %48, 5.000000e-01
%50 = fdiv double %49, 2.000000e+00
%51 = fsub double %44, %50
store double %51, double* %12
%52 = load double, double* %12
%53 = fmul double -1.000000e+00, %52
%54 = load double, double* %12
%55 = fmul double %53, %54
%56 = call double @exp(double %55)
%57 = load double*, double** %5
%58 = load i32, i32* %10
%59 = load i32, i32* %8
%60 = mul nsw i32 %58, %59
%61 = load i32, i32* %11
%62 = add nsw i32 %60, %61
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %57, i64 %63
store double %56, double* %64
br label %65
65: ; preds = %39
%66 = load i32, i32* %11
%67 = add nsw i32 %66, 1
store i32 %67, i32* %11
br label %35
68: ; preds = %35
br label %69
69: ; preds = %68
%70 = load i32, i32* %10
%71 = add nsw i32 %70, 1
store i32 %71, i32* %10
br label %19
72: ; preds = %19
%73 = load double*, double** %9
%74 = call i32 @free(double* %73)
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define void @gaussian_data(double* nocapture writeonly %0, i32 %1, i32 %2, i32 %3) {
%5 = shl i32 %3, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to double*
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %15
9: ; preds = %4
%10 = sdiv i32 %2, %1
%11 = icmp sgt i32 %3, 0
%12 = sext i32 %3 to i64
%13 = zext i32 %2 to i64
%14 = zext i32 %3 to i64
br label %17
15: ; preds = %27, %4
%16 = tail call i32 @free(double* %7)
ret void
17: ; preds = %9, %27
%18 = phi i64 [ 0, %9 ], [ %28, %27 ]
%19 = trunc i64 %18 to i32
%20 = srem i32 %19, %10
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = tail call i32 @random_matrix(double* %7, i32 %2, i32 1)
br label %24
24: ; preds = %22, %17
br i1 %11, label %25, label %27
25: ; preds = %24
%26 = mul nsw i64 %18, %12
br label %30
27: ; preds = %30, %24
%28 = add nuw nsw i64 %18, 1
%29 = icmp eq i64 %28, %13
br i1 %29, label %15, label %17
30: ; preds = %25, %30
%31 = phi i64 [ 0, %25 ], [ %46, %30 ]
%32 = getelementptr inbounds double, double* %7, i64 %31
%33 = load double, double* %32
%34 = tail call double (...) @rand()
%35 = load i64, i64* @RAND_MAX
%36 = sitofp i64 %35 to double
%37 = fdiv double %34, %36
%38 = fadd double %37, -5.000000e-01
%39 = fmul double %38, 5.000000e-01
%40 = fsub double %33, %39
%41 = fneg double %40
%42 = fmul double %40, %41
%43 = tail call double @exp(double %42)
%44 = add nsw i64 %31, %26
%45 = getelementptr inbounds double, double* %0, i64 %44
store double %43, double* %45
%46 = add nuw nsw i64 %31, 1
%47 = icmp eq i64 %46, %14
br i1 %47, label %27, label %30
}