#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 */
scalar_t__ log(double const);
int const logistic_loss2(int const, double const *, double const *,
                         double const *);
double eval_phi(const int m, const int n, const double *z, const double *expz,
                const double *expmz, const double *w, const double *u,
                const double lambda, const double t) {
  int i;
  double penalty = 0.0;
  double barrier = 0.0;
  for (i = 0; i < n; i++) {
    penalty += u[i];
    barrier -= log((-w[i] + u[i]) * (w[i] + u[i]));
  }
  return logistic_loss2(m, z, expz, expmz) / m + lambda * penalty + barrier / t;
}


x86 assembly (clang, -O0):
<eval_phi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm1,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11fb <eval_phi+0xdb>
mov    0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <log@plt>
cvtsi2sd %rax,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1163 <eval_phi+0x43>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <logistic_loss2@plt>
cltd
idivl  -0x4(%rbp)
cvtsi2sd %eax,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x50(%rbp),%xmm1
divsd  -0x38(%rbp),%xmm1
addsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_phi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movsd  %xmm1,0x28(%rsp)
movsd  %xmm0,0x30(%rsp)
mov    %r8,0x20(%rsp)
mov    %rcx,0x18(%rsp)
mov    %rdx,%r12
mov    %edi,%r13d
test   %esi,%esi
jle    11c5 <eval_phi+0xa5>
mov    %r9,%rbx
mov    0x70(%rsp),%rbp
mov    %esi,%r14d
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %r15d,%r15d
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x0(%rbp,%r15,8),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  (%rbx,%r15,8),%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
addsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
call   1040 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
add    $0x1,%r15
cmp    %r15,%r14
jne    1170 <eval_phi+0x50>
jmp    11d9 <eval_phi+0xb9>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r13d,%edi
mov    %r12,%rsi
mov    0x18(%rsp),%rdx
mov    0x20(%rsp),%rcx
call   1030 <logistic_loss2@plt>
cltd
idiv   %r13d
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x30(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
divsd  0x28(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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