#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 */
int /*<<< orphan*/ normalize(double *, double *, int);
double normrand(int /*<<< orphan*/, int);
void bingham_sample_uniform(double **X, int d, int n) {
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < d; j++)
      X[i][j] = normrand(0, 1);
    normalize(X[i], X[i], d);
  }
}


x86 assembly (clang, -O0):
<bingham_sample_uniform>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11b5 <bingham_sample_uniform+0x95>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1187 <bingham_sample_uniform+0x67>
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <normrand@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114c <bingham_sample_uniform+0x2c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0xc(%rbp),%edx
call   1030 <normalize@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <bingham_sample_uniform+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bingham_sample_uniform>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1180 <bingham_sample_uniform+0x60>
mov    %esi,%r15d
mov    %rdi,%r12
mov    %edx,%r14d
mov    %esi,%r13d
xor    %ebx,%ebx
jmp    1158 <bingham_sample_uniform+0x38>
nop
mov    (%r12,%rbx,8),%rdi
mov    %rdi,%rsi
mov    %r15d,%edx
call   1030 <normalize@plt>
add    $0x1,%rbx
cmp    %r14,%rbx
je     1180 <bingham_sample_uniform+0x60>
test   %r15d,%r15d
jle    1140 <bingham_sample_uniform+0x20>
xor    %ebp,%ebp
nop
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <normrand@plt>
mov    (%r12,%rbx,8),%rdi
movsd  %xmm0,(%rdi,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1160 <bingham_sample_uniform+0x40>
jmp    1144 <bingham_sample_uniform+0x24>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @bingham_sample_uniform(double** %0, i32 %1, i32 %2) {
%4 = alloca double**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store double** %0, double*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %44, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %47
13: ; preds = %9
store i32 0, i32* %8
br label %14
14: ; preds = %28, %13
%15 = load i32, i32* %8
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = call double @normrand(i32 0, i32 1)
%20 = load double**, double*** %4
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double*, double** %20, i64 %22
%24 = load double*, double** %23
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
store double %19, double* %27
br label %28
28: ; preds = %18
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %14
31: ; preds = %14
%32 = load double**, double*** %4
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double*, double** %32, i64 %34
%36 = load double*, double** %35
%37 = load double**, double*** %4
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double*, double** %37, i64 %39
%41 = load double*, double** %40
%42 = load i32, i32* %5
%43 = call i32 @normalize(double* %36, double* %41, i32 %42)
br label %44
44: ; preds = %31
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %9
47: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @bingham_sample_uniform(double** nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %26
5: ; preds = %3
%6 = icmp sgt i32 %1, 0
%7 = zext i32 %2 to i64
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %5, %21
%10 = phi i64 [ 0, %5 ], [ %24, %21 ]
%11 = getelementptr inbounds double*, double** %0, i64 %10
br i1 %6, label %14, label %12
12: ; preds = %9
%13 = load double*, double** %11
br label %21
14: ; preds = %9, %14
%15 = phi i64 [ %19, %14 ], [ 0, %9 ]
%16 = tail call double @normrand(i32 0, i32 1)
%17 = load double*, double** %11
%18 = getelementptr inbounds double, double* %17, i64 %15
store double %16, double* %18
%19 = add nuw nsw i64 %15, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %21, label %14
21: ; preds = %14, %12
%22 = phi double* [ %13, %12 ], [ %17, %14 ]
%23 = tail call i32 @normalize(double* %22, double* %22, i32 %1)
%24 = add nuw nsw i64 %10, 1
%25 = icmp eq i64 %24, %7
br i1 %25, label %26, label %9
26: ; preds = %21, %3
ret void
}