#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 expf(float);
void arraydiff_kernel_logistic_bwd2_f32(size_t dim, const float *x,
                                        const float *dy, const float *dy2,
                                        float *dx2) {
  for (size_t i = 0; i < dim; i++) {
    float x_i = x[i];
    float y_i = 1.0f / (1.0f + expf(-x_i));
    dx2[i] += (dy2[i] * (y_i * (1.0f - y_i)) + dy[i] * (1.0f - 2.0f * y_i)) *
              (y_i * (1.0f - y_i));
  }
}


x86 assembly (clang, -O0):
<arraydiff_kernel_logistic_bwd2_f32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    121a <arraydiff_kernel_logistic_bwd2_f32+0x10a>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x34(%rbp)
movss  -0x34(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1030 <expf@plt>
movss  0xe8d(%rip),%xmm1
addss  %xmm0,%xmm1
movss  0xe81(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  -0x38(%rbp),%xmm2
movss  0xe5e(%rip),%xmm1
subss  -0x38(%rbp),%xmm1
mulss  %xmm1,%xmm2
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
movss  -0x38(%rbp),%xmm4
addss  %xmm4,%xmm4
movss  0xe37(%rip),%xmm3
subss  %xmm4,%xmm3
mulss  %xmm3,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  -0x38(%rbp),%xmm2
movss  0xe1a(%rip),%xmm1
subss  -0x38(%rbp),%xmm1
mulss  %xmm1,%xmm2
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1134 <arraydiff_kernel_logistic_bwd2_f32+0x24>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arraydiff_kernel_logistic_bwd2_f32>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a3 <arraydiff_kernel_logistic_bwd2_f32+0x93>
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movss  (%r12,%rbp,4),%xmm0
xorps  0xeb3(%rip),%xmm0
call   1030 <expf@plt>
movss  0xeb6(%rip),%xmm2
addss  %xmm2,%xmm0
movaps %xmm2,%xmm1
divss  %xmm0,%xmm1
movaps %xmm2,%xmm0
subss  %xmm1,%xmm0
mulss  %xmm1,%xmm0
addss  %xmm1,%xmm1
subss  %xmm1,%xmm2
mulss  (%r15,%rbp,4),%xmm2
movss  (%r14,%rbp,4),%xmm1
mulss  %xmm0,%xmm1
addss  %xmm2,%xmm1
mulss  %xmm0,%xmm1
addss  (%rbx,%rbp,4),%xmm1
movss  %xmm1,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1140 <arraydiff_kernel_logistic_bwd2_f32+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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