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


x86 assembly (clang, -O0):
<logistic_loss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1204 <logistic_loss+0xe4>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe85(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    11ab <logistic_loss+0x8b>
movsd  -0x28(%rbp),%xmm0
call   1030 <exp@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1040 <log@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11e7 <logistic_loss+0xc7>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1040 <log@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <logistic_loss+0x1e>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logistic_loss>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %edi,%edi
jle    11af <logistic_loss+0x8f>
mov    %rsi,%r14
mov    %edi,%r15d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    1179 <logistic_loss+0x59>
nop
movapd %xmm0,0x10(%rsp)
call   1030 <exp@plt>
lea    0x1(%rax),%rdi
call   1040 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
subsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x1,%rbx
cmp    %rbx,%r15
je     11b3 <logistic_loss+0x93>
movsd  %xmm0,0x8(%rsp)
movsd  (%r14,%rbx,8),%xmm0
ucomisd 0xe73(%rip),%xmm0
jbe    1140 <logistic_loss+0x20>
xorpd  0xe79(%rip),%xmm0
call   1030 <exp@plt>
lea    0x1(%rax),%rdi
call   1040 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
jmp    1162 <logistic_loss+0x42>
xorpd  %xmm0,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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