#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 genann_act_sigmoid(double const);
double genann_act_sigmoid_cached(double a) {
  const double min = -15.0;
  const double max = 15.0;
  static double interval;
  static int initialized = 0;
  static double lookup[4096];
  if (!initialized) {
    interval = (max - min) / 4096;
    int i;
    for (i = 0; i < 4096; ++i) {
      lookup[i] = genann_act_sigmoid(min + interval * i);
    }
    initialized = 1;
  }
  int i;
  i = (int)((a - min) / interval + 0.5);
  if (i <= 0)
    return lookup[0];
  if (i >= 4096)
    return lookup[4096 - 1];
  return lookup[i];
}


x86 assembly (clang, -O0):
<genann_act_sigmoid_cached>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xee3(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xece(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,0x2f0a(%rip)
jne    11b2 <genann_act_sigmoid_cached+0xa2>
movsd  0xec4(%rip),%xmm0
movsd  %xmm0,0x2eec(%rip)
movl   $0x0,-0x24(%rbp)
cmpl   $0x1000,-0x24(%rbp)
jge    11a8 <genann_act_sigmoid_cached+0x98>
movsd  0x2ed0(%rip),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe87(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <genann_act_sigmoid@plt>
movslq -0x24(%rbp),%rcx
lea    0x2ebb(%rip),%rax
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115b <genann_act_sigmoid_cached+0x4b>
movl   $0x1,0x2e96(%rip)
movsd  -0x10(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
subsd  %xmm1,%xmm0
divsd  0x2e75(%rip),%xmm0
movsd  0xe45(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jg     11fa <genann_act_sigmoid_cached+0xea>
movsd  0x2e60(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122e <genann_act_sigmoid_cached+0x11e>
cmpl   $0x1000,-0x28(%rbp)
jl     1219 <genann_act_sigmoid_cached+0x109>
movsd  0xae39(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122e <genann_act_sigmoid_cached+0x11e>
movslq -0x28(%rbp),%rcx
lea    0x2e2c(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genann_act_sigmoid_cached>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,0x2f2d(%rip)
jne    119b <genann_act_sigmoid_cached+0x8b>
movsd  %xmm0,(%rsp)
movabs $0x3f7e000000000000,%rax
mov    %rax,0x2f0d(%rip)
movsd  0xec5(%rip),%xmm0
call   1030 <genann_act_sigmoid@plt>
movsd  %xmm0,0x2f08(%rip)
mov    $0x1,%ebx
lea    0x2efc(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x2ed1(%rip),%xmm0
addsd  0xe89(%rip),%xmm0
call   1030 <genann_act_sigmoid@plt>
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    $0x1000,%rbx
jne    1160 <genann_act_sigmoid_cached+0x50>
movb   $0x1,0x2eb2(%rip)
movsd  (%rsp),%xmm0
addsd  0xe65(%rip),%xmm0
divsd  0x2e95(%rip),%xmm0
addsd  0xe5d(%rip),%xmm0
cvttsd2si %xmm0,%eax
test   %eax,%eax
jle    11cb <genann_act_sigmoid_cached+0xbb>
cmp    $0xfff,%eax
jbe    11d4 <genann_act_sigmoid_cached+0xc4>
lea    0xae7f(%rip),%rax
jmp    11e1 <genann_act_sigmoid_cached+0xd1>
lea    0x2e7e(%rip),%rax
jmp    11e1 <genann_act_sigmoid_cached+0xd1>
mov    %eax,%eax
lea    0x2e73(%rip),%rcx
lea    (%rcx,%rax,8),%rax
movsd  (%rax),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@genann_act_sigmoid_cached.interval = internal global double 0.000000e+00
@genann_act_sigmoid_cached.initialized = internal global i32 0
@genann_act_sigmoid_cached.lookup = internal global [4096 x double] zeroinitializer
define double @genann_act_sigmoid_cached(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store double %0, double* %3
store double -1.500000e+01, double* %4
store double 1.500000e+01, double* %5
%8 = load i32, i32* @genann_act_sigmoid_cached.initialized
%9 = icmp ne i32 %8, 0
br i1 %9, label %27, label %10
10: ; preds = %1
store double 0x3F7E000000000000, double* @genann_act_sigmoid_cached.interval
store i32 0, i32* %6
br label %11
11: ; preds = %23, %10
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 4096
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = load double, double* @genann_act_sigmoid_cached.interval
%16 = load i32, i32* %6
%17 = sitofp i32 %16 to double
%18 = call double @llvm.fmuladd.f64(double %15, double %17, double -1.500000e+01)
%19 = call double @genann_act_sigmoid(double %18)
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [4096 x double], [4096 x double]* @genann_act_sigmoid_cached.lookup, i64 0, i64 %21
store double %19, double* %22
br label %23
23: ; preds = %14
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %11
26: ; preds = %11
store i32 1, i32* @genann_act_sigmoid_cached.initialized
br label %27
27: ; preds = %26, %1
%28 = load double, double* %3
%29 = fsub double %28, -1.500000e+01
%30 = load double, double* @genann_act_sigmoid_cached.interval
%31 = fdiv double %29, %30
%32 = fadd double %31, 5.000000e-01
%33 = fptosi double %32 to i32
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp sle i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = load double, double* getelementptr inbounds ([4096 x double], [4096 x double]* @genann_act_sigmoid_cached.lookup, i64 0, i64 0)
store double %37, double* %2
br label %48
38: ; preds = %27
%39 = load i32, i32* %7
%40 = icmp sge i32 %39, 4096
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = load double, double* getelementptr inbounds ([4096 x double], [4096 x double]* @genann_act_sigmoid_cached.lookup, i64 0, i64 4095)
store double %42, double* %2
br label %48
43: ; preds = %38
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [4096 x double], [4096 x double]* @genann_act_sigmoid_cached.lookup, i64 0, i64 %45
%47 = load double, double* %46
store double %47, double* %2
br label %48
48: ; preds = %43, %41, %36
%49 = load double, double* %2
ret double %49
}

LLVM IR (-O2):
@genann_act_sigmoid_cached.interval = internal unnamed_addr global double 0.000000e+00
@genann_act_sigmoid_cached.initialized = internal unnamed_addr global i1 false
@genann_act_sigmoid_cached.lookup = internal unnamed_addr global [4096 x double] zeroinitializer
define double @genann_act_sigmoid_cached(double %0) {
%2 = load i1, i1* @genann_act_sigmoid_cached.initialized
br i1 %2, label %16, label %3
3: ; preds = %1
store double 0x3F7E000000000000, double* @genann_act_sigmoid_cached.interval
%4 = tail call double @genann_act_sigmoid(double -1.500000e+01)
store double %4, double* getelementptr inbounds ([4096 x double], [4096 x double]* @genann_act_sigmoid_cached.lookup, i64 0, i64 0)
br label %5
5: ; preds = %3, %5
%6 = phi i64 [ 1, %3 ], [ %13, %5 ]
%7 = load double, double* @genann_act_sigmoid_cached.interval
%8 = trunc i64 %6 to i32
%9 = sitofp i32 %8 to double
%10 = tail call double @llvm.fmuladd.f64(double %7, double %9, double -1.500000e+01)
%11 = tail call double @genann_act_sigmoid(double %10)
%12 = getelementptr inbounds [4096 x double], [4096 x double]* @genann_act_sigmoid_cached.lookup, i64 0, i64 %6
store double %11, double* %12
%13 = add nuw nsw i64 %6, 1
%14 = icmp eq i64 %13, 4096
br i1 %14, label %15, label %5
15: ; preds = %5
store i1 true, i1* @genann_act_sigmoid_cached.initialized
br label %16
16: ; preds = %15, %1
%17 = fadd double %0, 1.500000e+01
%18 = load double, double* @genann_act_sigmoid_cached.interval
%19 = fdiv double %17, %18
%20 = fadd double %19, 5.000000e-01
%21 = fptosi double %20 to i32
%22 = icmp slt i32 %21, 1
br i1 %22, label %28, label %23
23: ; preds = %16
%24 = icmp ugt i32 %21, 4095
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = zext i32 %21 to i64
%27 = getelementptr inbounds [4096 x double], [4096 x double]* @genann_act_sigmoid_cached.lookup, i64 0, i64 %26
br label %28
28: ; preds = %23, %16, %25
%29 = phi double* [ %27, %25 ], [ getelementptr inbounds ([4096 x double], [4096 x double]* @genann_act_sigmoid_cached.lookup, i64 0, i64 0), %16 ], [ getelementptr inbounds ([4096 x double], [4096 x double]* @genann_act_sigmoid_cached.lookup, i64 0, i64 4095), %23 ]
%30 = load double, double* %29
ret double %30
}