#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 exp(double);
double c(double x, double y, int I) {
  double speed;
  if (I == 1) {
    if (y < 0.0)
      y = 0.0;
    else if (y > 1.0)
      y = 1.0;
    return (2.0 -
            0.5 * (cos(3.141592 * (y - 0.5)) * cos(3.141592 * (y - 0.5))));
  } else if (I == 2) {
    speed = 2.5 - 0.4 * y;
    speed = speed - 0.8 * exp(-10.0 * (y - 0.3) * (y - 0.3)) *
                        exp(-20.0 * (x - 0.25) * (x - 0.25));
    return (speed);
  }
  return (0);
}


x86 assembly (clang, -O0):
<c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    11fa <c+0xda>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    115a <c+0x3a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1183 <c+0x63>
movsd  -0x18(%rbp),%xmm0
movsd  0xed1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    117e <c+0x5e>
movsd  0xebf(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1183 <c+0x63>
movsd  -0x18(%rbp),%xmm1
movsd  0xec8(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xeb4(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  0xea1(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xe8d(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe60(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe5c(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ff <c+0x1df>
cmpl   $0x2,-0x1c(%rbp)
jne    12f2 <c+0x1d2>
movsd  -0x18(%rbp),%xmm0
movsd  0xe17(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe13(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  0xddb(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xdd7(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xdbe(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  0xd9e(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  0xd78(%rip),%xmm0
subsd  %xmm0,%xmm1
movsd  0xd74(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xd5b(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ff <c+0x1df>
jmp    12f7 <c+0x1d7>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<c>:
sub    $0x18,%rsp
cmp    $0x2,%edi
je     1199 <c+0x79>
xorpd  %xmm0,%xmm0
cmp    $0x1,%edi
jne    1217 <c+0xf7>
ucomisd %xmm1,%xmm0
ja     1152 <c+0x32>
ucomisd 0xef4(%rip),%xmm1
movapd %xmm1,%xmm0
jbe    1152 <c+0x32>
movsd  0xee6(%rip),%xmm0
addsd  0xee6(%rip),%xmm0
mulsd  0xee6(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <cos@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <cos@plt>
mulsd  0x10(%rsp),%xmm0
mulsd  0xeb4(%rip),%xmm0
addsd  0xebc(%rip),%xmm0
add    $0x18,%rsp
ret
movsd  %xmm0,0x8(%rsp)
movsd  0xe59(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe55(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
addsd  0xe4f(%rip),%xmm1
movsd  0xe4f(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  0x8(%rsp),%xmm1
addsd  0xe3c(%rip),%xmm1
movsd  %xmm0,0x8(%rsp)
movsd  0xe36(%rip),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  0x8(%rsp),%xmm1
mulsd  0xe23(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @c(double %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %31
11: ; preds = %3
%12 = load double, double* %6
%13 = fcmp olt double %12, 0.000000e+00
br i1 %13, label %14, label %15
14: ; preds = %11
store double 0.000000e+00, double* %6
br label %20
15: ; preds = %11
%16 = load double, double* %6
%17 = fcmp ogt double %16, 1.000000e+00
br i1 %17, label %18, label %19
18: ; preds = %15
store double 1.000000e+00, double* %6
br label %19
19: ; preds = %18, %15
br label %20
20: ; preds = %19, %14
%21 = load double, double* %6
%22 = fsub double %21, 5.000000e-01
%23 = fmul double 0x400921FAFC8B007A, %22
%24 = call double @cos(double %23)
%25 = load double, double* %6
%26 = fsub double %25, 5.000000e-01
%27 = fmul double 0x400921FAFC8B007A, %26
%28 = call double @cos(double %27)
%29 = fmul double %24, %28
%30 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %29, double 2.000000e+00)
store double %30, double* %4
br label %58
31: ; preds = %3
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 2
br i1 %33, label %34, label %56
34: ; preds = %31
%35 = load double, double* %6
%36 = call double @llvm.fmuladd.f64(double -4.000000e-01, double %35, double 2.500000e+00)
store double %36, double* %8
%37 = load double, double* %8
%38 = load double, double* %6
%39 = fsub double %38, 3.000000e-01
%40 = fmul double -1.000000e+01, %39
%41 = load double, double* %6
%42 = fsub double %41, 3.000000e-01
%43 = fmul double %40, %42
%44 = call double @exp(double %43)
%45 = fmul double 8.000000e-01, %44
%46 = load double, double* %5
%47 = fsub double %46, 2.500000e-01
%48 = fmul double -2.000000e+01, %47
%49 = load double, double* %5
%50 = fsub double %49, 2.500000e-01
%51 = fmul double %48, %50
%52 = call double @exp(double %51)
%53 = fneg double %45
%54 = call double @llvm.fmuladd.f64(double %53, double %52, double %37)
store double %54, double* %8
%55 = load double, double* %8
store double %55, double* %4
br label %58
56: ; preds = %31
br label %57
57: ; preds = %56
store double 0.000000e+00, double* %4
br label %58
58: ; preds = %57, %34, %20
%59 = load double, double* %4
ret double %59
}

LLVM IR (-O2):
define double @c(double %0, double %1, i32 %2) {
switch i32 %2, label %29 [
i32 1, label %4
i32 2, label %17
]
4: ; preds = %3
%5 = fcmp olt double %1, 0.000000e+00
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = fcmp ogt double %1, 1.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %6
br label %9
9: ; preds = %4, %6, %8
%10 = phi double [ 1.000000e+00, %8 ], [ %1, %6 ], [ 0.000000e+00, %4 ]
%11 = fadd double %10, -5.000000e-01
%12 = fmul double %11, 0x400921FAFC8B007A
%13 = tail call double @cos(double %12)
%14 = tail call double @cos(double %12)
%15 = fmul double %13, %14
%16 = tail call double @llvm.fmuladd.f64(double %15, double -5.000000e-01, double 2.000000e+00)
br label %29
17: ; preds = %3
%18 = tail call double @llvm.fmuladd.f64(double %1, double -4.000000e-01, double 2.500000e+00)
%19 = fadd double %1, -3.000000e-01
%20 = fmul double %19, -1.000000e+01
%21 = fmul double %19, %20
%22 = tail call double @exp(double %21)
%23 = fadd double %0, -2.500000e-01
%24 = fmul double %23, -2.000000e+01
%25 = fmul double %23, %24
%26 = tail call double @exp(double %25)
%27 = fmul double %22, -8.000000e-01
%28 = tail call double @llvm.fmuladd.f64(double %27, double %26, double %18)
br label %29
29: ; preds = %3, %17, %9
%30 = phi double [ %16, %9 ], [ %28, %17 ], [ 0.000000e+00, %3 ]
ret double %30
}