#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_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 hi = expf(x_i);
    float lo = expf(-x_i);
    float t = (hi - lo) / (hi + lo);
    float s = 2.0f / (hi + lo);
    r_dx[i] += (r_dy[i] + dy[i] * r_x[i] * (-2.0f * t)) * (s * s);
  }
}


x86 assembly (clang, -O0):
<arraydiff_kernel_tanh_rbwd_f32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    122c <arraydiff_kernel_tanh_rbwd_f32+0x11c>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x3c(%rbp),%xmm0
call   1030 <expf@plt>
movss  %xmm0,-0x40(%rbp)
movss  -0x3c(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1030 <expf@plt>
movss  %xmm0,-0x44(%rbp)
movss  -0x40(%rbp),%xmm0
subss  -0x44(%rbp),%xmm0
movss  -0x40(%rbp),%xmm1
addss  -0x44(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x40(%rbp),%xmm1
addss  -0x44(%rbp),%xmm1
movss  0xe52(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x4c(%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  0xe16(%rip),%xmm2
mulss  -0x48(%rbp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  -0x4c(%rbp),%xmm2
mulss  -0x4c(%rbp),%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_tanh_rbwd_f32+0x28>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arraydiff_kernel_tanh_rbwd_f32>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
je     11ce <arraydiff_kernel_tanh_rbwd_f32+0xbe>
mov    %r9,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%rbx
xor    %r14d,%r14d
mov    %r8,0x8(%rsp)
xchg   %ax,%ax
movss  0x0(%rbp,%r14,4),%xmm0
movaps %xmm0,0x10(%rsp)
call   1030 <expf@plt>
movss  %xmm0,0x4(%rsp)
movaps 0x10(%rsp),%xmm0
xorps  0xe9d(%rip),%xmm0
call   1030 <expf@plt>
mov    0x8(%rsp),%r8
movss  0x4(%rsp),%xmm2
movaps %xmm2,%xmm1
subss  %xmm0,%xmm1
addss  %xmm0,%xmm2
divss  %xmm2,%xmm1
movss  0xe86(%rip),%xmm0
divss  %xmm2,%xmm0
movss  (%r12,%r14,4),%xmm2
mulss  0x0(%r13,%r14,4),%xmm2
mulss  0xe71(%rip),%xmm1
mulss  %xmm2,%xmm1
addss  (%r8,%r14,4),%xmm1
mulss  %xmm0,%xmm0
mulss  %xmm1,%xmm0
addss  (%r15,%r14,4),%xmm0
movss  %xmm0,(%r15,%r14,4)
add    $0x1,%r14
cmp    %r14,%rbx
jne    1140 <arraydiff_kernel_tanh_rbwd_f32+0x30>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @arraydiff_kernel_tanh_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
%16 = alloca float
%17 = alloca float
%18 = 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 %19
19: ; preds = %68, %6
%20 = load i64, i64* %13
%21 = load i64, i64* %7
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %71
23: ; preds = %19
%24 = load float*, float** %8
%25 = load i64, i64* %13
%26 = getelementptr inbounds float, float* %24, i64 %25
%27 = load float, float* %26
store float %27, float* %14
%28 = load float, float* %14
%29 = call float @expf(float %28)
store float %29, float* %15
%30 = load float, float* %14
%31 = fneg float %30
%32 = call float @expf(float %31)
store float %32, float* %16
%33 = load float, float* %15
%34 = load float, float* %16
%35 = fsub float %33, %34
%36 = load float, float* %15
%37 = load float, float* %16
%38 = fadd float %36, %37
%39 = fdiv float %35, %38
store float %39, float* %17
%40 = load float, float* %15
%41 = load float, float* %16
%42 = fadd float %40, %41
%43 = fdiv float 2.000000e+00, %42
store float %43, float* %18
%44 = load float*, float** %11
%45 = load i64, i64* %13
%46 = getelementptr inbounds float, float* %44, i64 %45
%47 = load float, float* %46
%48 = load float*, float** %10
%49 = load i64, i64* %13
%50 = getelementptr inbounds float, float* %48, i64 %49
%51 = load float, float* %50
%52 = load float*, float** %9
%53 = load i64, i64* %13
%54 = getelementptr inbounds float, float* %52, i64 %53
%55 = load float, float* %54
%56 = fmul float %51, %55
%57 = load float, float* %17
%58 = fmul float -2.000000e+00, %57
%59 = call float @llvm.fmuladd.f32(float %56, float %58, float %47)
%60 = load float, float* %18
%61 = load float, float* %18
%62 = fmul float %60, %61
%63 = load float*, float** %12
%64 = load i64, i64* %13
%65 = getelementptr inbounds float, float* %63, i64 %64
%66 = load float, float* %65
%67 = call float @llvm.fmuladd.f32(float %59, float %62, float %66)
store float %67, float* %65
br label %68
68: ; preds = %23
%69 = load i64, i64* %13
%70 = add i64 %69, 1
store i64 %70, i64* %13
br label %19
71: ; preds = %19
ret void
}

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