#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 */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ exp(double);
int /*<<< orphan*/ printf(char *);
double tanh(double);
double activation(int type, double x) {
  switch (type) {
  case 0:
    return (tanh(x));
    break;
  case 1:
    return (1. / (1. + exp(-x)));
    break;
  case 2:
    return x;
    break;
  case 3:
    return (1. + x);
    break;
  case 4:
    return (1. + x + x * x);
    break;
  default:
    printf("unknown activation function!\n");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<activation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x4,%rax
ja     121f <activation+0xdf>
mov    -0x20(%rbp),%rax
lea    0xe9c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x18(%rbp),%xmm0
call   1030 <tanh@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1232 <activation+0xf2>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1050 <exp@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe4a(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0xe3e(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1232 <activation+0xf2>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1232 <activation+0xf2>
movsd  0xe19(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1232 <activation+0xf2>
movsd  0xe02(%rip),%xmm1
addsd  -0x18(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1232 <activation+0xf2>
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<activation>:
push   %rax
cmp    $0x4,%edi
ja     11a0 <activation+0x60>
mov    %edi,%eax
lea    0xed1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
pop    %rax
jmp    1040 <tanh@plt>
xorps  0xeab(%rip),%xmm0
call   1050 <exp@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe8a(%rip),%xmm0
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm0
pop    %rax
ret
addsd  0xe78(%rip),%xmm0
pop    %rax
ret
movsd  0xe6e(%rip),%xmm1
addsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
pop    %rax
ret
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"unknown activation function!\0A\00"
define double @activation(i32 %0, double %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
store i32 %0, i32* %4
store double %1, double* %5
%6 = load i32, i32* %4
switch i32 %6, label %28 [
i32 0, label %7
i32 1, label %10
i32 2, label %17
i32 3, label %19
i32 4, label %22
]
7: ; preds = %2
%8 = load double, double* %5
%9 = call double @tanh(double %8)
store double %9, double* %3
br label %31
10: ; preds = %2
%11 = load double, double* %5
%12 = fneg double %11
%13 = call i32 @exp(double %12)
%14 = sitofp i32 %13 to double
%15 = fadd double 1.000000e+00, %14
%16 = fdiv double 1.000000e+00, %15
store double %16, double* %3
br label %31
17: ; preds = %2
%18 = load double, double* %5
store double %18, double* %3
br label %31
19: ; preds = %2
%20 = load double, double* %5
%21 = fadd double 1.000000e+00, %20
store double %21, double* %3
br label %31
22: ; preds = %2
%23 = load double, double* %5
%24 = fadd double 1.000000e+00, %23
%25 = load double, double* %5
%26 = load double, double* %5
%27 = call double @llvm.fmuladd.f64(double %25, double %26, double %24)
store double %27, double* %3
br label %31
28: ; preds = %2
%29 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %22, %19, %17, %10, %7
%32 = load double, double* %3
ret double %32
}

LLVM IR (-O2):
@str = [29 x i8] c"unknown activation function!\00"
define double @activation(i32 %0, double %1) {
switch i32 %0, label %16 [
i32 0, label %3
i32 1, label %5
i32 2, label %19
i32 3, label %11
i32 4, label %13
]
3: ; preds = %2
%4 = tail call double @tanh(double %1)
br label %19
5: ; preds = %2
%6 = fneg double %1
%7 = tail call i32 @exp(double %6)
%8 = sitofp i32 %7 to double
%9 = fadd double %8, 1.000000e+00
%10 = fdiv double 1.000000e+00, %9
br label %19
11: ; preds = %2
%12 = fadd double %1, 1.000000e+00
br label %19
13: ; preds = %2
%14 = fadd double %1, 1.000000e+00
%15 = tail call double @llvm.fmuladd.f64(double %1, double %1, double %14)
br label %19
16: ; preds = %2
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %2, %13, %11, %5, %3
%20 = phi double [ %15, %13 ], [ %12, %11 ], [ %10, %5 ], [ %4, %3 ], [ %1, %2 ]
ret double %20
}