#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 alpha;
typedef size_t K;

/* Variables and functions */
scalar_t__ log(double);
double sample_Gam(double, double);
double resample_alpha(int D, int K, double alpha, double **post_theta) {
  double tmpSP0;
  int d_0;
  int cgds;
  tmpSP0 = 0.0;
  for (d_0 = 1; d_0 <= D; d_0++) {
    for (cgds = 1; cgds <= K; cgds++) {
      tmpSP0 += log(((1.0) / ((alpha) + (post_theta[d_0 - 1][(K) + (1) - 1]))) *
                    ((alpha) + (post_theta[d_0 - 1][cgds - 1])));
    }
  }
  alpha = sample_Gam(0.1, (1.0) / ((1.0) - ((1.0) / (tmpSP0))));
  return (alpha);
}


x86 assembly (clang, -O0):
<resample_alpha>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11f5 <resample_alpha+0xd5>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11e2 <resample_alpha+0xc2>
movsd  -0x10(%rbp),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm1
movsd  0xe74(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
addsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <log@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1159 <resample_alpha+0x39>
jmp    11e7 <resample_alpha+0xc7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1146 <resample_alpha+0x26>
movsd  0xe0b(%rip),%xmm1
divsd  -0x20(%rbp),%xmm1
movsd  0xdfe(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  0xdf2(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  0xdde(%rip),%xmm0
call   1030 <sample_Gam@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resample_alpha>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    11e7 <resample_alpha+0xc7>
mov    %rdx,%r12
movapd %xmm0,%xmm2
mov    %edi,%r15d
movslq %esi,%r13
lea    0x1(%r13),%ebx
add    $0x1,%r15d
add    $0xffffffffffffffff,%rbx
xorpd  %xmm3,%xmm3
mov    $0x1,%ebp
mov    %esi,0x4(%rsp)
movsd  %xmm0,0x8(%rsp)
jmp    1180 <resample_alpha+0x60>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbp
mov    %r15,%rax
cmp    %r15,%rbp
mov    0x4(%rsp),%esi
je     11eb <resample_alpha+0xcb>
test   %esi,%esi
jle    1170 <resample_alpha+0x50>
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
movsd  %xmm3,0x10(%rsp)
mov    -0x8(%r12,%rbp,8),%rax
movsd  (%rax,%r13,8),%xmm0
addsd  %xmm2,%xmm0
movsd  0xe53(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  (%rax,%r14,8),%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
call   1040 <log@plt>
movsd  0x10(%rsp),%xmm3
movsd  0x8(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm3
add    $0x1,%r14
cmp    %r14,%rbx
jne    1190 <resample_alpha+0x70>
jmp    1170 <resample_alpha+0x50>
xorpd  %xmm3,%xmm3
movsd  0xe0d(%rip),%xmm1
movapd %xmm1,%xmm0
divsd  %xmm3,%xmm0
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
divsd  %xmm2,%xmm1
movsd  0xdf9(%rip),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <sample_Gam@plt>

LLVM IR (-O0):
define double @resample_alpha(i32 %0, i32 %1, double %2, double** %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double**
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store double %2, double* %7
store double** %3, double*** %8
store double 0.000000e+00, double* %9
store i32 1, i32* %10
br label %12
12: ; preds = %59, %4
%13 = load i32, i32* %10
%14 = load i32, i32* %5
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %62
16: ; preds = %12
store i32 1, i32* %11
br label %17
17: ; preds = %55, %16
%18 = load i32, i32* %11
%19 = load i32, i32* %6
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %58
21: ; preds = %17
%22 = load double, double* %7
%23 = load double**, double*** %8
%24 = load i32, i32* %10
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double*, double** %23, i64 %26
%28 = load double*, double** %27
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds double, double* %28, i64 %32
%34 = load double, double* %33
%35 = fadd double %22, %34
%36 = fdiv double 1.000000e+00, %35
%37 = load double, double* %7
%38 = load double**, double*** %8
%39 = load i32, i32* %10
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double*, double** %38, i64 %41
%43 = load double*, double** %42
%44 = load i32, i32* %11
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %43, i64 %46
%48 = load double, double* %47
%49 = fadd double %37, %48
%50 = fmul double %36, %49
%51 = call i64 @log(double %50)
%52 = sitofp i64 %51 to double
%53 = load double, double* %9
%54 = fadd double %53, %52
store double %54, double* %9
br label %55
55: ; preds = %21
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
br label %17
58: ; preds = %17
br label %59
59: ; preds = %58
%60 = load i32, i32* %10
%61 = add nsw i32 %60, 1
store i32 %61, i32* %10
br label %12
62: ; preds = %12
%63 = load double, double* %9
%64 = fdiv double 1.000000e+00, %63
%65 = fsub double 1.000000e+00, %64
%66 = fdiv double 1.000000e+00, %65
%67 = call double @sample_Gam(double 1.000000e-01, double %66)
store double %67, double* %7
%68 = load double, double* %7
ret double %68
}

LLVM IR (-O2):
define double @resample_alpha(i32 %0, i32 %1, double %2, double** nocapture %3) {
%5 = icmp slt i32 %0, 1
br i1 %5, label %41, label %6
6: ; preds = %4
%7 = icmp slt i32 %1, 1
%8 = sext i32 %1 to i64
%9 = add i32 %1, 1
%10 = add nuw i32 %0, 1
%11 = zext i32 %10 to i64
%12 = zext i32 %9 to i64
br label %13
13: ; preds = %6, %37
%14 = phi i64 [ 1, %6 ], [ %39, %37 ]
%15 = phi double [ 0.000000e+00, %6 ], [ %38, %37 ]
br i1 %7, label %37, label %16
16: ; preds = %13
%17 = add nsw i64 %14, -1
%18 = getelementptr inbounds double*, double** %3, i64 %17
br label %19
19: ; preds = %16, %19
%20 = phi i64 [ 1, %16 ], [ %35, %19 ]
%21 = phi double [ %15, %16 ], [ %34, %19 ]
%22 = load double*, double** %18
%23 = getelementptr inbounds double, double* %22, i64 %8
%24 = load double, double* %23
%25 = fadd double %24, %2
%26 = fdiv double 1.000000e+00, %25
%27 = add nsw i64 %20, -1
%28 = getelementptr inbounds double, double* %22, i64 %27
%29 = load double, double* %28
%30 = fadd double %29, %2
%31 = fmul double %26, %30
%32 = tail call i64 @log(double %31)
%33 = sitofp i64 %32 to double
%34 = fadd double %21, %33
%35 = add nuw nsw i64 %20, 1
%36 = icmp eq i64 %35, %12
br i1 %36, label %37, label %19
37: ; preds = %19, %13
%38 = phi double [ %15, %13 ], [ %34, %19 ]
%39 = add nuw nsw i64 %14, 1
%40 = icmp eq i64 %39, %11
br i1 %40, label %41, label %13
41: ; preds = %37, %4
%42 = phi double [ 0.000000e+00, %4 ], [ %38, %37 ]
%43 = fdiv double 1.000000e+00, %42
%44 = fsub double 1.000000e+00, %43
%45 = fdiv double 1.000000e+00, %44
%46 = tail call double @sample_Gam(double 1.000000e-01, double %45)
ret double %46
}