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


x86 assembly (clang, -O0):
<arraydiff_kernel_logistic_rbwd_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)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1211 <arraydiff_kernel_logistic_rbwd_f32+0x101>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x3c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1030 <expf@plt>
movss  0xe89(%rip),%xmm1
addss  %xmm0,%xmm1
movss  0xe7d(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mulss  (%rax,%rcx,4),%xmm0
movss  -0x40(%rbp),%xmm3
addss  %xmm3,%xmm3
movss  0xe3c(%rip),%xmm2
subss  %xmm3,%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  -0x40(%rbp),%xmm2
movss  0xe23(%rip),%xmm1
subss  -0x40(%rbp),%xmm1
mulss  %xmm1,%xmm2
mov    -0x30(%rbp),%rax
mov    -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1138 <arraydiff_kernel_logistic_rbwd_f32+0x28>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arraydiff_kernel_logistic_rbwd_f32>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11b0 <arraydiff_kernel_logistic_rbwd_f32+0xa0>
mov    %r9,%rbx
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
xor    %r14d,%r14d
mov    %rdi,(%rsp)
nopw   0x0(%rax,%rax,1)
movss  0x0(%rbp,%r14,4),%xmm0
xorps  0xeb2(%rip),%xmm0
call   1030 <expf@plt>
mov    (%rsp),%rdi
movss  0xeb1(%rip),%xmm4
addss  %xmm4,%xmm0
movaps %xmm4,%xmm1
divss  %xmm0,%xmm1
movss  (%r12,%r14,4),%xmm0
mulss  0x0(%r13,%r14,4),%xmm0
movaps %xmm4,%xmm2
subss  %xmm1,%xmm2
movaps %xmm1,%xmm3
addss  %xmm1,%xmm3
subss  %xmm3,%xmm4
mulss  %xmm0,%xmm4
addss  (%r15,%r14,4),%xmm4
mulss  %xmm1,%xmm2
mulss  %xmm4,%xmm2
addss  (%rbx,%r14,4),%xmm2
movss  %xmm2,(%rbx,%r14,4)
add    $0x1,%r14
cmp    %r14,%rdi
jne    1140 <arraydiff_kernel_logistic_rbwd_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_rbwd_f32(i64 %0, float* %1, float* %2, float* %3, float* %4, float* %5) {
%7 = alloca i64
%8 = alloca float*
%9 = alloca float*
%10 = alloca float*
%11 = alloca float*
%12 = alloca float*
%13 = alloca i64
%14 = alloca float
%15 = alloca float
store i64 %0, i64* %7
store float* %1, float** %8
store float* %2, float** %9
store float* %3, float** %10
store float* %4, float** %11
store float* %5, float** %12
store i64 0, i64* %13
br label %16
16: ; preds = %55, %6
%17 = load i64, i64* %13
%18 = load i64, i64* %7
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %58
20: ; preds = %16
%21 = load float*, float** %8
%22 = load i64, i64* %13
%23 = getelementptr inbounds float, float* %21, i64 %22
%24 = load float, float* %23
store float %24, float* %14
%25 = load float, float* %14
%26 = fneg float %25
%27 = call float @expf(float %26)
%28 = fadd float 1.000000e+00, %27
%29 = fdiv float 1.000000e+00, %28
store float %29, float* %15
%30 = load float*, float** %11
%31 = load i64, i64* %13
%32 = getelementptr inbounds float, float* %30, i64 %31
%33 = load float, float* %32
%34 = load float*, float** %10
%35 = load i64, i64* %13
%36 = getelementptr inbounds float, float* %34, i64 %35
%37 = load float, float* %36
%38 = load float*, float** %9
%39 = load i64, i64* %13
%40 = getelementptr inbounds float, float* %38, i64 %39
%41 = load float, float* %40
%42 = fmul float %37, %41
%43 = load float, float* %15
%44 = call float @llvm.fmuladd.f32(float -2.000000e+00, float %43, float 1.000000e+00)
%45 = call float @llvm.fmuladd.f32(float %42, float %44, float %33)
%46 = load float, float* %15
%47 = load float, float* %15
%48 = fsub float 1.000000e+00, %47
%49 = fmul float %46, %48
%50 = load float*, float** %12
%51 = load i64, i64* %13
%52 = getelementptr inbounds float, float* %50, i64 %51
%53 = load float, float* %52
%54 = call float @llvm.fmuladd.f32(float %45, float %49, float %53)
store float %54, float* %52
br label %55
55: ; preds = %20
%56 = load i64, i64* %13
%57 = add i64 %56, 1
store i64 %57, i64* %13
br label %16
58: ; preds = %16
ret void
}

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