#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);
double pow(double, double);
double dqwgts(double x, double a, double b, double alpha, double beta,
              int wgtfunc) {
  double bmx, xma, result;
  xma = x - a;
  bmx = b - x;
  result = pow(xma, alpha) * pow(bmx, beta);
  switch (wgtfunc) {
  case 1:
    return result;
  case 2:
    return result * log(xma);
  case 3:
    return result * log(bmx);
  case 4:
    return result * log(xma) * log(bmx);
  default:
    return result;
  }
}


x86 assembly (clang, -O0):
<dqwgts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
mov    %edi,-0x34(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
call   1040 <pow@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
call   1040 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x58(%rbp)
sub    $0x3,%eax
ja     1272 <dqwgts+0x152>
mov    -0x58(%rbp),%rax
lea    0xe3f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127c <dqwgts+0x15c>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127c <dqwgts+0x15c>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127c <dqwgts+0x15c>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x80(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127c <dqwgts+0x15c>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dqwgts>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
movsd  %xmm4,(%rsp)
subsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
subsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movaps %xmm3,%xmm1
call   1040 <pow@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
call   1040 <pow@plt>
movapd %xmm0,%xmm1
mulsd  0x18(%rsp),%xmm1
cmp    $0x2,%ebx
je     117f <dqwgts+0x5f>
cmp    $0x4,%ebx
je     1187 <dqwgts+0x67>
cmp    $0x3,%ebx
movsd  0x8(%rsp),%xmm0
je     11a6 <dqwgts+0x86>
jmp    11b9 <dqwgts+0x99>
movsd  0x10(%rsp),%xmm0
jmp    11a6 <dqwgts+0x86>
movsd  0x10(%rsp),%xmm0
movsd  %xmm1,(%rsp)
call   1030 <log@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
movsd  %xmm1,(%rsp)
call   1030 <log@plt>
movsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @dqwgts(double %0, double %1, double %2, double %3, double %4, i32 %5) {
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
store double %0, double* %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store double %4, double* %12
store i32 %5, i32* %13
%17 = load double, double* %8
%18 = load double, double* %9
%19 = fsub double %17, %18
store double %19, double* %15
%20 = load double, double* %10
%21 = load double, double* %8
%22 = fsub double %20, %21
store double %22, double* %14
%23 = load double, double* %15
%24 = load double, double* %11
%25 = call double @pow(double %23, double %24)
%26 = load double, double* %14
%27 = load double, double* %12
%28 = call double @pow(double %26, double %27)
%29 = fmul double %25, %28
store double %29, double* %16
%30 = load i32, i32* %13
switch i32 %30, label %51 [
i32 1, label %31
i32 2, label %33
i32 3, label %38
i32 4, label %43
]
31: ; preds = %6
%32 = load double, double* %16
store double %32, double* %7
br label %53
33: ; preds = %6
%34 = load double, double* %16
%35 = load double, double* %15
%36 = call double @log(double %35)
%37 = fmul double %34, %36
store double %37, double* %7
br label %53
38: ; preds = %6
%39 = load double, double* %16
%40 = load double, double* %14
%41 = call double @log(double %40)
%42 = fmul double %39, %41
store double %42, double* %7
br label %53
43: ; preds = %6
%44 = load double, double* %16
%45 = load double, double* %15
%46 = call double @log(double %45)
%47 = fmul double %44, %46
%48 = load double, double* %14
%49 = call double @log(double %48)
%50 = fmul double %47, %49
store double %50, double* %7
br label %53
51: ; preds = %6
%52 = load double, double* %16
store double %52, double* %7
br label %53
53: ; preds = %51, %43, %38, %33, %31
%54 = load double, double* %7
ret double %54
}

LLVM IR (-O2):
define double @dqwgts(double %0, double %1, double %2, double %3, double %4, i32 %5) {
%7 = fsub double %0, %1
%8 = fsub double %2, %0
%9 = tail call double @pow(double %7, double %3)
%10 = tail call double @pow(double %8, double %4)
%11 = fmul double %9, %10
switch i32 %5, label %21 [
i32 4, label %13
i32 2, label %16
i32 3, label %12
]
12: ; preds = %6
br label %16
13: ; preds = %6
%14 = tail call double @log(double %7)
%15 = fmul double %11, %14
br label %16
16: ; preds = %6, %12, %13
%17 = phi double [ %8, %13 ], [ %8, %12 ], [ %7, %6 ]
%18 = phi double [ %15, %13 ], [ %11, %12 ], [ %11, %6 ]
%19 = tail call double @log(double %17)
%20 = fmul double %18, %19
br label %21
21: ; preds = %16, %6
%22 = phi double [ %11, %6 ], [ %20, %16 ]
ret double %22
}