#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 */
double exp(double const);
void morpheus_sigmoid_gradient(int n, const double *x, double *y) {
  for (int i = 0; i < n; ++i) {
    const double s = 1.0 / (1.0 + exp(-x[i]));
    y[i] = s * (1 - s);
  }
}


x86 assembly (clang, -O0):
<morpheus_sigmoid_gradient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ad <morpheus_sigmoid_gradient+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
movsd  0xe99(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0xe8d(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe77(%rip),%xmm1
subsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <morpheus_sigmoid_gradient+0x1a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<morpheus_sigmoid_gradient>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    1172 <morpheus_sigmoid_gradient+0x62>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsd  (%r15,%rbx,8),%xmm0
xorpd  0xec2(%rip),%xmm0
call   1030 <exp@plt>
movsd  0xec5(%rip),%xmm2
addsd  %xmm2,%xmm0
movapd %xmm2,%xmm1
divsd  %xmm0,%xmm1
movapd %xmm2,%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <morpheus_sigmoid_gradient+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @morpheus_sigmoid_gradient(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
store i32 0, i32* %7
br label %9
9: ; preds = %31, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %34
13: ; preds = %9
%14 = load double*, double** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds double, double* %14, i64 %16
%18 = load double, double* %17
%19 = fneg double %18
%20 = call double @exp(double %19)
%21 = fadd double 1.000000e+00, %20
%22 = fdiv double 1.000000e+00, %21
store double %22, double* %8
%23 = load double, double* %8
%24 = load double, double* %8
%25 = fsub double 1.000000e+00, %24
%26 = fmul double %23, %25
%27 = load double*, double** %6
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
store double %26, double* %30
br label %31
31: ; preds = %13
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %9
34: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @morpheus_sigmoid_gradient(i32 %0, double* nocapture %1, double* nocapture writeonly %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %8
7: ; preds = %8, %3
ret void
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %19, %8 ]
%10 = getelementptr inbounds double, double* %1, i64 %9
%11 = load double, double* %10
%12 = fneg double %11
%13 = tail call double @exp(double %12)
%14 = fadd double %13, 1.000000e+00
%15 = fdiv double 1.000000e+00, %14
%16 = fsub double 1.000000e+00, %15
%17 = fmul double %15, %16
%18 = getelementptr inbounds double, double* %2, i64 %9
store double %17, double* %18
%19 = add nuw nsw i64 %9, 1
%20 = icmp eq i64 %19, %6
br i1 %20, label %7, label %8
}