#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 */
int log(int);
void logistic_x_ent_cpu(int n, float *pred, float *truth, float *delta,
                        float *error) {
  int i;
  for (i = 0; i < n; ++i) {
    float t = truth[i];
    float p = pred[i];
    error[i] = -t * log(p) - (1 - t) * log(1 - p);
    delta[i] = t - p;
  }
}


x86 assembly (clang, -O0):
<logistic_x_ent_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1212 <logistic_x_ent_cpu+0x102>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x30(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x3c(%rbp)
cvttss2si -0x34(%rbp),%edi
call   1030 <log@plt>
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x38(%rbp)
movss  0xe6c(%rip),%xmm0
subss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x40(%rbp)
movss  0xe5a(%rip),%xmm0
subss  -0x34(%rbp),%xmm0
cvttss2si %xmm0,%edi
call   1030 <log@plt>
movss  -0x40(%rbp),%xmm1
movss  -0x3c(%rbp),%xmm0
movss  -0x38(%rbp),%xmm2
cvtsi2ss %eax,%xmm3
mulss  %xmm3,%xmm1
movd   %xmm1,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
movss  -0x30(%rbp),%xmm0
subss  -0x34(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1132 <logistic_x_ent_cpu+0x22>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logistic_x_ent_cpu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
test   %edi,%edi
jle    11e1 <logistic_x_ent_cpu+0xd1>
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %edi,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movss  (%r12,%rbp,4),%xmm0
movaps %xmm0,0x10(%rsp)
movss  0x0(%r13,%rbp,4),%xmm1
movss  %xmm1,0x4(%rsp)
xorps  0xea1(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
cvttss2si %xmm1,%edi
call   1030 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0xc(%rsp)
movss  0xe8e(%rip),%xmm0
movaps %xmm0,%xmm1
subss  0x10(%rsp),%xmm1
movss  %xmm1,0x8(%rsp)
subss  0x4(%rsp),%xmm0
cvttss2si %xmm0,%edi
call   1030 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
mulss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
mulss  0x20(%rsp),%xmm1
subss  %xmm0,%xmm1
movss  %xmm1,(%r14,%rbp,4)
movaps 0x10(%rsp),%xmm0
subss  0x4(%rsp),%xmm0
movss  %xmm0,(%r15,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1140 <logistic_x_ent_cpu+0x30>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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