#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 fabs(double);
double calc_cross_field(double f00, double f10, double f11, double f01) {
  double value;
  if (fabs(f00 + f11 - f01 - f10) < 0.00000001)
    value = (f00 + f11 + f01 + f10) / 4.0;
  else
    value = ((f00 * f11 - f10 * f01) / (f00 + f11 - f01 - f10));
  return value;
}


x86 assembly (clang, -O0):
<calc_cross_field>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm1
addsd  -0x18(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movaps 0xedd(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xec1(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1173 <calc_cross_field+0x73>
movsd  -0x8(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xea3(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11c3 <calc_cross_field+0xc3>
movsd  -0x8(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x8(%rbp),%xmm1
addsd  -0x18(%rbp),%xmm1
subsd  -0x20(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_cross_field>:
movapd %xmm0,%xmm4
addsd  %xmm2,%xmm0
movapd %xmm0,%xmm5
subsd  %xmm3,%xmm5
subsd  %xmm1,%xmm5
movapd 0xee4(%rip),%xmm6
andpd  %xmm5,%xmm6
movsd  0xee8(%rip),%xmm7
ucomisd %xmm6,%xmm7
jbe    113f <calc_cross_field+0x3f>
addsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
mulsd  0xeda(%rip),%xmm0
ret
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm4
subsd  %xmm1,%xmm4
divsd  %xmm5,%xmm4
movapd %xmm4,%xmm0
ret

LLVM IR (-O0):
define double @calc_cross_field(double %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%10 = load double, double* %5
%11 = load double, double* %7
%12 = fadd double %10, %11
%13 = load double, double* %8
%14 = fsub double %12, %13
%15 = load double, double* %6
%16 = fsub double %14, %15
%17 = call double @llvm.fabs.f64(double %16)
%18 = fcmp olt double %17, 1.000000e-08
br i1 %18, label %19, label %28
19: ; preds = %4
%20 = load double, double* %5
%21 = load double, double* %7
%22 = fadd double %20, %21
%23 = load double, double* %8
%24 = fadd double %22, %23
%25 = load double, double* %6
%26 = fadd double %24, %25
%27 = fdiv double %26, 4.000000e+00
store double %27, double* %9
br label %44
28: ; preds = %4
%29 = load double, double* %5
%30 = load double, double* %7
%31 = load double, double* %6
%32 = load double, double* %8
%33 = fmul double %31, %32
%34 = fneg double %33
%35 = call double @llvm.fmuladd.f64(double %29, double %30, double %34)
%36 = load double, double* %5
%37 = load double, double* %7
%38 = fadd double %36, %37
%39 = load double, double* %8
%40 = fsub double %38, %39
%41 = load double, double* %6
%42 = fsub double %40, %41
%43 = fdiv double %35, %42
store double %43, double* %9
br label %44
44: ; preds = %28, %19
%45 = load double, double* %9
ret double %45
}

LLVM IR (-O2):
define double @calc_cross_field(double %0, double %1, double %2, double %3) {
%5 = fadd double %0, %2
%6 = fsub double %5, %3
%7 = fsub double %6, %1
%8 = tail call double @llvm.fabs.f64(double %7)
%9 = fcmp olt double %8, 1.000000e-08
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = fadd double %5, %3
%12 = fadd double %11, %1
%13 = fmul double %12, 2.500000e-01
br label %19
14: ; preds = %4
%15 = fneg double %1
%16 = fmul double %15, %3
%17 = tail call double @llvm.fmuladd.f64(double %0, double %2, double %16)
%18 = fdiv double %17, %7
br label %19
19: ; preds = %14, %10
%20 = phi double [ %13, %10 ], [ %18, %14 ]
ret double %20
}