#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 */
int /*<<< orphan*/ my_assert_greaterDouble(char *, double, int /*<<< orphan*/);
double my_math_pctIntersection(double start1, double end1, double start2,
                               double end2) {
  if (end1 <= start2 || end2 <= start1) {
    return 0;
  } else if ((start2 <= start1 && end1 <= end2) ||
             (start1 <= start2 && end2 <= end1)) {
    return 1;
  }
  double l1 = end1 - start1;
  double l2 = end2 - start2;
  if (l1 <= 0 || l2 <= 0)
    return 1;
  double l12 = end2 - start1;
  double l21 = end1 - start2;
  my_assert_greaterDouble("l12", l12, 0);
  my_assert_greaterDouble("l21", l21, 0);
  return ((l12) > (l21) ? (l21) : (l12)) / ((l1) > (l2) ? (l2) : (l1));
}


x86 assembly (clang, -O0):
<my_math_pctIntersection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jae    1154 <my_math_pctIntersection+0x44>
movsd  -0x28(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1161 <my_math_pctIntersection+0x51>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c7 <my_math_pctIntersection+0x1b7>
movsd  -0x20(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1189 <my_math_pctIntersection+0x79>
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jae    11b1 <my_math_pctIntersection+0xa1>
movsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11c3 <my_math_pctIntersection+0xb3>
movsd  -0x28(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11c3 <my_math_pctIntersection+0xb3>
movsd  0xe47(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c7 <my_math_pctIntersection+0x1b7>
jmp    11c8 <my_math_pctIntersection+0xb8>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jae    1202 <my_math_pctIntersection+0xf2>
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     1214 <my_math_pctIntersection+0x104>
movsd  0xdf6(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c7 <my_math_pctIntersection+0x1b7>
movsd  -0x28(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
lea    0xdca(%rip),%rdi
xor    %esi,%esi
call   1030 <my_assert_greaterDouble@plt>
movsd  -0x48(%rbp),%xmm0
lea    0xdbb(%rip),%rdi
xor    %esi,%esi
call   1030 <my_assert_greaterDouble@plt>
movsd  -0x40(%rbp),%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1277 <my_math_pctIntersection+0x167>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    1281 <my_math_pctIntersection+0x171>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    12aa <my_math_pctIntersection+0x19a>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    12b4 <my_math_pctIntersection+0x1a4>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_math_pctIntersection>:
sub    $0x28,%rsp
movapd %xmm0,%xmm4
ucomisd %xmm1,%xmm2
xorpd  %xmm0,%xmm0
jae    113c <my_math_pctIntersection+0x2c>
ucomisd %xmm3,%xmm4
jae    113c <my_math_pctIntersection+0x2c>
ucomisd %xmm2,%xmm4
movsd  0xecc(%rip),%xmm0
jb     1141 <my_math_pctIntersection+0x31>
ucomisd %xmm1,%xmm3
jb     1141 <my_math_pctIntersection+0x31>
add    $0x28,%rsp
ret
ucomisd %xmm4,%xmm2
jb     114d <my_math_pctIntersection+0x3d>
ucomisd %xmm3,%xmm1
jae    113c <my_math_pctIntersection+0x2c>
movapd %xmm1,%xmm6
subsd  %xmm4,%xmm6
xorpd  %xmm5,%xmm5
ucomisd %xmm6,%xmm5
jae    113c <my_math_pctIntersection+0x2c>
movapd %xmm3,%xmm7
subsd  %xmm2,%xmm7
ucomisd %xmm7,%xmm5
jae    113c <my_math_pctIntersection+0x2c>
subsd  %xmm4,%xmm3
movsd  %xmm3,0x10(%rsp)
subsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xe80(%rip),%rdi
movapd %xmm3,%xmm0
xor    %esi,%esi
movsd  %xmm6,0x20(%rsp)
movsd  %xmm7,0x18(%rsp)
call   1030 <my_assert_greaterDouble@plt>
lea    0xe66(%rip),%rdi
movsd  0x8(%rsp),%xmm0
xor    %esi,%esi
call   1030 <my_assert_greaterDouble@plt>
movsd  0x8(%rsp),%xmm0
minsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
minsd  0x20(%rsp),%xmm1
divsd  %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"l12\00"
@.str.1 = [4 x i8] c"l21\00"
define double @my_math_pctIntersection(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
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%14 = load double, double* %7
%15 = load double, double* %8
%16 = fcmp ole double %14, %15
br i1 %16, label %21, label %17
17: ; preds = %4
%18 = load double, double* %9
%19 = load double, double* %6
%20 = fcmp ole double %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17, %4
store double 0.000000e+00, double* %5
br label %83
22: ; preds = %17
%23 = load double, double* %8
%24 = load double, double* %6
%25 = fcmp ole double %23, %24
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load double, double* %7
%28 = load double, double* %9
%29 = fcmp ole double %27, %28
br i1 %29, label %38, label %30
30: ; preds = %26, %22
%31 = load double, double* %6
%32 = load double, double* %8
%33 = fcmp ole double %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load double, double* %9
%36 = load double, double* %7
%37 = fcmp ole double %35, %36
br i1 %37, label %38, label %39
38: ; preds = %34, %26
store double 1.000000e+00, double* %5
br label %83
39: ; preds = %34, %30
br label %40
40: ; preds = %39
%41 = load double, double* %7
%42 = load double, double* %6
%43 = fsub double %41, %42
store double %43, double* %10
%44 = load double, double* %9
%45 = load double, double* %8
%46 = fsub double %44, %45
store double %46, double* %11
%47 = load double, double* %10
%48 = fcmp ole double %47, 0.000000e+00
br i1 %48, label %52, label %49
49: ; preds = %40
%50 = load double, double* %11
%51 = fcmp ole double %50, 0.000000e+00
br i1 %51, label %52, label %53
52: ; preds = %49, %40
store double 1.000000e+00, double* %5
br label %83
53: ; preds = %49
%54 = load double, double* %9
%55 = load double, double* %6
%56 = fsub double %54, %55
store double %56, double* %12
%57 = load double, double* %7
%58 = load double, double* %8
%59 = fsub double %57, %58
store double %59, double* %13
%60 = load double, double* %12
%61 = call i32 @my_assert_greaterDouble(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %60, i32 0)
%62 = load double, double* %13
%63 = call i32 @my_assert_greaterDouble(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %62, i32 0)
%64 = load double, double* %12
%65 = load double, double* %13
%66 = fcmp ogt double %64, %65
br i1 %66, label %67, label %69
67: ; preds = %53
%68 = load double, double* %13
br label %71
69: ; preds = %53
%70 = load double, double* %12
br label %71
71: ; preds = %69, %67
%72 = phi double [ %68, %67 ], [ %70, %69 ]
%73 = load double, double* %10
%74 = load double, double* %11
%75 = fcmp ogt double %73, %74
br i1 %75, label %76, label %78
76: ; preds = %71
%77 = load double, double* %11
br label %80
78: ; preds = %71
%79 = load double, double* %10
br label %80
80: ; preds = %78, %76
%81 = phi double [ %77, %76 ], [ %79, %78 ]
%82 = fdiv double %72, %81
store double %82, double* %5
br label %83
83: ; preds = %80, %52, %38, %21
%84 = load double, double* %5
ret double %84
}

LLVM IR (-O2):
@.str = [4 x i8] c"l12\00"
@.str.1 = [4 x i8] c"l21\00"
define double @my_math_pctIntersection(double %0, double %1, double %2, double %3) {
%5 = fcmp ugt double %1, %2
%6 = fcmp ugt double %3, %0
%7 = and i1 %5, %6
br i1 %7, label %8, label %32
8: ; preds = %4
%9 = fcmp ugt double %2, %0
%10 = fcmp ugt double %1, %3
%11 = or i1 %9, %10
br i1 %11, label %12, label %32
12: ; preds = %8
%13 = fcmp ugt double %0, %2
%14 = fcmp ugt double %3, %1
%15 = or i1 %13, %14
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = fsub double %1, %0
%18 = fsub double %3, %2
%19 = fcmp ole double %17, 0.000000e+00
%20 = fcmp ole double %18, 0.000000e+00
%21 = or i1 %19, %20
br i1 %21, label %32, label %22
22: ; preds = %16
%23 = fsub double %3, %0
%24 = fsub double %1, %2
%25 = tail call i32 @my_assert_greaterDouble(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %23, i32 0)
%26 = tail call i32 @my_assert_greaterDouble(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %24, i32 0)
%27 = fcmp ogt double %23, %24
%28 = select i1 %27, double %24, double %23
%29 = fcmp ogt double %17, %18
%30 = select i1 %29, double %18, double %17
%31 = fdiv double %28, %30
br label %32
32: ; preds = %22, %16, %8, %12, %4
%33 = phi double [ 0.000000e+00, %4 ], [ 1.000000e+00, %12 ], [ 1.000000e+00, %8 ], [ %31, %22 ], [ 1.000000e+00, %16 ]
ret double %33
}