#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*/ cosh(double);
double log(double);
double pow(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
double tanh(double);
double df(double C, double b, double a, int q, int r) {
  if (q == 2 && r == 1) {
    if (b != 0.0) {
      return (C * (1.0 / pow(cosh(b * C / a), 2)) * (b / a) + tanh(b * C / a));
    } else {
      printf("function df(q=2,r=1,b=0) returns -99999.99\n");
      return -99999.99;
    }
  } else if (q == 1 && r == 2) {
    return (2.0 * (log(C - 1.0) - log(C)) +
            2.0 * C * (1.0 / (C - 1.0) - 1.0 / C));
  } else {
    printf("q,r not implemented: function df returns -99999.99\n");
    return -99999.99;
  }
}


x86 assembly (clang, -O0):
<df>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %edi,-0x24(%rbp)
mov    %esi,-0x28(%rbp)
cmpl   $0x2,-0x24(%rbp)
jne    1245 <df+0xf5>
cmpl   $0x1,-0x28(%rbp)
jne    1245 <df+0xf5>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    119e <df+0x4e>
jp     119e <df+0x4e>
jmp    1227 <df+0xd7>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1040 <cosh@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1070 <pow@plt>
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movsd  0xe30(%rip),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1030 <tanh@plt>
movsd  -0x38(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12f4 <df+0x1a4>
lea    0xdea(%rip),%rdi
call   1050 <printf@plt>
movsd  0xdc5(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12f4 <df+0x1a4>
cmpl   $0x1,-0x24(%rbp)
jne    12db <df+0x18b>
cmpl   $0x2,-0x28(%rbp)
jne    12db <df+0x18b>
movsd  -0x10(%rbp),%xmm0
movsd  0xda2(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xd7e(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm3
movsd  0xd64(%rip),%xmm2
subsd  %xmm2,%xmm3
movsd  0xd58(%rip),%xmm2
divsd  %xmm3,%xmm2
movsd  0xd4c(%rip),%xmm3
divsd  -0x10(%rbp),%xmm3
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12f4 <df+0x1a4>
lea    0xd62(%rip),%rdi
call   1050 <printf@plt>
movsd  0xd11(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<df>:
sub    $0x38,%rsp
movapd %xmm0,%xmm3
cmp    $0x2,%edi
jne    11e5 <df+0x95>
cmp    $0x1,%esi
jne    11e5 <df+0x95>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1176 <df+0x26>
jnp    126f <df+0x11f>
movapd %xmm3,%xmm0
mulsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
movapd %xmm0,0x20(%rsp)
movapd %xmm3,0x10(%rsp)
movsd  %xmm1,(%rsp)
movsd  %xmm2,0x30(%rsp)
call   1050 <cosh@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1070 <pow@plt>
movsd  0xe5e(%rip),%xmm1
divsd  %xmm0,%xmm1
mulsd  0x10(%rsp),%xmm1
movsd  (%rsp),%xmm0
divsd  0x30(%rsp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
movapd 0x20(%rsp),%xmm0
call   1040 <tanh@plt>
addsd  (%rsp),%xmm0
add    $0x38,%rsp
ret
cmp    $0x1,%edi
jne    1266 <df+0x116>
cmp    $0x2,%esi
jne    1266 <df+0x116>
movsd  0xe09(%rip),%xmm0
addsd  %xmm3,%xmm0
movapd %xmm0,(%rsp)
movapd %xmm3,0x10(%rsp)
call   1060 <log@plt>
movsd  %xmm0,0x20(%rsp)
movapd 0x10(%rsp),%xmm0
call   1060 <log@plt>
movsd  0x20(%rsp),%xmm3
subsd  %xmm0,%xmm3
movapd 0x10(%rsp),%xmm0
movapd (%rsp),%xmm1
unpcklpd %xmm0,%xmm1
addsd  %xmm0,%xmm0
movapd 0xddf(%rip),%xmm2
divpd  %xmm1,%xmm2
movapd %xmm2,%xmm1
unpckhpd %xmm2,%xmm1
subsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm2
movapd %xmm3,%xmm0
addsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
add    $0x38,%rsp
ret
lea    0xdc3(%rip),%rdi
jmp    1276 <df+0x126>
lea    0xded(%rip),%rdi
call   1030 <puts@plt>
movsd  0xd85(%rip),%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"function df(q=2,r=1,b=0) returns -99999.99\0A\00"
@.str.1 = [52 x i8] c"q,r not implemented: function df returns -99999.99\0A\00"
define double @df(double %0, double %1, double %2, i32 %3, i32 %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%12 = load i32, i32* %10
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %43
14: ; preds = %5
%15 = load i32, i32* %11
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %43
17: ; preds = %14
%18 = load double, double* %8
%19 = fcmp une double %18, 0.000000e+00
br i1 %19, label %20, label %41
20: ; preds = %17
%21 = load double, double* %7
%22 = load double, double* %8
%23 = load double, double* %7
%24 = fmul double %22, %23
%25 = load double, double* %9
%26 = fdiv double %24, %25
%27 = call i32 @cosh(double %26)
%28 = call double @pow(i32 %27, i32 2)
%29 = fdiv double 1.000000e+00, %28
%30 = fmul double %21, %29
%31 = load double, double* %8
%32 = load double, double* %9
%33 = fdiv double %31, %32
%34 = load double, double* %8
%35 = load double, double* %7
%36 = fmul double %34, %35
%37 = load double, double* %9
%38 = fdiv double %36, %37
%39 = call double @tanh(double %38)
%40 = call double @llvm.fmuladd.f64(double %30, double %33, double %39)
store double %40, double* %6
br label %68
41: ; preds = %17
%42 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
store double 0xC0F869FFD70A3D71, double* %6
br label %68
43: ; preds = %14, %5
%44 = load i32, i32* %10
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %66
46: ; preds = %43
%47 = load i32, i32* %11
%48 = icmp eq i32 %47, 2
br i1 %48, label %49, label %66
49: ; preds = %46
%50 = load double, double* %7
%51 = fsub double %50, 1.000000e+00
%52 = call double @log(double %51)
%53 = load double, double* %7
%54 = call double @log(double %53)
%55 = fsub double %52, %54
%56 = load double, double* %7
%57 = fmul double 2.000000e+00, %56
%58 = load double, double* %7
%59 = fsub double %58, 1.000000e+00
%60 = fdiv double 1.000000e+00, %59
%61 = load double, double* %7
%62 = fdiv double 1.000000e+00, %61
%63 = fsub double %60, %62
%64 = fmul double %57, %63
%65 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %55, double %64)
store double %65, double* %6
br label %68
66: ; preds = %46, %43
%67 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
store double 0xC0F869FFD70A3D71, double* %6
br label %68
68: ; preds = %66, %49, %41, %20
%69 = load double, double* %6
ret double %69
}

LLVM IR (-O2):
@str = [51 x i8] c"q,r not implemented: function df returns -99999.99\00"
@str.2 = [43 x i8] c"function df(q=2,r=1,b=0) returns -99999.99\00"
define double @df(double %0, double %1, double %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %3, 2
%7 = icmp eq i32 %4, 1
%8 = and i1 %6, %7
br i1 %8, label %9, label %23
9: ; preds = %5
%10 = fcmp une double %1, 0.000000e+00
br i1 %10, label %11, label %21
11: ; preds = %9
%12 = fmul double %0, %1
%13 = fdiv double %12, %2
%14 = tail call i32 @cosh(double %13)
%15 = tail call double @pow(i32 %14, i32 2)
%16 = fdiv double 1.000000e+00, %15
%17 = fmul double %16, %0
%18 = fdiv double %1, %2
%19 = tail call double @tanh(double %13)
%20 = tail call double @llvm.fmuladd.f64(double %17, double %18, double %19)
br label %43
21: ; preds = %9
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.2, i64 0, i64 0))
br label %43
23: ; preds = %5
%24 = icmp eq i32 %3, 1
%25 = icmp eq i32 %4, 2
%26 = and i1 %24, %25
br i1 %26, label %27, label %41
27: ; preds = %23
%28 = fadd double %0, -1.000000e+00
%29 = tail call double @log(double %28)
%30 = tail call double @log(double %0)
%31 = fsub double %29, %30
%32 = fmul double %0, 2.000000e+00
%33 = insertelement <2 x double> poison, double %0, i64 1
%34 = insertelement <2 x double> %33, double %28, i64 0
%35 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %34
%36 = shufflevector <2 x double> %35, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%37 = fsub <2 x double> %35, %36
%38 = extractelement <2 x double> %37, i64 0
%39 = fmul double %32, %38
%40 = tail call double @llvm.fmuladd.f64(double %31, double 2.000000e+00, double %39)
br label %43
41: ; preds = %23
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
br label %43
43: ; preds = %41, %27, %21, %11
%44 = phi double [ %20, %11 ], [ 0xC0F869FFD70A3D71, %21 ], [ %40, %27 ], [ 0xC0F869FFD70A3D71, %41 ]
ret double %44
}