#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 */
struct twobody_f {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ twobody_far(int, int, double, double, double *);
int /*<<< orphan*/ twobody_lub_with_f(int, struct twobody_f *, int, double,
                                      double, double *);
int /*<<< orphan*/ twobody_scale(int, double *, double, double);
int /*<<< orphan*/ twobody_scale_SD(int, double *, double);
void twobody_scalars_res(int version, double r, double aa, double ab,
                         struct twobody_f *f12, int n, int flag_lub,
                         int flag_scale, double *res) {
  double l = ab / aa;
  double s = 2.0 * r / (aa + ab);
  if (flag_lub == 0) {
    twobody_far(version, n, l, s, res);
  } else {
    twobody_lub_with_f(version, f12, n, l, s, res);
  }
  if (flag_scale == 1) {
    twobody_scale(version, res, aa, l);
  } else if (flag_scale == 2) {
    twobody_scale_SD(version, res, l);
  }
}


x86 assembly (clang, -O0):
<twobody_scalars_res>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %edx,-0x2c(%rbp)
mov    %ecx,-0x30(%rbp)
mov    %r8d,-0x34(%rbp)
mov    %r9,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xe7d(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
addsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    11c3 <twobody_scalars_res+0x83>
mov    -0x4(%rbp),%edi
mov    -0x2c(%rbp),%esi
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
mov    -0x40(%rbp),%rdx
call   1050 <twobody_far@plt>
jmp    11e0 <twobody_scalars_res+0xa0>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
mov    -0x40(%rbp),%rcx
call   1040 <twobody_lub_with_f@plt>
cmpl   $0x1,-0x34(%rbp)
jne    1205 <twobody_scalars_res+0xc5>
mov    -0x4(%rbp),%edi
mov    -0x40(%rbp),%rsi
movsd  -0x18(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
call   1060 <twobody_scale@plt>
jmp    1225 <twobody_scalars_res+0xe5>
cmpl   $0x2,-0x34(%rbp)
jne    1220 <twobody_scalars_res+0xe0>
mov    -0x4(%rbp),%edi
mov    -0x40(%rbp),%rsi
movsd  -0x48(%rbp),%xmm0
call   1030 <twobody_scale_SD@plt>
jmp    1225 <twobody_scalars_res+0xe5>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twobody_scalars_res>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r9,%r14
mov    %r8d,%ebp
movapd %xmm0,%xmm3
mov    %edi,%ebx
addsd  %xmm0,%xmm3
movapd %xmm1,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm1,0x8(%rsp)
divsd  %xmm1,%xmm2
divsd  %xmm0,%xmm3
test   %ecx,%ecx
movsd  %xmm2,(%rsp)
je     11ae <twobody_scalars_res+0x6e>
movapd %xmm2,%xmm0
movapd %xmm3,%xmm1
mov    %r14,%rcx
call   1040 <twobody_lub_with_f@plt>
cmp    $0x2,%ebp
je     11c5 <twobody_scalars_res+0x85>
cmp    $0x1,%ebp
movsd  (%rsp),%xmm1
jne    11dc <twobody_scalars_res+0x9c>
mov    %ebx,%edi
mov    %r14,%rsi
movsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <twobody_scale@plt>
mov    %edx,%esi
movapd %xmm2,%xmm0
movapd %xmm3,%xmm1
mov    %r14,%rdx
call   1050 <twobody_far@plt>
cmp    $0x2,%ebp
jne    118c <twobody_scalars_res+0x4c>
mov    %ebx,%edi
mov    %r14,%rsi
movsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <twobody_scale_SD@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.twobody_f = type { i32 }
define void @twobody_scalars_res(i32 %0, double %1, double %2, double %3, %struct.twobody_f* %4, i32 %5, i32 %6, i32 %7, double* %8) {
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca %struct.twobody_f*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca double*
%19 = alloca double
%20 = alloca double
store i32 %0, i32* %10
store double %1, double* %11
store double %2, double* %12
store double %3, double* %13
store %struct.twobody_f* %4, %struct.twobody_f** %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store double* %8, double** %18
%21 = load double, double* %13
%22 = load double, double* %12
%23 = fdiv double %21, %22
store double %23, double* %19
%24 = load double, double* %11
%25 = fmul double 2.000000e+00, %24
%26 = load double, double* %12
%27 = load double, double* %13
%28 = fadd double %26, %27
%29 = fdiv double %25, %28
store double %29, double* %20
%30 = load i32, i32* %16
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %9
%33 = load i32, i32* %10
%34 = load i32, i32* %15
%35 = load double, double* %19
%36 = load double, double* %20
%37 = load double*, double** %18
%38 = call i32 @twobody_far(i32 %33, i32 %34, double %35, double %36, double* %37)
br label %47
39: ; preds = %9
%40 = load i32, i32* %10
%41 = load %struct.twobody_f*, %struct.twobody_f** %14
%42 = load i32, i32* %15
%43 = load double, double* %19
%44 = load double, double* %20
%45 = load double*, double** %18
%46 = call i32 @twobody_lub_with_f(i32 %40, %struct.twobody_f* %41, i32 %42, double %43, double %44, double* %45)
br label %47
47: ; preds = %39, %32
%48 = load i32, i32* %17
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = load i32, i32* %10
%52 = load double*, double** %18
%53 = load double, double* %12
%54 = load double, double* %19
%55 = call i32 @twobody_scale(i32 %51, double* %52, double %53, double %54)
br label %65
56: ; preds = %47
%57 = load i32, i32* %17
%58 = icmp eq i32 %57, 2
br i1 %58, label %59, label %64
59: ; preds = %56
%60 = load i32, i32* %10
%61 = load double*, double** %18
%62 = load double, double* %19
%63 = call i32 @twobody_scale_SD(i32 %60, double* %61, double %62)
br label %64
64: ; preds = %59, %56
br label %65
65: ; preds = %64, %50
ret void
}

LLVM IR (-O2):
%struct.twobody_f = type { i32 }
define void @twobody_scalars_res(i32 %0, double %1, double %2, double %3, %struct.twobody_f* %4, i32 %5, i32 %6, i32 %7, double* %8) {
%10 = fdiv double %3, %2
%11 = fmul double %1, 2.000000e+00
%12 = fadd double %2, %3
%13 = fdiv double %11, %12
%14 = icmp eq i32 %6, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 @twobody_far(i32 %0, i32 %5, double %10, double %13, double* %8)
br label %19
17: ; preds = %9
%18 = tail call i32 @twobody_lub_with_f(i32 %0, %struct.twobody_f* %4, i32 %5, double %10, double %13, double* %8)
br label %19
19: ; preds = %17, %15
switch i32 %7, label %24 [
i32 1, label %20
i32 2, label %22
]
20: ; preds = %19
%21 = tail call i32 @twobody_scale(i32 %0, double* %8, double %2, double %10)
br label %24
22: ; preds = %19
%23 = tail call i32 @twobody_scale_SD(i32 %0, double* %8, double %10)
br label %24
24: ; preds = %19, %22, %20
ret void
}