#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 */
float log(float);
float crossEntropy(float target[], float result[], const int n_c) {
  float sum1 = 0.0;
  int i;
#pragma parallel for private(i)
  for (i = 0; i != n_c; ++i) {
    sum1 += target[i] * log(result[i]);
  }
  return sum1;
}


x86 assembly (clang, -O0):
<crossEntropy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     118a <crossEntropy+0x7a>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm2
movss  -0x20(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1132 <crossEntropy+0x22>
movss  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crossEntropy>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     1170 <crossEntropy+0x60>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movss  %xmm0,(%rsp)
movss  (%r15,%rbx,4),%xmm0
movss  %xmm0,0x4(%rsp)
movss  (%r14,%rbx,4),%xmm0
call   1030 <log@plt>
mulss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
movss  (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <crossEntropy+0x20>
jmp    1173 <crossEntropy+0x63>
xorps  %xmm0,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define float @crossEntropy(float* %0, float* %1, i32 %2) {
%4 = alloca float*
%5 = alloca float*
%6 = alloca i32
%7 = alloca float
%8 = alloca i32
store float* %0, float** %4
store float* %1, float** %5
store i32 %2, i32* %6
store float 0.000000e+00, float* %7
store i32 0, i32* %8
br label %9
9: ; preds = %27, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = load float*, float** %4
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds float, float* %14, i64 %16
%18 = load float, float* %17
%19 = load float*, float** %5
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds float, float* %19, i64 %21
%23 = load float, float* %22
%24 = call float @log(float %23)
%25 = load float, float* %7
%26 = call float @llvm.fmuladd.f32(float %18, float %24, float %25)
store float %26, float* %7
br label %27
27: ; preds = %13
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %9
30: ; preds = %9
%31 = load float, float* %7
ret float %31
}

LLVM IR (-O2):
define float @crossEntropy(float* nocapture %0, float* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %18, label %5
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %16, %7 ]
%9 = phi float [ 0.000000e+00, %5 ], [ %15, %7 ]
%10 = getelementptr inbounds float, float* %0, i64 %8
%11 = load float, float* %10
%12 = getelementptr inbounds float, float* %1, i64 %8
%13 = load float, float* %12
%14 = tail call float @log(float %13)
%15 = tail call float @llvm.fmuladd.f32(float %11, float %14, float %9)
%16 = add nuw nsw i64 %8, 1
%17 = icmp eq i64 %16, %6
br i1 %17, label %18, label %7
18: ; preds = %7, %3
%19 = phi float [ 0.000000e+00, %3 ], [ %15, %7 ]
ret float %19
}