#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 neural_gradient(int const, double const);
void neural_gradient_array(const double *state, double *delta, const int n,
                           const int a) {
  for (int i = 0; i < n; ++i) {
    delta[i] *= neural_gradient(a, state[i]);
  }
}


x86 assembly (clang, -O0):
<neural_gradient_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    116e <neural_gradient_array+0x5e>
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <neural_gradient@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112d <neural_gradient_array+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<neural_gradient_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
jle    1151 <neural_gradient_array+0x41>
mov    %ecx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsd  (%r15,%rbp,8),%xmm0
mov    %r14d,%edi
call   1030 <neural_gradient@plt>
mulsd  (%rbx,%rbp,8),%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1130 <neural_gradient_array+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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