#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 sqrt(double);
double sum(double r1, double r2) {
  if (r1 <= 1e-6)
    return r2;
  else if (r2 <= 1e-6)
    return r1;
  return sqrt((r1 + r2) * (r1 + r2) - (r1 - r2) * (r1 - r2));
}


x86 assembly (clang, -O0):
<sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  0xed6(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1144 <sum+0x34>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c0 <sum+0xb0>
movsd  0xeb4(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1166 <sum+0x56>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c0 <sum+0xb0>
jmp    116b <sum+0x5b>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
addsd  -0x18(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm3
subsd  -0x18(%rbp),%xmm3
mulsd  %xmm3,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum>:
movsd  0xee8(%rip),%xmm2
ucomisd %xmm0,%xmm2
jae    114d <sum+0x3d>
ucomisd %xmm1,%xmm2
jae    1151 <sum+0x41>
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
subsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
mulsd  %xmm2,%xmm2
subsd  %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jb     1152 <sum+0x42>
xorps  %xmm1,%xmm1
sqrtsd %xmm2,%xmm1
movapd %xmm1,%xmm0
ret
movapd %xmm2,%xmm0
jmp    1030 <sqrt@plt>

LLVM IR (-O0):
define double @sum(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = fcmp ole double %6, 0x3EB0C6F7A0B5ED8D
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load double, double* %5
store double %9, double* %3
br label %33
10: ; preds = %2
%11 = load double, double* %5
%12 = fcmp ole double %11, 0x3EB0C6F7A0B5ED8D
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load double, double* %4
store double %14, double* %3
br label %33
15: ; preds = %10
br label %16
16: ; preds = %15
%17 = load double, double* %4
%18 = load double, double* %5
%19 = fadd double %17, %18
%20 = load double, double* %4
%21 = load double, double* %5
%22 = fadd double %20, %21
%23 = load double, double* %4
%24 = load double, double* %5
%25 = fsub double %23, %24
%26 = load double, double* %4
%27 = load double, double* %5
%28 = fsub double %26, %27
%29 = fmul double %25, %28
%30 = fneg double %29
%31 = call double @llvm.fmuladd.f64(double %19, double %22, double %30)
%32 = call double @sqrt(double %31)
store double %32, double* %3
br label %33
33: ; preds = %16, %13, %8
%34 = load double, double* %3
ret double %34
}

LLVM IR (-O2):
define double @sum(double %0, double %1) {
%3 = fcmp ugt double %0, 0x3EB0C6F7A0B5ED8D
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = fcmp ugt double %1, 0x3EB0C6F7A0B5ED8D
br i1 %5, label %6, label %13
6: ; preds = %4
%7 = fadd double %0, %1
%8 = fsub double %0, %1
%9 = fneg double %8
%10 = fmul double %8, %9
%11 = tail call double @llvm.fmuladd.f64(double %7, double %7, double %10)
%12 = tail call double @sqrt(double %11)
br label %13
13: ; preds = %4, %2, %6
%14 = phi double [ %12, %6 ], [ %1, %2 ], [ %0, %4 ]
ret double %14
}