#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 const log(int);
double logistic_loss2(const int n, const double *z, const double *expz,
                      const double *expmz) {
  int i;
  double ret = 0.0;
  for (i = 0; i < n; i++) {
    ret += (z[i] > -700) ? log(1 + expmz[i]) : log(1 + expz[i]) - z[i];
  }
  return ret;
}


x86 assembly (clang, -O0):
<logistic_loss2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d6 <logistic_loss2+0xc6>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xea9(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1189 <logistic_loss2+0x79>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  0xe97(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
movsd  %xmm0,-0x38(%rbp)
jmp    11b9 <logistic_loss2+0xa9>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  0xe6f(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1136 <logistic_loss2+0x26>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logistic_loss2>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
jle    11a5 <logistic_loss2+0x95>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r13
mov    %edi,%r12d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    1175 <logistic_loss2+0x65>
nopl   0x0(%rax)
movsd  (%r15,%rbx,8),%xmm0
addsd  0xeba(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
subsd  0x0(%r13,%rbx,8),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x1,%rbx
cmp    %rbx,%r12
je     11a9 <logistic_loss2+0x99>
movsd  %xmm0,0x8(%rsp)
movsd  0x0(%r13,%rbx,8),%xmm0
ucomisd 0xe76(%rip),%xmm0
jbe    1140 <logistic_loss2+0x30>
movsd  (%r14,%rbx,8),%xmm0
addsd  0xe6e(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <log@plt>
jmp    115e <logistic_loss2+0x4e>
xorpd  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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