#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 K;

/* Variables and functions */
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sample_Delta(double *, double *, int);
void resample_post_theta(int D, int K, int **M, int *N, double **post_theta,
                         int ***z) {
  int d_9;
  double *tmpSP7;
  int n_3;
  int m_75;
  int dvv_loop_var_1;
  tmpSP7 = (double *)malloc(sizeof(double) * (1 + ((K) + (1)) - (1)));
  for (d_9 = 1; d_9 <= D; d_9++) {
    for (dvv_loop_var_1 = 1; dvv_loop_var_1 <= K; dvv_loop_var_1++) {
      tmpSP7[dvv_loop_var_1 - 1] = 0.0;
    }
    tmpSP7[(K) + (1) - 1] = (0.0) * (((1) + (K)) - (1));
    for (n_3 = 1; n_3 <= N[d_9 - 1]; n_3++) {
      for (m_75 = 1; m_75 <= M[d_9 - 1][n_3 - 1]; m_75++) {
        tmpSP7[(K) + (1) - 1] += 1.0;
        tmpSP7[z[d_9 - 1][n_3 - 1][m_75 - 1] - 1] += 1.0;
      }
    }
    sample_Delta(post_theta[d_9 - 1], tmpSP7, K);
  }
  free(tmpSP7);
}


x86 assembly (clang, -O0):
<resample_post_theta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
add    $0x1,%eax
sub    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     12de <resample_post_theta+0x1ae>
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11b4 <resample_post_theta+0x84>
mov    -0x38(%rbp),%rax
mov    -0x44(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1185 <resample_post_theta+0x55>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
xorps  %xmm0,%xmm0
mulsd  %xmm1,%xmm0
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    -0x2c(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jg     12b3 <resample_post_theta+0x183>
movl   $0x1,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    -0x2c(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,8),%rcx
mov    -0x3c(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,4),%eax
jg     12a0 <resample_post_theta+0x170>
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  0xdbe(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,8),%rcx
mov    -0x3c(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,8),%rcx
mov    -0x40(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
mov    (%rcx,%rdx,4),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  0xd78(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1204 <resample_post_theta+0xd4>
jmp    12a5 <resample_post_theta+0x175>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e4 <resample_post_theta+0xb4>
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1040 <sample_Delta@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1172 <resample_post_theta+0x42>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resample_post_theta>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r13
mov    %r8,0x30(%rsp)
mov    %rcx,0x28(%rsp)
mov    %rdx,0x10(%rsp)
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x8(,%rbx,8),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rbp,(%rsp)
test   %ebp,%ebp
jle    1314 <resample_post_theta+0x1d4>
cvtsi2sd %ebx,%xmm0
xorpd  %xmm1,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movslq %ebx,%r14
mov    %ebx,%eax
shl    $0x3,%rax
mov    %rax,0x8(%rsp)
mov    (%rsp),%rax
add    $0x1,%eax
mov    %rax,(%rsp)
mov    $0x1,%r15d
movsd  0xe48(%rip),%xmm1
mov    %rbx,0x20(%rsp)
jmp    11ef <resample_post_theta+0xaf>
nop
mov    0x30(%rsp),%rax
mov    -0x8(%rax,%r15,8),%rdi
mov    %r12,%rsi
mov    0x20(%rsp),%rbx
mov    %ebx,%edx
call   1050 <sample_Delta@plt>
movsd  0xe1f(%rip),%xmm1
add    $0x1,%r15
cmp    (%rsp),%r15
je     1314 <resample_post_theta+0x1d4>
test   %ebx,%ebx
jle    120a <resample_post_theta+0xca>
mov    %r12,%rdi
xor    %esi,%esi
mov    0x8(%rsp),%rdx
call   1040 <memset@plt>
movsd  0xdf6(%rip),%xmm1
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,(%r12,%r14,8)
mov    0x28(%rsp),%rax
mov    -0x4(%rax,%r15,4),%eax
test   %eax,%eax
jle    11c0 <resample_post_theta+0x80>
mov    0x10(%rsp),%rcx
mov    -0x8(%rcx,%r15,8),%r8
add    $0x1,%rax
mov    $0x1,%edx
jmp    124d <resample_post_theta+0x10d>
nopl   0x0(%rax)
add    $0x1,%rdx
cmp    %rax,%rdx
je     11c0 <resample_post_theta+0x80>
mov    -0x4(%r8,%rdx,4),%ebx
test   %ebx,%ebx
jle    1240 <resample_post_theta+0x100>
mov    -0x8(%r13,%r15,8),%rsi
mov    -0x8(%rsi,%rdx,8),%rdi
mov    $0x1,%ebp
cmp    $0x1,%ebx
je     12df <resample_post_theta+0x19f>
mov    %ebx,%esi
and    $0xfffffffe,%esi
neg    %rsi
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
movsd  (%r12,%r14,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r12,%r14,8)
movslq -0x4(%rdi,%rbp,4),%rcx
movsd  -0x8(%r12,%rcx,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%r12,%rcx,8)
movsd  (%r12,%r14,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r12,%r14,8)
movslq (%rdi,%rbp,4),%rcx
movsd  -0x8(%r12,%rcx,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%r12,%rcx,8)
lea    (%rsi,%rbp,1),%rcx
add    $0x2,%rcx
add    $0x2,%rbp
cmp    $0x1,%rcx
jne    1280 <resample_post_theta+0x140>
test   $0x1,%bl
je     1240 <resample_post_theta+0x100>
movsd  (%r12,%r14,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r12,%r14,8)
movslq -0x4(%rdi,%rbp,4),%rcx
movsd  -0x8(%r12,%rcx,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%r12,%rcx,8)
jmp    1240 <resample_post_theta+0x100>
mov    %r12,%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @resample_post_theta(i32 %0, i32 %1, i32** %2, i32* %3, double** %4, i32*** %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32**
%10 = alloca i32*
%11 = alloca double**
%12 = alloca i32***
%13 = alloca i32
%14 = alloca double*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32** %2, i32*** %9
store i32* %3, i32** %10
store double** %4, double*** %11
store i32*** %5, i32**** %12
%18 = load i32, i32* %8
%19 = add nsw i32 %18, 1
%20 = add nsw i32 1, %19
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = mul i64 8, %22
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to double*
store double* %26, double** %14
store i32 1, i32* %13
br label %27
27: ; preds = %129, %6
%28 = load i32, i32* %13
%29 = load i32, i32* %7
%30 = icmp sle i32 %28, %29
br i1 %30, label %31, label %132
31: ; preds = %27
store i32 1, i32* %17
br label %32
32: ; preds = %42, %31
%33 = load i32, i32* %17
%34 = load i32, i32* %8
%35 = icmp sle i32 %33, %34
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load double*, double** %14
%38 = load i32, i32* %17
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %37, i64 %40
store double 0.000000e+00, double* %41
br label %42
42: ; preds = %36
%43 = load i32, i32* %17
%44 = add nsw i32 %43, 1
store i32 %44, i32* %17
br label %32
45: ; preds = %32
%46 = load i32, i32* %8
%47 = add nsw i32 1, %46
%48 = sub nsw i32 %47, 1
%49 = sitofp i32 %48 to double
%50 = fmul double 0.000000e+00, %49
%51 = load double*, double** %14
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
%54 = sub nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %51, i64 %55
store double %50, double* %56
store i32 1, i32* %15
br label %57
57: ; preds = %116, %45
%58 = load i32, i32* %15
%59 = load i32*, i32** %10
%60 = load i32, i32* %13
%61 = sub nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %59, i64 %62
%64 = load i32, i32* %63
%65 = icmp sle i32 %58, %64
br i1 %65, label %66, label %119
66: ; preds = %57
store i32 1, i32* %16
br label %67
67: ; preds = %112, %66
%68 = load i32, i32* %16
%69 = load i32**, i32*** %9
%70 = load i32, i32* %13
%71 = sub nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32*, i32** %69, i64 %72
%74 = load i32*, i32** %73
%75 = load i32, i32* %15
%76 = sub nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %74, i64 %77
%79 = load i32, i32* %78
%80 = icmp sle i32 %68, %79
br i1 %80, label %81, label %115
81: ; preds = %67
%82 = load double*, double** %14
%83 = load i32, i32* %8
%84 = add nsw i32 %83, 1
%85 = sub nsw i32 %84, 1
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds double, double* %82, i64 %86
%88 = load double, double* %87
%89 = fadd double %88, 1.000000e+00
store double %89, double* %87
%90 = load double*, double** %14
%91 = load i32***, i32**** %12
%92 = load i32, i32* %13
%93 = sub nsw i32 %92, 1
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i32**, i32*** %91, i64 %94
%96 = load i32**, i32*** %95
%97 = load i32, i32* %15
%98 = sub nsw i32 %97, 1
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i32*, i32** %96, i64 %99
%101 = load i32*, i32** %100
%102 = load i32, i32* %16
%103 = sub nsw i32 %102, 1
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i32, i32* %101, i64 %104
%106 = load i32, i32* %105
%107 = sub nsw i32 %106, 1
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds double, double* %90, i64 %108
%110 = load double, double* %109
%111 = fadd double %110, 1.000000e+00
store double %111, double* %109
br label %112
112: ; preds = %81
%113 = load i32, i32* %16
%114 = add nsw i32 %113, 1
store i32 %114, i32* %16
br label %67
115: ; preds = %67
br label %116
116: ; preds = %115
%117 = load i32, i32* %15
%118 = add nsw i32 %117, 1
store i32 %118, i32* %15
br label %57
119: ; preds = %57
%120 = load double**, double*** %11
%121 = load i32, i32* %13
%122 = sub nsw i32 %121, 1
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds double*, double** %120, i64 %123
%125 = load double*, double** %124
%126 = load double*, double** %14
%127 = load i32, i32* %8
%128 = call i32 @sample_Delta(double* %125, double* %126, i32 %127)
br label %129
129: ; preds = %119
%130 = load i32, i32* %13
%131 = add nsw i32 %130, 1
store i32 %131, i32* %13
br label %27
132: ; preds = %27
%133 = load double*, double** %14
%134 = call i32 @free(double* %133)
ret void
}

LLVM IR (-O2):
define void @resample_post_theta(i32 %0, i32 %1, i32** nocapture %2, i32* nocapture %3, double** nocapture %4, i32*** nocapture %5) {
%7 = shl i32 %1, 3
%8 = add i32 %7, 8
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to double*
%11 = inttoptr i64 %9 to i8*
%12 = icmp slt i32 %0, 1
br i1 %12, label %100, label %13
13: ; preds = %6
%14 = icmp slt i32 %1, 1
%15 = sitofp i32 %1 to double
%16 = fmul double %15, 0.000000e+00
%17 = sext i32 %1 to i64
%18 = getelementptr inbounds double, double* %10, i64 %17
%19 = zext i32 %1 to i64
%20 = shl nuw nsw i64 %19, 3
%21 = add nuw i32 %0, 1
%22 = zext i32 %21 to i64
br label %23
23: ; preds = %13, %94
%24 = phi i64 [ 1, %13 ], [ %98, %94 ]
br i1 %14, label %26, label %25
25: ; preds = %23
br label %26
26: ; preds = %25, %23
store double %16, double* %18
%27 = add nsw i64 %24, -1
%28 = getelementptr inbounds i32, i32* %3, i64 %27
%29 = load i32, i32* %28
%30 = icmp slt i32 %29, 1
br i1 %30, label %94, label %31
31: ; preds = %26
%32 = getelementptr inbounds i32*, i32** %2, i64 %27
%33 = load i32*, i32** %32
%34 = getelementptr inbounds i32**, i32*** %5, i64 %27
%35 = add nuw i32 %29, 1
%36 = zext i32 %35 to i64
br label %37
37: ; preds = %31, %91
%38 = phi i64 [ 1, %31 ], [ %92, %91 ]
%39 = add nsw i64 %38, -1
%40 = getelementptr inbounds i32, i32* %33, i64 %39
%41 = load i32, i32* %40
%42 = icmp slt i32 %41, 1
br i1 %42, label %91, label %43
43: ; preds = %37
%44 = load i32**, i32*** %34
%45 = getelementptr inbounds i32*, i32** %44, i64 %39
%46 = load i32*, i32** %45
%47 = zext i32 %41 to i64
%48 = and i64 %47, 1
%49 = icmp eq i32 %41, 1
br i1 %49, label %77, label %50
50: ; preds = %43
%51 = and i64 %47, 4294967294
br label %52
52: ; preds = %52, %50
%53 = phi i64 [ 1, %50 ], [ %74, %52 ]
%54 = phi i64 [ 0, %50 ], [ %75, %52 ]
%55 = load double, double* %18
%56 = fadd double %55, 1.000000e+00
store double %56, double* %18
%57 = add nsw i64 %53, -1
%58 = getelementptr inbounds i32, i32* %46, i64 %57
%59 = load i32, i32* %58
%60 = add nsw i32 %59, -1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %10, i64 %61
%63 = load double, double* %62
%64 = fadd double %63, 1.000000e+00
store double %64, double* %62
%65 = load double, double* %18
%66 = fadd double %65, 1.000000e+00
store double %66, double* %18
%67 = getelementptr inbounds i32, i32* %46, i64 %53
%68 = load i32, i32* %67
%69 = add nsw i32 %68, -1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds double, double* %10, i64 %70
%72 = load double, double* %71
%73 = fadd double %72, 1.000000e+00
store double %73, double* %71
%74 = add nuw nsw i64 %53, 2
%75 = add i64 %54, 2
%76 = icmp eq i64 %75, %51
br i1 %76, label %77, label %52
77: ; preds = %52, %43
%78 = phi i64 [ 1, %43 ], [ %74, %52 ]
%79 = icmp eq i64 %48, 0
br i1 %79, label %91, label %80
80: ; preds = %77
%81 = load double, double* %18
%82 = fadd double %81, 1.000000e+00
store double %82, double* %18
%83 = add nsw i64 %78, -1
%84 = getelementptr inbounds i32, i32* %46, i64 %83
%85 = load i32, i32* %84
%86 = add nsw i32 %85, -1
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %10, i64 %87
%89 = load double, double* %88
%90 = fadd double %89, 1.000000e+00
store double %90, double* %88
br label %91
91: ; preds = %80, %77, %37
%92 = add nuw nsw i64 %38, 1
%93 = icmp eq i64 %92, %36
br i1 %93, label %94, label %37
94: ; preds = %91, %26
%95 = getelementptr inbounds double*, double** %4, i64 %27
%96 = load double*, double** %95
%97 = tail call i32 @sample_Delta(double* %96, double* %10, i32 %1)
%98 = add nuw nsw i64 %24, 1
%99 = icmp eq i64 %98, %22
br i1 %99, label %100, label %23
100: ; preds = %94, %6
%101 = tail call i32 @free(double* %10)
ret void
}