#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*/ exit(int);
double ldf_Mult_smooth(int /*<<< orphan*/, double, int, double *, int, int);
int /*<<< orphan*/ normalizeLog(double *, int, int);
int sample_Mult(double *, int, int);
int sample_Mult_labeled_stop(int w, int s, double **post_beta,
                             double *post_theta, int V, int K, double alpha,
                             double eta, int *labels, int *labelIdx,
                             double *post_z) {
  int nLabels = 0;
  int i, j, z, result;
  j = 0;
  for (i = 1; i <= K; i++) {
    if (labels[i - 1]) {
      labelIdx[j] = i;
      if (s == 1) {
        post_z[j] = (ldf_Mult_smooth(0, eta, w, post_beta[i - 1], 1, V)) +
                    (ldf_Mult_smooth(0, alpha, i, post_theta, 1, K));
      } else if (s == 2) {
        post_z[j] = (ldf_Mult_smooth(0, eta, w, post_beta[i - 1], 1, V));
      } else {
        exit(1);
      }
      j += 1;
    }
  }
  normalizeLog(post_z, 1, j);
  z = sample_Mult(post_z, 1, j);
  result = labelIdx[z - 1];
  return result;
}


x86 assembly (clang, -O0):
<sample_Mult_labeled_stop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
movsd  %xmm1,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     129c <sample_Mult_labeled_stop+0x15c>
mov    0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     1289 <sample_Mult_labeled_stop+0x149>
mov    -0x38(%rbp),%edx
mov    0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
cmpl   $0x1,-0x8(%rbp)
jne    122c <sample_Mult_labeled_stop+0xec>
movsd  -0x30(%rbp),%xmm0
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x1c(%rbp),%r8d
xor    %edi,%edi
mov    $0x1,%ecx
call   1050 <ldf_Mult_smooth@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x38(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%r8d
xor    %edi,%edi
mov    $0x1,%ecx
call   1050 <ldf_Mult_smooth@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
mov    0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1280 <sample_Mult_labeled_stop+0x140>
cmpl   $0x2,-0x8(%rbp)
jne    1271 <sample_Mult_labeled_stop+0x131>
movsd  -0x30(%rbp),%xmm0
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x1c(%rbp),%r8d
xor    %edi,%edi
mov    $0x1,%ecx
call   1050 <ldf_Mult_smooth@plt>
mov    0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    127b <sample_Mult_labeled_stop+0x13b>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1280 <sample_Mult_labeled_stop+0x140>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    128e <sample_Mult_labeled_stop+0x14e>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1189 <sample_Mult_labeled_stop+0x49>
mov    0x20(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    $0x1,%esi
call   1030 <normalizeLog@plt>
mov    0x20(%rbp),%rdi
mov    -0x3c(%rbp),%edx
mov    $0x1,%esi
call   1040 <sample_Mult@plt>
mov    %eax,-0x40(%rbp)
mov    0x18(%rbp),%rax
mov    -0x40(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sample_Mult_labeled_stop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x28(%rsp)
mov    %r8d,0xc(%rsp)
mov    %rcx,0x20(%rsp)
test   %r9d,%r9d
jle    1240 <sample_Mult_labeled_stop+0x100>
mov    %rdx,%rbp
mov    %esi,%r14d
mov    %edi,%r12d
mov    %r9,0x18(%rsp)
lea    0x1(%r9),%r13d
xor    %ebx,%ebx
mov    $0x1,%r15d
jmp    11c8 <sample_Mult_labeled_stop+0x88>
nopl   0x0(%rax)
mov    -0x8(%rbp,%r15,8),%rdx
xor    %edi,%edi
movsd  0x10(%rsp),%xmm0
mov    %r12d,%esi
mov    $0x1,%ecx
mov    0xc(%rsp),%r8d
call   1050 <ldf_Mult_smooth@plt>
mov    0x80(%rsp),%rax
movsd  %xmm0,(%rax,%rbx,8)
add    $0x1,%ebx
add    $0x1,%r15
cmp    %r15,%r13
je     1242 <sample_Mult_labeled_stop+0x102>
mov    0x70(%rsp),%rax
cmpl   $0x0,-0x4(%rax,%r15,4)
je     11bf <sample_Mult_labeled_stop+0x7f>
movslq %ebx,%rbx
mov    0x78(%rsp),%rax
mov    %r15d,(%rax,%rbx,4)
cmp    $0x2,%r14d
je     1190 <sample_Mult_labeled_stop+0x50>
cmp    $0x1,%r14d
jne    1282 <sample_Mult_labeled_stop+0x142>
mov    -0x8(%rbp,%r15,8),%rdx
xor    %edi,%edi
movsd  0x10(%rsp),%xmm0
mov    %r12d,%esi
mov    $0x1,%ecx
mov    0xc(%rsp),%r8d
call   1050 <ldf_Mult_smooth@plt>
movsd  %xmm0,0x30(%rsp)
xor    %edi,%edi
movsd  0x28(%rsp),%xmm0
mov    %r15d,%esi
mov    0x20(%rsp),%rdx
mov    $0x1,%ecx
mov    0x18(%rsp),%r8
call   1050 <ldf_Mult_smooth@plt>
addsd  0x30(%rsp),%xmm0
jmp    11af <sample_Mult_labeled_stop+0x6f>
xor    %ebx,%ebx
mov    0x80(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
call   1030 <normalizeLog@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
call   1040 <sample_Mult@plt>
cltq
mov    0x78(%rsp),%rcx
mov    -0x4(%rcx,%rax,4),%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
define i32 @sample_Mult_labeled_stop(i32 %0, i32 %1, double** %2, double* %3, i32 %4, i32 %5, double %6, double %7, i32* %8, i32* %9, double* %10) {
%12 = alloca i32
%13 = alloca i32
%14 = alloca double**
%15 = alloca double*
%16 = alloca i32
%17 = alloca i32
%18 = alloca double
%19 = alloca double
%20 = alloca i32*
%21 = alloca i32*
%22 = alloca double*
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
store i32 %0, i32* %12
store i32 %1, i32* %13
store double** %2, double*** %14
store double* %3, double** %15
store i32 %4, i32* %16
store i32 %5, i32* %17
store double %6, double* %18
store double %7, double* %19
store i32* %8, i32** %20
store i32* %9, i32** %21
store double* %10, double** %22
store i32 0, i32* %23
store i32 0, i32* %25
store i32 1, i32* %24
br label %28
28: ; preds = %94, %11
%29 = load i32, i32* %24
%30 = load i32, i32* %17
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %97
32: ; preds = %28
%33 = load i32*, i32** %20
%34 = load i32, i32* %24
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %33, i64 %36
%38 = load i32, i32* %37
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %93
40: ; preds = %32
%41 = load i32, i32* %24
%42 = load i32*, i32** %21
%43 = load i32, i32* %25
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
store i32 %41, i32* %45
%46 = load i32, i32* %13
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %69
48: ; preds = %40
%49 = load double, double* %19
%50 = load i32, i32* %12
%51 = load double**, double*** %14
%52 = load i32, i32* %24
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double*, double** %51, i64 %54
%56 = load double*, double** %55
%57 = load i32, i32* %16
%58 = call double @ldf_Mult_smooth(i32 0, double %49, i32 %50, double* %56, i32 1, i32 %57)
%59 = load double, double* %18
%60 = load i32, i32* %24
%61 = load double*, double** %15
%62 = load i32, i32* %17
%63 = call double @ldf_Mult_smooth(i32 0, double %59, i32 %60, double* %61, i32 1, i32 %62)
%64 = fadd double %58, %63
%65 = load double*, double** %22
%66 = load i32, i32* %25
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
store double %64, double* %68
br label %90
69: ; preds = %40
%70 = load i32, i32* %13
%71 = icmp eq i32 %70, 2
br i1 %71, label %72, label %87
72: ; preds = %69
%73 = load double, double* %19
%74 = load i32, i32* %12
%75 = load double**, double*** %14
%76 = load i32, i32* %24
%77 = sub nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double*, double** %75, i64 %78
%80 = load double*, double** %79
%81 = load i32, i32* %16
%82 = call double @ldf_Mult_smooth(i32 0, double %73, i32 %74, double* %80, i32 1, i32 %81)
%83 = load double*, double** %22
%84 = load i32, i32* %25
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds double, double* %83, i64 %85
store double %82, double* %86
br label %89
87: ; preds = %69
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %72
br label %90
90: ; preds = %89, %48
%91 = load i32, i32* %25
%92 = add nsw i32 %91, 1
store i32 %92, i32* %25
br label %93
93: ; preds = %90, %32
br label %94
94: ; preds = %93
%95 = load i32, i32* %24
%96 = add nsw i32 %95, 1
store i32 %96, i32* %24
br label %28
97: ; preds = %28
%98 = load double*, double** %22
%99 = load i32, i32* %25
%100 = call i32 @normalizeLog(double* %98, i32 1, i32 %99)
%101 = load double*, double** %22
%102 = load i32, i32* %25
%103 = call i32 @sample_Mult(double* %101, i32 1, i32 %102)
store i32 %103, i32* %26
%104 = load i32*, i32** %21
%105 = load i32, i32* %26
%106 = sub nsw i32 %105, 1
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i32, i32* %104, i64 %107
%109 = load i32, i32* %108
store i32 %109, i32* %27
%110 = load i32, i32* %27
ret i32 %110
}

LLVM IR (-O2):
define i32 @sample_Mult_labeled_stop(i32 %0, i32 %1, double** nocapture %2, double* %3, i32 %4, i32 %5, double %6, double %7, i32* nocapture %8, i32* nocapture %9, double* %10) {
%12 = icmp slt i32 %5, 1
br i1 %12, label %47, label %13
13: ; preds = %11
%14 = add nuw i32 %5, 1
%15 = zext i32 %14 to i64
br label %16
16: ; preds = %13, %43
%17 = phi i64 [ 1, %13 ], [ %45, %43 ]
%18 = phi i32 [ 0, %13 ], [ %44, %43 ]
%19 = add nsw i64 %17, -1
%20 = getelementptr inbounds i32, i32* %8, i64 %19
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %43, label %23
23: ; preds = %16
%24 = sext i32 %18 to i64
%25 = getelementptr inbounds i32, i32* %9, i64 %24
%26 = trunc i64 %17 to i32
store i32 %26, i32* %25
switch i32 %1, label %37 [
i32 1, label %27
i32 2, label %33
]
27: ; preds = %23
%28 = getelementptr inbounds double*, double** %2, i64 %19
%29 = load double*, double** %28
%30 = tail call double @ldf_Mult_smooth(i32 0, double %7, i32 %0, double* %29, i32 1, i32 %4)
%31 = tail call double @ldf_Mult_smooth(i32 0, double %6, i32 %26, double* %3, i32 1, i32 %5)
%32 = fadd double %30, %31
br label %39
33: ; preds = %23
%34 = getelementptr inbounds double*, double** %2, i64 %19
%35 = load double*, double** %34
%36 = tail call double @ldf_Mult_smooth(i32 0, double %7, i32 %0, double* %35, i32 1, i32 %4)
br label %39
37: ; preds = %23
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %33, %27
%40 = phi double [ %36, %33 ], [ %32, %27 ]
%41 = getelementptr inbounds double, double* %10, i64 %24
store double %40, double* %41
%42 = add nsw i32 %18, 1
br label %43
43: ; preds = %16, %39
%44 = phi i32 [ %42, %39 ], [ %18, %16 ]
%45 = add nuw nsw i64 %17, 1
%46 = icmp eq i64 %45, %15
br i1 %46, label %47, label %16
47: ; preds = %43, %11
%48 = phi i32 [ 0, %11 ], [ %44, %43 ]
%49 = tail call i32 @normalizeLog(double* %10, i32 1, i32 %48)
%50 = tail call i32 @sample_Mult(double* %10, i32 1, i32 %48)
%51 = add nsw i32 %50, -1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %9, i64 %52
%54 = load i32, i32* %53
ret i32 %54
}