#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 atan2(double, double);
double sqrt(double);
double rotary_two_arm_calc(double dx, double dy, double upper_arm2,
                           double lower_arm2) {
  double inv_dy = 1. / dy;
  double c1 = .5 * inv_dy * (dx * dx + dy * dy + upper_arm2 - lower_arm2);
  double c2 = dx * inv_dy;
  double scale = c2 * c2 + 1.0;
  double scaled_elbow_x = c1 * c2 + sqrt(scale * upper_arm2 - c1 * c1);
  double scaled_elbow_y = c1 * scale - c2 * scaled_elbow_x;
  return atan2(scaled_elbow_y, scaled_elbow_x);
}


x86 assembly (clang, -O0):
<rotary_two_arm_calc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  0xebc(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xeb2(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm2
mulsd  -0x10(%rbp),%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
addsd  -0x18(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe51(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  -0x60(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
call   1030 <atan2@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rotary_two_arm_calc>:
sub    $0x18,%rsp
movapd %xmm0,%xmm6
movsd  0xed0(%rip),%xmm0
movapd %xmm0,%xmm5
divsd  %xmm1,%xmm5
movsd  0xec8(%rip),%xmm4
mulsd  %xmm5,%xmm4
mulsd  %xmm1,%xmm1
mulsd  %xmm6,%xmm5
mulsd  %xmm6,%xmm6
addsd  %xmm1,%xmm6
addsd  %xmm2,%xmm6
subsd  %xmm3,%xmm6
mulsd  %xmm4,%xmm6
movapd %xmm5,%xmm3
mulsd  %xmm5,%xmm3
addsd  %xmm0,%xmm3
movapd %xmm6,%xmm0
mulsd  %xmm6,%xmm0
mulsd  %xmm3,%xmm2
subsd  %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jb     118f <rotary_two_arm_calc+0x6f>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
jmp    11ba <rotary_two_arm_calc+0x9a>
movapd %xmm2,%xmm0
movsd  %xmm5,0x10(%rsp)
movsd  %xmm6,0x8(%rsp)
movsd  %xmm3,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm3
movsd  0x8(%rsp),%xmm6
movsd  0x10(%rsp),%xmm5
movapd %xmm6,%xmm1
mulsd  %xmm5,%xmm1
addsd  %xmm0,%xmm1
mulsd  %xmm1,%xmm5
mulsd  %xmm6,%xmm3
subsd  %xmm5,%xmm3
movapd %xmm3,%xmm0
add    $0x18,%rsp
jmp    1030 <atan2@plt>

LLVM IR (-O0):
define double @rotary_two_arm_calc(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%15 = load double, double* %6
%16 = fdiv double 1.000000e+00, %15
store double %16, double* %9
%17 = load double, double* %9
%18 = fmul double 5.000000e-01, %17
%19 = load double, double* %5
%20 = load double, double* %5
%21 = load double, double* %6
%22 = load double, double* %6
%23 = fmul double %21, %22
%24 = call double @llvm.fmuladd.f64(double %19, double %20, double %23)
%25 = load double, double* %7
%26 = fadd double %24, %25
%27 = load double, double* %8
%28 = fsub double %26, %27
%29 = fmul double %18, %28
store double %29, double* %10
%30 = load double, double* %5
%31 = load double, double* %9
%32 = fmul double %30, %31
store double %32, double* %11
%33 = load double, double* %11
%34 = load double, double* %11
%35 = call double @llvm.fmuladd.f64(double %33, double %34, double 1.000000e+00)
store double %35, double* %12
%36 = load double, double* %10
%37 = load double, double* %11
%38 = load double, double* %12
%39 = load double, double* %7
%40 = load double, double* %10
%41 = load double, double* %10
%42 = fmul double %40, %41
%43 = fneg double %42
%44 = call double @llvm.fmuladd.f64(double %38, double %39, double %43)
%45 = call double @sqrt(double %44)
%46 = call double @llvm.fmuladd.f64(double %36, double %37, double %45)
store double %46, double* %13
%47 = load double, double* %10
%48 = load double, double* %12
%49 = load double, double* %11
%50 = load double, double* %13
%51 = fmul double %49, %50
%52 = fneg double %51
%53 = call double @llvm.fmuladd.f64(double %47, double %48, double %52)
store double %53, double* %14
%54 = load double, double* %14
%55 = load double, double* %13
%56 = call double @atan2(double %54, double %55)
ret double %56
}

LLVM IR (-O2):
define double @rotary_two_arm_calc(double %0, double %1, double %2, double %3) {
%5 = fdiv double 1.000000e+00, %1
%6 = fmul double %5, 5.000000e-01
%7 = fmul double %1, %1
%8 = tail call double @llvm.fmuladd.f64(double %0, double %0, double %7)
%9 = fadd double %8, %2
%10 = fsub double %9, %3
%11 = fmul double %6, %10
%12 = fmul double %5, %0
%13 = tail call double @llvm.fmuladd.f64(double %12, double %12, double 1.000000e+00)
%14 = fneg double %11
%15 = fmul double %11, %14
%16 = tail call double @llvm.fmuladd.f64(double %13, double %2, double %15)
%17 = tail call double @sqrt(double %16)
%18 = tail call double @llvm.fmuladd.f64(double %11, double %12, double %17)
%19 = fneg double %12
%20 = fmul double %18, %19
%21 = tail call double @llvm.fmuladd.f64(double %11, double %13, double %20)
%22 = tail call double @atan2(double %21, double %18)
ret double %22
}