#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_tanh_bwd_f32(size_t dim, const float *x, const float *dy,
                                   float *dx) {
  for (size_t i = 0; i < dim; i++) {
    float x_i = x[i];
    float hi = expf(x_i);
    float lo = expf(-x_i);
    float s = 2.0f / (hi + lo);
    dx[i] += dy[i] * (s * s);
  }
}


x86 assembly (clang, -O0):
<arraydiff_kernel_tanh_bwd_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)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11d8 <arraydiff_kernel_tanh_bwd_f32+0xc8>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x2c(%rbp),%xmm0
call   1030 <expf@plt>
movss  %xmm0,-0x30(%rbp)
movss  -0x2c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1030 <expf@plt>
movss  %xmm0,-0x34(%rbp)
movss  -0x30(%rbp),%xmm1
addss  -0x34(%rbp),%xmm1
movss  0xe73(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  -0x38(%rbp),%xmm2
mulss  -0x38(%rbp),%xmm2
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1130 <arraydiff_kernel_tanh_bwd_f32+0x20>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arraydiff_kernel_tanh_bwd_f32>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
test   %rdi,%rdi
je     118a <arraydiff_kernel_tanh_bwd_f32+0x7a>
mov    %rcx,%r13
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
movss  (%r15,%rbx,4),%xmm0
movaps %xmm0,0x10(%rsp)
call   1030 <expf@plt>
movss  %xmm0,0xc(%rsp)
movaps 0x10(%rsp),%xmm0
xorps  0xeae(%rip),%xmm0
call   1030 <expf@plt>
addss  0xc(%rsp),%xmm0
movss  0xeab(%rip),%xmm1
divss  %xmm0,%xmm1
mulss  %xmm1,%xmm1
mulss  (%r14,%rbx,4),%xmm1
addss  0x0(%r13,%rbx,4),%xmm1
movss  %xmm1,0x0(%r13,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <arraydiff_kernel_tanh_bwd_f32+0x20>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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