#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_fwd_f32(size_t dim, const float *x, float *y) {
  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);
    y[i] = t;
  }
}


x86 assembly (clang, -O0):
<arraydiff_kernel_tanh_fwd_f32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11b7 <arraydiff_kernel_tanh_fwd_f32+0xa7>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
call   1030 <expf@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0x24(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1030 <expf@plt>
movss  %xmm0,-0x2c(%rbp)
movss  -0x28(%rbp),%xmm0
subss  -0x2c(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
addss  -0x2c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <arraydiff_kernel_tanh_fwd_f32+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arraydiff_kernel_tanh_fwd_f32>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
je     117b <arraydiff_kernel_tanh_fwd_f32+0x6b>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
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>
movss  0xc(%rsp),%xmm2
movaps %xmm2,%xmm1
subss  %xmm0,%xmm1
addss  %xmm0,%xmm2
divss  %xmm2,%xmm1
movss  %xmm1,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <arraydiff_kernel_tanh_fwd_f32+0x20>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @arraydiff_kernel_tanh_fwd_f32(i64 %0, float* nocapture %1, float* nocapture writeonly %2) {
%4 = icmp eq i64 %0, 0
br i1 %4, label %5, label %6
5: ; preds = %6, %3
ret void
6: ; preds = %3, %6
%7 = phi i64 [ %17, %6 ], [ 0, %3 ]
%8 = getelementptr inbounds float, float* %1, i64 %7
%9 = load float, float* %8
%10 = tail call float @expf(float %9)
%11 = fneg float %9
%12 = tail call float @expf(float %11)
%13 = fsub float %10, %12
%14 = fadd float %10, %12
%15 = fdiv float %13, %14
%16 = getelementptr inbounds float, float* %2, i64 %7
store float %15, float* %16
%17 = add nuw i64 %7, 1
%18 = icmp eq i64 %17, %0
br i1 %18, label %5, label %6
}