#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 a(double);
double b(double);
double c(double);
double d(double);
double f(double x, int q) {
  switch (q) {
  case 1:
    return a(x);
    break;
  case 2:
    return b(x);
    break;
  case 3:
    return c(x);
    break;
  case 4:
    return d(x);
    break;
  default:
    return -1;
    break;
  }
}


x86 assembly (clang, -O0):
<f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     11c9 <f+0x89>
mov    -0x20(%rbp),%rax
lea    0xe98(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x10(%rbp),%xmm0
call   1060 <a@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11d6 <f+0x96>
movsd  -0x10(%rbp),%xmm0
call   1040 <b@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11d6 <f+0x96>
movsd  -0x10(%rbp),%xmm0
call   1050 <c@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11d6 <f+0x96>
movsd  -0x10(%rbp),%xmm0
call   1030 <d@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11d6 <f+0x96>
movsd  0xe2f(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f>:
add    $0xffffffff,%edi
cmp    $0x3,%edi
ja     115d <f+0x1d>
lea    0xeb9(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
jmp    1060 <a@plt>
movsd  0xe9b(%rip),%xmm0
ret
jmp    1040 <b@plt>
jmp    1050 <c@plt>
jmp    1030 <d@plt>

LLVM IR (-O0):
define double @f(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
switch i32 %6, label %19 [
i32 1, label %7
i32 2, label %10
i32 3, label %13
i32 4, label %16
]
7: ; preds = %2
%8 = load double, double* %4
%9 = call double @a(double %8)
store double %9, double* %3
br label %20
10: ; preds = %2
%11 = load double, double* %4
%12 = call double @b(double %11)
store double %12, double* %3
br label %20
13: ; preds = %2
%14 = load double, double* %4
%15 = call double @c(double %14)
store double %15, double* %3
br label %20
16: ; preds = %2
%17 = load double, double* %4
%18 = call double @d(double %17)
store double %18, double* %3
br label %20
19: ; preds = %2
store double -1.000000e+00, double* %3
br label %20
20: ; preds = %19, %16, %13, %10, %7
%21 = load double, double* %3
ret double %21
}

LLVM IR (-O2):
define double @f(double %0, i32 %1) {
switch i32 %1, label %11 [
i32 1, label %3
i32 2, label %5
i32 3, label %7
i32 4, label %9
]
3: ; preds = %2
%4 = tail call double @a(double %0)
br label %11
5: ; preds = %2
%6 = tail call double @b(double %0)
br label %11
7: ; preds = %2
%8 = tail call double @c(double %0)
br label %11
9: ; preds = %2
%10 = tail call double @d(double %0)
br label %11
11: ; preds = %2, %9, %7, %5, %3
%12 = phi double [ %10, %9 ], [ %8, %7 ], [ %6, %5 ], [ %4, %3 ], [ -1.000000e+00, %2 ]
ret double %12
}