#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 int uint_fast16_t;
typedef int /*<<< orphan*/ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ condKappaMu(int, int, double *, double *, double *, double *,
                               double *, double *);
int /*<<< orphan*/ memcpy(double *, double *, int);
double rvm_s_r(double, double, int /*<<< orphan*/ *);
int xorshift4096_r(int /*<<< orphan*/ *);
int mvvm_sampler_safe_rsgibbs(int n, int p, double *mu, double *kappa,
                              double *lambda, int prec, int *alphaTable,
                              int thinning, double *theta, uint64_t *seeds,
                              double *ret) {
  double mu_c, kappa_c;
  uint_fast16_t i, j;
  for (i = 1; i <= n; i++) {
    j = alphaTable[xorshift4096_r(seeds) % prec];
    condKappaMu(p, j, theta, mu, kappa, lambda, &mu_c, &kappa_c);
    theta[j] = rvm_s_r(mu_c, kappa_c, seeds);
    if (i % thinning == 0)
      memcpy(ret + ((i / thinning) - 1) * p, theta, sizeof(double) * p);
  }
  return (0);
}


x86 assembly (clang, -O0):
<mvvm_sampler_safe_rsgibbs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1243 <mvvm_sampler_safe_rsgibbs+0x103>
mov    0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x28(%rbp),%rdi
call   1040 <xorshift4096_r@plt>
cltd
idivl  -0x24(%rbp)
mov    -0x48(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x40(%rbp),%esi
mov    0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    -0x30(%rbp),%r10
lea    -0x38(%rbp),%rax
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1030 <condKappaMu@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mov    0x28(%rbp),%rdi
call   1060 <rvm_s_r@plt>
mov    0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
cltd
idivl  0x18(%rbp)
cmp    $0x0,%edx
jne    1230 <mvvm_sampler_safe_rsgibbs+0xf0>
mov    0x30(%rbp),%rdi
mov    -0x3c(%rbp),%eax
cltd
idivl  0x18(%rbp)
sub    $0x1,%eax
imul   -0x8(%rbp),%eax
cltq
shl    $0x3,%rax
add    %rax,%rdi
mov    0x20(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
jmp    1235 <mvvm_sampler_safe_rsgibbs+0xf5>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1178 <mvvm_sampler_safe_rsgibbs+0x38>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mvvm_sampler_safe_rsgibbs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8,0x20(%rsp)
mov    %rcx,0x18(%rsp)
mov    %rdx,0x10(%rsp)
test   %edi,%edi
jle    124d <mvvm_sampler_safe_rsgibbs+0x10d>
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x88(%rsp),%r14
mov    0x80(%rsp),%r15
lea    0x0(,%rbp,8),%eax
mov    %eax,0x8(%rsp)
neg    %ebx
mov    $0x1,%r12d
jmp    11b9 <mvvm_sampler_safe_rsgibbs+0x79>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%rbx,%r12,1),%eax
add    $0x1,%eax
mov    %r12d,%ecx
add    $0x1,%ecx
mov    %ecx,%r12d
cmp    $0x1,%eax
je     124d <mvvm_sampler_safe_rsgibbs+0x10d>
mov    %r14,%rdi
call   1040 <xorshift4096_r@plt>
cltd
idivl  0xc(%rsp)
movslq %edx,%rax
mov    0x70(%rsp),%rcx
movslq (%rcx,%rax,4),%r13
mov    %ebp,%edi
mov    %r13d,%esi
mov    %r15,%rdx
mov    0x10(%rsp),%rcx
mov    0x18(%rsp),%r8
mov    0x20(%rsp),%r9
lea    0x28(%rsp),%rax
push   %rax
lea    0x38(%rsp),%rax
push   %rax
call   1030 <condKappaMu@plt>
add    $0x10,%rsp
movsd  0x30(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
mov    %r14,%rdi
call   1060 <rvm_s_r@plt>
movsd  %xmm0,(%r15,%r13,8)
mov    %r12d,%eax
cltd
idivl  0x78(%rsp)
test   %edx,%edx
jne    11a0 <mvvm_sampler_safe_rsgibbs+0x60>
add    $0xffffffff,%eax
imul   %ebp,%eax
cltq
mov    0x90(%rsp),%rcx
lea    (%rcx,%rax,8),%rdi
mov    %r15,%rsi
mov    0x8(%rsp),%edx
call   1050 <memcpy@plt>
jmp    11a0 <mvvm_sampler_safe_rsgibbs+0x60>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mvvm_sampler_safe_rsgibbs(i32 %0, i32 %1, double* %2, double* %3, double* %4, i32 %5, i32* %6, i32 %7, double* %8, i32* %9, double* %10) {
%12 = alloca i32
%13 = alloca i32
%14 = alloca double*
%15 = alloca double*
%16 = alloca double*
%17 = alloca i32
%18 = alloca i32*
%19 = alloca i32
%20 = alloca double*
%21 = alloca i32*
%22 = alloca double*
%23 = alloca double
%24 = alloca double
%25 = alloca i32
%26 = alloca i32
store i32 %0, i32* %12
store i32 %1, i32* %13
store double* %2, double** %14
store double* %3, double** %15
store double* %4, double** %16
store i32 %5, i32* %17
store i32* %6, i32** %18
store i32 %7, i32* %19
store double* %8, double** %20
store i32* %9, i32** %21
store double* %10, double** %22
store i32 1, i32* %25
br label %27
27: ; preds = %76, %11
%28 = load i32, i32* %25
%29 = load i32, i32* %12
%30 = icmp sle i32 %28, %29
br i1 %30, label %31, label %79
31: ; preds = %27
%32 = load i32*, i32** %18
%33 = load i32*, i32** %21
%34 = call i32 @xorshift4096_r(i32* %33)
%35 = load i32, i32* %17
%36 = srem i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %32, i64 %37
%39 = load i32, i32* %38
store i32 %39, i32* %26
%40 = load i32, i32* %13
%41 = load i32, i32* %26
%42 = load double*, double** %20
%43 = load double*, double** %14
%44 = load double*, double** %15
%45 = load double*, double** %16
%46 = call i32 @condKappaMu(i32 %40, i32 %41, double* %42, double* %43, double* %44, double* %45, double* %23, double* %24)
%47 = load double, double* %23
%48 = load double, double* %24
%49 = load i32*, i32** %21
%50 = call double @rvm_s_r(double %47, double %48, i32* %49)
%51 = load double*, double** %20
%52 = load i32, i32* %26
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
store double %50, double* %54
%55 = load i32, i32* %25
%56 = load i32, i32* %19
%57 = srem i32 %55, %56
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %75
59: ; preds = %31
%60 = load double*, double** %22
%61 = load i32, i32* %25
%62 = load i32, i32* %19
%63 = sdiv i32 %61, %62
%64 = sub nsw i32 %63, 1
%65 = load i32, i32* %13
%66 = mul nsw i32 %64, %65
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %60, i64 %67
%69 = load double*, double** %20
%70 = load i32, i32* %13
%71 = sext i32 %70 to i64
%72 = mul i64 8, %71
%73 = trunc i64 %72 to i32
%74 = call i32 @memcpy(double* %68, double* %69, i32 %73)
br label %75
75: ; preds = %59, %31
br label %76
76: ; preds = %75
%77 = load i32, i32* %25
%78 = add nsw i32 %77, 1
store i32 %78, i32* %25
br label %27
79: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
define i32 @mvvm_sampler_safe_rsgibbs(i32 %0, i32 %1, double* %2, double* %3, double* %4, i32 %5, i32* nocapture %6, i32 %7, double* %8, i32* %9, double* %10) {
%12 = alloca double
%13 = alloca double
%14 = bitcast double* %12 to i8*
%15 = bitcast double* %13 to i8*
%16 = icmp slt i32 %0, 1
br i1 %16, label %44, label %17
17: ; preds = %11
%18 = shl i32 %1, 3
br label %19
19: ; preds = %17, %41
%20 = phi i32 [ 1, %17 ], [ %42, %41 ]
%21 = call i32 @xorshift4096_r(i32* %9)
%22 = srem i32 %21, %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %6, i64 %23
%25 = load i32, i32* %24
%26 = call i32 @condKappaMu(i32 %1, i32 %25, double* %8, double* %2, double* %3, double* %4, double* %12, double* %13)
%27 = load double, double* %12
%28 = load double, double* %13
%29 = call double @rvm_s_r(double %27, double %28, i32* %9)
%30 = sext i32 %25 to i64
%31 = getelementptr inbounds double, double* %8, i64 %30
store double %29, double* %31
%32 = srem i32 %20, %7
%33 = sdiv i32 %20, %7
%34 = icmp eq i32 %32, 0
br i1 %34, label %35, label %41
35: ; preds = %19
%36 = add nsw i32 %33, -1
%37 = mul nsw i32 %36, %1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %10, i64 %38
%40 = call i32 @memcpy(double* %39, double* %8, i32 %18)
br label %41
41: ; preds = %19, %35
%42 = add nuw i32 %20, 1
%43 = icmp eq i32 %20, %0
br i1 %43, label %44, label %19
44: ; preds = %41, %11
ret i32 0
}