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


x86 assembly (clang, -O0):
<inverse_transform_simplex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movsd  0xeb1(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    125b <inverse_transform_simplex+0x12b>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x2c(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1030 <inverse_logit@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
mov    -0x20(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <log1p_exp@plt>
cvtsi2sd %rax,%xmm1
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
movsd  -0x38(%rbp),%xmm0
call   1050 <log1p_exp@plt>
cvtsi2sd %rax,%xmm1
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115b <inverse_transform_simplex+0x2b>
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inverse_transform_simplex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
cmp    $0x2,%edx
jl     1230 <inverse_transform_simplex+0x100>
mov    %rcx,%r13
mov    %rsi,%r15
add    $0xffffffff,%edx
mov    %edx,%r12d
movsd  0xea2(%rip),%xmm0
xor    %ebx,%ebx
mov    %r12,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm0,0x8(%rsp)
movsd  (%r15,%rbx,1),%xmm0
movaps %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
call   1040 <log@plt>
movapd 0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
call   1030 <inverse_logit@plt>
mulsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,1)
movsd  0x8(%rsp),%xmm0
call   1040 <log@plt>
addsd  0x0(%r13),%xmm0
movsd  %xmm0,0x0(%r13)
movaps 0x10(%rsp),%xmm0
xorps  0xe3b(%rip),%xmm0
call   1050 <log1p_exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x0(%r13),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x0(%r13)
movaps 0x10(%rsp),%xmm0
call   1050 <log1p_exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x0(%r13),%xmm1
subsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
movsd  %xmm1,0x0(%r13)
subsd  (%r14,%rbx,1),%xmm0
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
jne    1170 <inverse_transform_simplex+0x40>
jmp    123b <inverse_transform_simplex+0x10b>
movsd  0xdc8(%rip),%xmm0
xor    %r12d,%r12d
movsd  %xmm0,(%r14,%r12,8)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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