#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 */
double inverse_logit(scalar_t__);
scalar_t__ log(int);
void inverse_transform_simplex2(double *x, const double *y, int K) {
  double stick = 1.0;
  int k = 0;
  for (; k < K - 1; k++) {
    double z = inverse_logit(y[k] - log(K - k - 1));
    x[k] = stick * z;
    stick -= x[k];
  }
  x[k] = stick;
}


x86 assembly (clang, -O0):
<inverse_transform_simplex2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d5 <inverse_transform_simplex2+0xb5>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x14(%rbp),%edi
sub    -0x24(%rbp),%edi
sub    $0x1,%edi
call   1040 <log@plt>
movsd  -0x38(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1030 <inverse_logit@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x20(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1147 <inverse_transform_simplex2+0x27>
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inverse_transform_simplex2>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
cmp    $0x2,%edx
jl     11a4 <inverse_transform_simplex2+0x84>
mov    %rsi,%r15
add    $0xffffffff,%edx
mov    %edx,%r12d
movsd  0xeba(%rip),%xmm1
xor    %ebx,%ebx
mov    %r12,%r13
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  (%r15,%rbx,1),%xmm0
movsd  %xmm0,(%rsp)
mov    %r13d,%edi
call   1040 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
call   1030 <inverse_logit@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%r14,%rbx,1)
subsd  %xmm0,%xmm1
add    $0x8,%rbx
add    $0xffffffffffffffff,%r13
jne    1150 <inverse_transform_simplex2+0x30>
jmp    11af <inverse_transform_simplex2+0x8f>
movsd  0xe54(%rip),%xmm1
xor    %r12d,%r12d
movsd  %xmm1,(%r14,%r12,8)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @inverse_transform_simplex2(double* nocapture writeonly %0, double* nocapture %1, i32 %2) {
%4 = add i32 %2, -1
%5 = icmp sgt i32 %2, 1
br i1 %5, label %6, label %28
6: ; preds = %3
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %24, %8 ]
%10 = phi double [ 1.000000e+00, %6 ], [ %23, %8 ]
%11 = trunc i64 %9 to i32
%12 = getelementptr inbounds double, double* %1, i64 %9
%13 = load double, double* %12
%14 = xor i32 %11, -1
%15 = add i32 %14, %2
%16 = tail call i64 @log(i32 %15)
%17 = sitofp i64 %16 to double
%18 = fsub double %13, %17
%19 = fptosi double %18 to i64
%20 = tail call double @inverse_logit(i64 %19)
%21 = fmul double %10, %20
%22 = getelementptr inbounds double, double* %0, i64 %9
store double %21, double* %22
%23 = fsub double %10, %21
%24 = add nuw nsw i64 %9, 1
%25 = icmp eq i64 %24, %7
br i1 %25, label %26, label %8
26: ; preds = %8
%27 = zext i32 %4 to i64
br label %28
28: ; preds = %3, %26
%29 = phi i64 [ %27, %26 ], [ 0, %3 ]
%30 = phi double [ %23, %26 ], [ 1.000000e+00, %3 ]
%31 = getelementptr inbounds double, double* %0, i64 %29
store double %30, double* %31
ret void
}