#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);
void softmax_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) : 0;
    delta[i] = t - p;
  }
}


x86 assembly (clang, -O0):
<softmax_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    11e3 <softmax_x_ent_cpu+0xd3>
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
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    117e <softmax_x_ent_cpu+0x6e>
jp     117e <softmax_x_ent_cpu+0x6e>
jmp    119f <softmax_x_ent_cpu+0x8f>
movss  -0x34(%rbp),%xmm0
call   1030 <log@plt>
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x38(%rbp)
jmp    11ac <softmax_x_ent_cpu+0x9c>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x38(%rbp)
jmp    11ac <softmax_x_ent_cpu+0x9c>
movss  -0x38(%rbp),%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 <softmax_x_ent_cpu+0x22>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<softmax_x_ent_cpu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    1197 <softmax_x_ent_cpu+0x87>
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %edi,%ebx
xor    %ebp,%ebp
jmp    1159 <softmax_x_ent_cpu+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  %xmm0,(%r14,%rbp,4)
subss  %xmm2,%xmm1
movss  %xmm1,(%r15,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1197 <softmax_x_ent_cpu+0x87>
movss  (%r12,%rbp,4),%xmm1
movss  0x0(%r13,%rbp,4),%xmm2
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jne    1170 <softmax_x_ent_cpu+0x60>
jnp    1140 <softmax_x_ent_cpu+0x30>
movaps %xmm2,%xmm0
movss  %xmm1,0x4(%rsp)
movss  %xmm2,(%rsp)
call   1030 <log@plt>
movss  (%rsp),%xmm2
movss  0x4(%rsp),%xmm1
xorps  0xe6b(%rip),%xmm0
jmp    1140 <softmax_x_ent_cpu+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @softmax_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 = %49, %5
%15 = load i32, i32* %11
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %52
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 = fcmp une float %29, 0.000000e+00
br i1 %30, label %31, label %35
31: ; preds = %18
%32 = load float, float* %13
%33 = call float @log(float %32)
%34 = fneg float %33
br label %36
35: ; preds = %18
br label %36
36: ; preds = %35, %31
%37 = phi float [ %34, %31 ], [ 0.000000e+00, %35 ]
%38 = load float*, float** %10
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds float, float* %38, i64 %40
store float %37, float* %41
%42 = load float, float* %12
%43 = load float, float* %13
%44 = fsub float %42, %43
%45 = load float*, float** %9
%46 = load i32, i32* %11
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds float, float* %45, i64 %47
store float %44, float* %48
br label %49
49: ; preds = %36
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %14
52: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @softmax_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 %26
7: ; preds = %5
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %19
%10 = phi i64 [ 0, %7 ], [ %24, %19 ]
%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 = fcmp une float %12, 0.000000e+00
br i1 %15, label %16, label %19
16: ; preds = %9
%17 = tail call float @log(float %14)
%18 = fneg float %17
br label %19
19: ; preds = %9, %16
%20 = phi float [ %18, %16 ], [ 0.000000e+00, %9 ]
%21 = getelementptr inbounds float, float* %4, i64 %10
store float %20, float* %21
%22 = fsub float %12, %14
%23 = getelementptr inbounds float, float* %3, i64 %10
store float %22, float* %23
%24 = add nuw nsw i64 %10, 1
%25 = icmp eq i64 %24, %8
br i1 %25, label %26, label %9
26: ; preds = %19, %5
ret void
}