#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 cos(double);
double pow(double, double);
double sin(double);
double function(double *param, int dimension, int functiontype, double x) {
  int i;
  double fun = 0;
  switch (functiontype) {
  case 1: {
    for (i = 0; i <= dimension; i++) {
      fun += param[i] * (pow(x, i));
    }
    break;
  }
  case 2: {
    double a = param[0];
    double b = param[1];
    double n = param[2];
    fun = a * (pow(2.7182818284, x)) + b * (pow(x, n));
    break;
  }
  case 3: {
    double A = param[0];
    double m = param[1];
    double t = param[2];
    double B = param[3];
    double n = param[4];
    double p = param[5];
    fun = A * (sin(m * x + t)) + B * (cos(n * x + p));
    break;
  }
  }
  return fun;
}


x86 assembly (clang, -O0):
<function>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x74(%rbp)
sub    $0x1,%eax
je     1188 <function+0x58>
jmp    1166 <function+0x36>
mov    -0x74(%rbp),%eax
sub    $0x2,%eax
je     11e9 <function+0xb9>
jmp    1177 <function+0x47>
mov    -0x74(%rbp),%eax
sub    $0x3,%eax
je     1286 <function+0x156>
jmp    135f <function+0x22f>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11e4 <function+0xb4>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
call   1050 <pow@plt>
movaps %xmm0,%xmm2
movsd  -0x80(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118f <function+0x5f>
jmp    135f <function+0x22f>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x18(%rbp),%xmm1
movsd  0xdd4(%rip),%xmm0
call   1050 <pow@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x18(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
call   1050 <pow@plt>
movsd  -0x98(%rbp),%xmm1
ff
movsd  -0x90(%rbp),%xmm2
ff
movaps %xmm0,%xmm3
movsd  -0x88(%rbp),%xmm0
ff
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    135f <function+0x22f>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x20(%rax),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x28(%rax),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x50(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x70(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  -0xb0(%rbp),%xmm1
ff
movsd  -0xa8(%rbp),%xmm2
ff
movaps %xmm0,%xmm3
movsd  -0xa0(%rbp),%xmm0
ff
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<function>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
movapd %xmm0,%xmm1
mov    %rdi,%r14
cmp    $0x3,%edx
je     118d <function+0x5d>
cmp    $0x2,%edx
je     11e9 <function+0xb9>
xorpd  %xmm0,%xmm0
cmp    $0x1,%edx
jne    124a <function+0x11a>
test   %esi,%esi
js     124a <function+0x11a>
movsd  %xmm1,0x10(%rsp)
mov    %esi,%r12d
add    $0x1,%r12
mov    %r12d,%r15d
and    $0x3,%r15d
cmp    $0x3,%esi
jae    1256 <function+0x126>
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    1331 <function+0x201>
movsd  (%r14),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x18(%r14),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%r14),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x10(%r14),%xmm0
mulsd  0x20(%r14),%xmm1
addsd  0x28(%r14),%xmm1
movsd  %xmm1,0x10(%rsp)
call   1030 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <cos@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
jmp    1241 <function+0x111>
movsd  (%r14),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%r14),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%r14),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xded(%rip),%xmm0
movsd  %xmm1,0x10(%rsp)
call   1050 <pow@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
call   1050 <pow@plt>
mulsd  0x8(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
mulsd  (%rsp),%xmm1
addsd  %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
and    $0xfffffffc,%r12d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
movsd  %xmm0,(%rsp)
movsd  (%r14,%rbx,8),%xmm1
movsd  %xmm1,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movsd  0x10(%rsp),%xmm0
call   1050 <pow@plt>
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x1(%rbx),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x10(%rsp),%xmm0
call   1050 <pow@plt>
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x10(%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x2(%rbx),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x10(%rsp),%xmm0
call   1050 <pow@plt>
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x18(%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0x3(%rbx),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x10(%rsp),%xmm0
call   1050 <pow@plt>
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
add    $0x4,%rbx
cmp    %r12,%rbx
jne    1260 <function+0x130>
test   %r15,%r15
movsd  0x10(%rsp),%xmm2
je     124a <function+0x11a>
movsd  %xmm0,(%rsp)
movsd  (%r14,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
movapd %xmm2,%xmm0
call   1050 <pow@plt>
movsd  0x10(%rsp),%xmm2
mulsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
jne    1340 <function+0x210>
jmp    124a <function+0x11a>

LLVM IR (-O0):
define double @function(double* %0, i32 %1, i32 %2, double %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
store double* %0, double** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store double %3, double* %8
store double 0.000000e+00, double* %10
%20 = load i32, i32* %7
switch i32 %20, label %94 [
i32 1, label %21
i32 2, label %42
i32 3, label %61
]
21: ; preds = %4
store i32 0, i32* %9
br label %22
22: ; preds = %38, %21
%23 = load i32, i32* %9
%24 = load i32, i32* %6
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %41
26: ; preds = %22
%27 = load double*, double** %5
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = load double, double* %8
%33 = load i32, i32* %9
%34 = sitofp i32 %33 to double
%35 = call double @pow(double %32, double %34)
%36 = load double, double* %10
%37 = call double @llvm.fmuladd.f64(double %31, double %35, double %36)
store double %37, double* %10
br label %38
38: ; preds = %26
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
store i32 %40, i32* %9
br label %22
41: ; preds = %22
br label %94
42: ; preds = %4
%43 = load double*, double** %5
%44 = getelementptr inbounds double, double* %43, i64 0
%45 = load double, double* %44
store double %45, double* %11
%46 = load double*, double** %5
%47 = getelementptr inbounds double, double* %46, i64 1
%48 = load double, double* %47
store double %48, double* %12
%49 = load double*, double** %5
%50 = getelementptr inbounds double, double* %49, i64 2
%51 = load double, double* %50
store double %51, double* %13
%52 = load double, double* %11
%53 = load double, double* %8
%54 = call double @pow(double 0x4005BF0A8B12500B, double %53)
%55 = load double, double* %12
%56 = load double, double* %8
%57 = load double, double* %13
%58 = call double @pow(double %56, double %57)
%59 = fmul double %55, %58
%60 = call double @llvm.fmuladd.f64(double %52, double %54, double %59)
store double %60, double* %10
br label %94
61: ; preds = %4
%62 = load double*, double** %5
%63 = getelementptr inbounds double, double* %62, i64 0
%64 = load double, double* %63
store double %64, double* %14
%65 = load double*, double** %5
%66 = getelementptr inbounds double, double* %65, i64 1
%67 = load double, double* %66
store double %67, double* %15
%68 = load double*, double** %5
%69 = getelementptr inbounds double, double* %68, i64 2
%70 = load double, double* %69
store double %70, double* %16
%71 = load double*, double** %5
%72 = getelementptr inbounds double, double* %71, i64 3
%73 = load double, double* %72
store double %73, double* %17
%74 = load double*, double** %5
%75 = getelementptr inbounds double, double* %74, i64 4
%76 = load double, double* %75
store double %76, double* %18
%77 = load double*, double** %5
%78 = getelementptr inbounds double, double* %77, i64 5
%79 = load double, double* %78
store double %79, double* %19
%80 = load double, double* %14
%81 = load double, double* %15
%82 = load double, double* %8
%83 = load double, double* %16
%84 = call double @llvm.fmuladd.f64(double %81, double %82, double %83)
%85 = call double @sin(double %84)
%86 = load double, double* %17
%87 = load double, double* %18
%88 = load double, double* %8
%89 = load double, double* %19
%90 = call double @llvm.fmuladd.f64(double %87, double %88, double %89)
%91 = call double @cos(double %90)
%92 = fmul double %86, %91
%93 = call double @llvm.fmuladd.f64(double %80, double %85, double %92)
store double %93, double* %10
br label %94
94: ; preds = %4, %61, %42, %41
%95 = load double, double* %10
ret double %95
}

LLVM IR (-O2):
define double @function(double* nocapture %0, i32 %1, i32 %2, double %3) {
switch i32 %2, label %95 [
i32 1, label %5
i32 2, label %49
i32 3, label %59
]
5: ; preds = %4
%6 = icmp slt i32 %1, 0
br i1 %6, label %95, label %7
7: ; preds = %5
%8 = add nuw i32 %1, 1
%9 = zext i32 %8 to i64
%10 = add nsw i64 %9, -1
%11 = and i64 %9, 3
%12 = icmp ult i64 %10, 3
br i1 %12, label %77, label %13
13: ; preds = %7
%14 = and i64 %9, 4294967292
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 0, %13 ], [ %46, %15 ]
%17 = phi double [ 0.000000e+00, %13 ], [ %45, %15 ]
%18 = phi i64 [ 0, %13 ], [ %47, %15 ]
%19 = getelementptr inbounds double, double* %0, i64 %16
%20 = load double, double* %19
%21 = trunc i64 %16 to i32
%22 = sitofp i32 %21 to double
%23 = tail call double @pow(double %3, double %22)
%24 = tail call double @llvm.fmuladd.f64(double %20, double %23, double %17)
%25 = or i64 %16, 1
%26 = getelementptr inbounds double, double* %0, i64 %25
%27 = load double, double* %26
%28 = trunc i64 %25 to i32
%29 = sitofp i32 %28 to double
%30 = tail call double @pow(double %3, double %29)
%31 = tail call double @llvm.fmuladd.f64(double %27, double %30, double %24)
%32 = or i64 %16, 2
%33 = getelementptr inbounds double, double* %0, i64 %32
%34 = load double, double* %33
%35 = trunc i64 %32 to i32
%36 = sitofp i32 %35 to double
%37 = tail call double @pow(double %3, double %36)
%38 = tail call double @llvm.fmuladd.f64(double %34, double %37, double %31)
%39 = or i64 %16, 3
%40 = getelementptr inbounds double, double* %0, i64 %39
%41 = load double, double* %40
%42 = trunc i64 %39 to i32
%43 = sitofp i32 %42 to double
%44 = tail call double @pow(double %3, double %43)
%45 = tail call double @llvm.fmuladd.f64(double %41, double %44, double %38)
%46 = add nuw nsw i64 %16, 4
%47 = add i64 %18, 4
%48 = icmp eq i64 %47, %14
br i1 %48, label %77, label %15
49: ; preds = %4
%50 = load double, double* %0
%51 = getelementptr inbounds double, double* %0, i64 1
%52 = load double, double* %51
%53 = getelementptr inbounds double, double* %0, i64 2
%54 = load double, double* %53
%55 = tail call double @pow(double 0x4005BF0A8B12500B, double %3)
%56 = tail call double @pow(double %3, double %54)
%57 = fmul double %52, %56
%58 = tail call double @llvm.fmuladd.f64(double %50, double %55, double %57)
br label %95
59: ; preds = %4
%60 = load double, double* %0
%61 = getelementptr inbounds double, double* %0, i64 1
%62 = load double, double* %61
%63 = getelementptr inbounds double, double* %0, i64 2
%64 = load double, double* %63
%65 = getelementptr inbounds double, double* %0, i64 3
%66 = load double, double* %65
%67 = getelementptr inbounds double, double* %0, i64 4
%68 = load double, double* %67
%69 = getelementptr inbounds double, double* %0, i64 5
%70 = load double, double* %69
%71 = tail call double @llvm.fmuladd.f64(double %62, double %3, double %64)
%72 = tail call double @sin(double %71)
%73 = tail call double @llvm.fmuladd.f64(double %68, double %3, double %70)
%74 = tail call double @cos(double %73)
%75 = fmul double %66, %74
%76 = tail call double @llvm.fmuladd.f64(double %60, double %72, double %75)
br label %95
77: ; preds = %15, %7
%78 = phi double [ undef, %7 ], [ %45, %15 ]
%79 = phi i64 [ 0, %7 ], [ %46, %15 ]
%80 = phi double [ 0.000000e+00, %7 ], [ %45, %15 ]
%81 = icmp eq i64 %11, 0
br i1 %81, label %95, label %82
82: ; preds = %77, %82
%83 = phi i64 [ %92, %82 ], [ %79, %77 ]
%84 = phi double [ %91, %82 ], [ %80, %77 ]
%85 = phi i64 [ %93, %82 ], [ 0, %77 ]
%86 = getelementptr inbounds double, double* %0, i64 %83
%87 = load double, double* %86
%88 = trunc i64 %83 to i32
%89 = sitofp i32 %88 to double
%90 = tail call double @pow(double %3, double %89)
%91 = tail call double @llvm.fmuladd.f64(double %87, double %90, double %84)
%92 = add nuw nsw i64 %83, 1
%93 = add i64 %85, 1
%94 = icmp eq i64 %93, %11
br i1 %94, label %95, label %82
95: ; preds = %77, %82, %5, %4, %59, %49
%96 = phi double [ 0.000000e+00, %4 ], [ %76, %59 ], [ %58, %49 ], [ 0.000000e+00, %5 ], [ %78, %77 ], [ %91, %82 ]
ret double %96
}