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


x86 assembly (clang, -O0):
<f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    11dc <f+0xac>
cmpl   $0x1,-0x28(%rbp)
jne    11dc <f+0xac>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117e <f+0x4e>
jp     117e <f+0x4e>
jmp    11be <f+0x8e>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
call   1030 <tanh@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe68(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1279 <f+0x149>
lea    0xe5b(%rip),%rdi
call   1040 <printf@plt>
movsd  0xe2e(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1279 <f+0x149>
cmpl   $0x1,-0x24(%rbp)
jne    1260 <f+0x130>
cmpl   $0x2,-0x28(%rbp)
jne    1260 <f+0x130>
movsd  0xe10(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe01(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdc4(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1279 <f+0x149>
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
movsd  0xd8c(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f>:
sub    $0x28,%rsp
movapd %xmm0,%xmm3
cmp    $0x2,%edi
jne    117a <f+0x4a>
cmp    $0x1,%esi
jne    117a <f+0x4a>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1152 <f+0x22>
jnp    11f7 <f+0xc7>
mulsd  %xmm3,%xmm1
divsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
movsd  %xmm3,(%rsp)
call   1040 <tanh@plt>
mulsd  (%rsp),%xmm0
addsd  0xe93(%rip),%xmm0
add    $0x28,%rsp
ret
cmp    $0x1,%edi
jne    11ee <f+0xbe>
cmp    $0x2,%esi
jne    11ee <f+0xbe>
movapd %xmm3,%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xe6e(%rip),%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm1,0x20(%rsp)
movsd  %xmm2,0x10(%rsp)
movsd  %xmm3,(%rsp)
call   1050 <log@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1050 <log@plt>
movsd  0x20(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
subsd  %xmm0,%xmm2
mulsd  0x18(%rsp),%xmm2
addsd  0xe2e(%rip),%xmm2
divsd  0x10(%rsp),%xmm1
addsd  %xmm2,%xmm1
jmp    120b <f+0xdb>
lea    0xe23(%rip),%rdi
jmp    11fe <f+0xce>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
movsd  0xdf5(%rip),%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"function f(q=2,r=1,b=0) returns -99999.99\0A\00"
@.str.1 = [51 x i8] c"q,r not implemented: function f returns -99999.99\0A\00"
define double @f(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 %31
14: ; preds = %5
%15 = load i32, i32* %11
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %31
17: ; preds = %14
%18 = load double, double* %8
%19 = fcmp une double %18, 0.000000e+00
br i1 %19, label %20, label %29
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 double @tanh(double %26)
%28 = call double @llvm.fmuladd.f64(double %21, double %27, double -1.000000e+00)
store double %28, double* %6
br label %53
29: ; preds = %17
%30 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store double 0xC0F869FFD70A3D71, double* %6
br label %53
31: ; preds = %14, %5
%32 = load i32, i32* %10
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %51
34: ; preds = %31
%35 = load i32, i32* %11
%36 = icmp eq i32 %35, 2
br i1 %36, label %37, label %51
37: ; preds = %34
%38 = load double, double* %7
%39 = fmul double 2.000000e+00, %38
%40 = load double, double* %7
%41 = fsub double %40, 1.000000e+00
%42 = call double @log(double %41)
%43 = load double, double* %7
%44 = call double @log(double %43)
%45 = fsub double %42, %44
%46 = call double @llvm.fmuladd.f64(double %39, double %45, double 2.000000e+00)
%47 = load double, double* %8
%48 = load double, double* %9
%49 = fdiv double %47, %48
%50 = fadd double %46, %49
store double %50, double* %6
br label %53
51: ; preds = %34, %31
%52 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
store double 0xC0F869FFD70A3D71, double* %6
br label %53
53: ; preds = %51, %37, %29, %20
%54 = load double, double* %6
ret double %54
}

LLVM IR (-O2):
@str = [50 x i8] c"q,r not implemented: function f returns -99999.99\00"
@str.2 = [42 x i8] c"function f(q=2,r=1,b=0) returns -99999.99\00"
define double @f(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 %18
9: ; preds = %5
%10 = fcmp une double %1, 0.000000e+00
br i1 %10, label %11, label %16
11: ; preds = %9
%12 = fmul double %0, %1
%13 = fdiv double %12, %2
%14 = tail call double @tanh(double %13)
%15 = tail call double @llvm.fmuladd.f64(double %0, double %14, double -1.000000e+00)
br label %33
16: ; preds = %9
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.2, i64 0, i64 0))
br label %33
18: ; preds = %5
%19 = icmp eq i32 %3, 1
%20 = icmp eq i32 %4, 2
%21 = and i1 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = fmul double %0, 2.000000e+00
%24 = fadd double %0, -1.000000e+00
%25 = tail call double @log(double %24)
%26 = tail call double @log(double %0)
%27 = fsub double %25, %26
%28 = tail call double @llvm.fmuladd.f64(double %23, double %27, double 2.000000e+00)
%29 = fdiv double %1, %2
%30 = fadd double %29, %28
br label %33
31: ; preds = %18
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %31, %22, %16, %11
%34 = phi double [ %15, %11 ], [ 0xC0F869FFD70A3D71, %16 ], [ %30, %22 ], [ 0xC0F869FFD70A3D71, %31 ]
ret double %34
}