#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);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, char const *);
double sin(double);
scalar_t__ strcmp(char const *, char *);
double f(const char *funname, double x) {
  if (strcmp(funname, "poly") == 0)
    return (x * x - 4);
  else if (strcmp(funname, "cos") == 0)
    return (cos(x) - x * x * x);
  else if (strcmp(funname, "sin") == 0)
    return (sin(x) - .5);
  else if (strcmp(funname, "xsin") == 0)
    return (x * sin(x) - 10);
  else if (strcmp(funname, "imaginary") == 0)
    return (x * x + 1);
  else {
    printf("Error: %s is not a valid function name\n", funname);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb4(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    119f <f+0x4f>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe87(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e0 <f+0x190>
mov    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11fe <f+0xae>
movsd  -0x18(%rbp),%xmm0
call   1060 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e0 <f+0x190>
mov    -0x10(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1238 <f+0xe8>
movsd  -0x18(%rbp),%xmm0
call   1050 <sin@plt>
movsd  0xde6(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e0 <f+0x190>
mov    -0x10(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1288 <f+0x138>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xd8e(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e0 <f+0x190>
mov    -0x10(%rbp),%rdi
lea    0xd9b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12c6 <f+0x176>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd48(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12e0 <f+0x190>
mov    -0x10(%rbp),%rsi
lea    0xd67(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
lea    0xebb(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11d3 <f+0x83>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e7 <f+0x97>
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     120a <f+0xba>
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     121f <f+0xcf>
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    123e <f+0xee>
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  0xe2f(%rip),%xmm0
jmp    1238 <f+0xe8>
movsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  0xe33(%rip),%xmm0
jmp    1238 <f+0xe8>
movsd  0x8(%rsp),%xmm0
call   1060 <cos@plt>
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
jmp    1238 <f+0xe8>
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
addsd  0xdf3(%rip),%xmm0
jmp    1238 <f+0xe8>
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
mulsd  0x8(%rsp),%xmm0
addsd  0xdd0(%rip),%xmm0
add    $0x10,%rsp
pop    %rbx
ret
lea    0xdf3(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"poly\00"
@.str.1 = [4 x i8] c"cos\00"
@.str.2 = [4 x i8] c"sin\00"
@.str.3 = [5 x i8] c"xsin\00"
@.str.4 = [10 x i8] c"imaginary\00"
@.str.5 = [40 x i8] c"Error: %s is not a valid function name\0A\00"
define double @f(i8* %0, double %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca double
store i8* %0, i8** %4
store double %1, double* %5
%6 = load i8*, i8** %4
%7 = call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load double, double* %5
%11 = load double, double* %5
%12 = call double @llvm.fmuladd.f64(double %10, double %11, double -4.000000e+00)
store double %12, double* %3
br label %55
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load double, double* %5
%19 = call double @cos(double %18)
%20 = load double, double* %5
%21 = load double, double* %5
%22 = fmul double %20, %21
%23 = load double, double* %5
%24 = fneg double %22
%25 = call double @llvm.fmuladd.f64(double %24, double %23, double %19)
store double %25, double* %3
br label %55
26: ; preds = %13
%27 = load i8*, i8** %4
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load double, double* %5
%32 = call double @sin(double %31)
%33 = fsub double %32, 5.000000e-01
store double %33, double* %3
br label %55
34: ; preds = %26
%35 = load i8*, i8** %4
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load double, double* %5
%40 = load double, double* %5
%41 = call double @sin(double %40)
%42 = call double @llvm.fmuladd.f64(double %39, double %41, double -1.000000e+01)
store double %42, double* %3
br label %55
43: ; preds = %34
%44 = load i8*, i8** %4
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = load double, double* %5
%49 = load double, double* %5
%50 = call double @llvm.fmuladd.f64(double %48, double %49, double 1.000000e+00)
store double %50, double* %3
br label %55
51: ; preds = %43
%52 = load i8*, i8** %4
%53 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %47, %38, %30, %17, %9
%56 = load double, double* %3
ret double %56
}

LLVM IR (-O2):
@.str = [5 x i8] c"poly\00"
@.str.1 = [4 x i8] c"cos\00"
@.str.2 = [4 x i8] c"sin\00"
@.str.3 = [5 x i8] c"xsin\00"
@.str.4 = [10 x i8] c"imaginary\00"
@.str.5 = [40 x i8] c"Error: %s is not a valid function name\0A\00"
define double @f(i8* %0, double %1) {
%3 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call double @llvm.fmuladd.f64(double %1, double %1, double -4.000000e+00)
br label %35
7: ; preds = %2
%8 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = tail call double @cos(double %1)
%12 = fneg double %1
%13 = fmul double %12, %1
%14 = tail call double @llvm.fmuladd.f64(double %13, double %1, double %11)
br label %35
15: ; preds = %7
%16 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call double @sin(double %1)
%20 = fadd double %19, -5.000000e-01
br label %35
21: ; preds = %15
%22 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = tail call double @sin(double %1)
%26 = tail call double @llvm.fmuladd.f64(double %1, double %25, double -1.000000e+01)
br label %35
27: ; preds = %21
%28 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = tail call double @llvm.fmuladd.f64(double %1, double %1, double 1.000000e+00)
br label %35
32: ; preds = %27
%33 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %30, %24, %18, %10, %5
%36 = phi double [ %6, %5 ], [ %14, %10 ], [ %20, %18 ], [ %26, %24 ], [ %31, %30 ]
ret double %36
}