; LLVM IR from simonaertssen/MIT-6.172-Performance-Engineering-of-Software-Systems :: Project 2 - Collision Detection/screensaver (intersection_detection)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.Vec = type { double, double }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @pointInParallelogram(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7, ptr noundef byval(%struct.Vec) align 8 %8) #1 {
  %10 = alloca i1, align 1
  %11 = alloca %struct.Vec, align 8
  %12 = alloca %struct.Vec, align 8
  %13 = alloca %struct.Vec, align 8
  %14 = alloca %struct.Vec, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca i32, align 4
  %20 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  store double %0, ptr %20, align 8
  %21 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  store double %1, ptr %21, align 8
  %22 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  store double %2, ptr %22, align 8
  %23 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  store double %3, ptr %23, align 8
  %24 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 0
  store double %4, ptr %24, align 8
  %25 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 1
  store double %5, ptr %25, align 8
  %26 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  store double %6, ptr %26, align 8
  %27 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  store double %7, ptr %27, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %28 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  %29 = load double, ptr %28, align 8
  %30 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  %31 = load double, ptr %30, align 8
  %32 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 0
  %33 = load double, ptr %32, align 8
  %34 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 1
  %35 = load double, ptr %34, align 8
  %36 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %37 = load double, ptr %36, align 8
  %38 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %39 = load double, ptr %38, align 8
  %40 = call double @direction(double %29, double %31, double %33, double %35, double %37, double %39)
  store double %40, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #2
  %41 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %42 = load double, ptr %41, align 8
  %43 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %44 = load double, ptr %43, align 8
  %45 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 0
  %46 = load double, ptr %45, align 8
  %47 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 1
  %48 = load double, ptr %47, align 8
  %49 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %50 = load double, ptr %49, align 8
  %51 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %52 = load double, ptr %51, align 8
  %53 = call double @direction(double %42, double %44, double %46, double %48, double %50, double %52)
  store double %53, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #2
  %54 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  %55 = load double, ptr %54, align 8
  %56 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  %57 = load double, ptr %56, align 8
  %58 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %59 = load double, ptr %58, align 8
  %60 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %61 = load double, ptr %60, align 8
  %62 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %63 = load double, ptr %62, align 8
  %64 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %65 = load double, ptr %64, align 8
  %66 = call double @direction(double %55, double %57, double %59, double %61, double %63, double %65)
  store double %66, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #2
  %67 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 0
  %68 = load double, ptr %67, align 8
  %69 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 1
  %70 = load double, ptr %69, align 8
  %71 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 0
  %72 = load double, ptr %71, align 8
  %73 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 1
  %74 = load double, ptr %73, align 8
  %75 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %76 = load double, ptr %75, align 8
  %77 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %78 = load double, ptr %77, align 8
  %79 = call double @direction(double %68, double %70, double %72, double %74, double %76, double %78)
  store double %79, ptr %18, align 8, !tbaa !5
  %80 = load double, ptr %15, align 8, !tbaa !5
  %81 = fcmp ogt double %80, 0.000000e+00
  br i1 %81, label %82, label %85

82:                                               ; preds = %9
  %83 = load double, ptr %16, align 8, !tbaa !5
  %84 = fcmp olt double %83, 0.000000e+00
  br i1 %84, label %91, label %85

85:                                               ; preds = %82, %9
  %86 = load double, ptr %15, align 8, !tbaa !5
  %87 = fcmp olt double %86, 0.000000e+00
  br i1 %87, label %88, label %104

88:                                               ; preds = %85
  %89 = load double, ptr %16, align 8, !tbaa !5
  %90 = fcmp ogt double %89, 0.000000e+00
  br i1 %90, label %91, label %104

91:                                               ; preds = %88, %82
  %92 = load double, ptr %17, align 8, !tbaa !5
  %93 = fcmp ogt double %92, 0.000000e+00
  br i1 %93, label %94, label %97

94:                                               ; preds = %91
  %95 = load double, ptr %18, align 8, !tbaa !5
  %96 = fcmp olt double %95, 0.000000e+00
  br i1 %96, label %103, label %97

97:                                               ; preds = %94, %91
  %98 = load double, ptr %17, align 8, !tbaa !5
  %99 = fcmp olt double %98, 0.000000e+00
  br i1 %99, label %100, label %104

100:                                              ; preds = %97
  %101 = load double, ptr %18, align 8, !tbaa !5
  %102 = fcmp ogt double %101, 0.000000e+00
  br i1 %102, label %103, label %104

103:                                              ; preds = %100, %94
  store i1 true, ptr %10, align 1
  store i32 1, ptr %19, align 4
  br label %105

104:                                              ; preds = %100, %97, %88, %85
  store i1 false, ptr %10, align 1
  store i32 1, ptr %19, align 4
  br label %105

105:                                              ; preds = %104, %103
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  %106 = load i1, ptr %10, align 1
  ret i1 %106
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local double @direction(double, double, double, double, double, double) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.Vec = type { double, double }

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @pointInParallelogram(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7, ptr nocapture noundef readonly byval(%struct.Vec) align 8 %8) local_unnamed_addr #0 {
  %10 = tail call double @direction(double %2, double %3, double %4, double %5, double %0, double %1)
  %11 = load double, ptr %8, align 8
  %12 = getelementptr inbounds i8, ptr %8, i64 8
  %13 = load double, ptr %12, align 8
  %14 = tail call double @direction(double %6, double %7, double %11, double %13, double %0, double %1)
  %15 = tail call double @direction(double %2, double %3, double %6, double %7, double %0, double %1)
  %16 = tail call double @direction(double %4, double %5, double %11, double %13, double %0, double %1)
  %17 = fcmp ogt double %10, 0.000000e+00
  %18 = fcmp olt double %14, 0.000000e+00
  %or.cond = select i1 %17, i1 %18, i1 false
  br i1 %or.cond, label %22, label %19

19:                                               ; preds = %9
  %20 = fcmp olt double %10, 0.000000e+00
  %21 = fcmp ogt double %14, 0.000000e+00
  %or.cond3 = select i1 %20, i1 %21, i1 false
  br i1 %or.cond3, label %22, label %28

22:                                               ; preds = %19, %9
  %23 = fcmp ogt double %15, 0.000000e+00
  %24 = fcmp olt double %16, 0.000000e+00
  %or.cond5 = select i1 %23, i1 %24, i1 false
  br i1 %or.cond5, label %29, label %25

25:                                               ; preds = %22
  %26 = fcmp olt double %15, 0.000000e+00
  %27 = fcmp ogt double %16, 0.000000e+00
  %or.cond7 = select i1 %26, i1 %27, i1 false
  br i1 %or.cond7, label %29, label %28

28:                                               ; preds = %25, %19
  br label %29

29:                                               ; preds = %22, %25, %28
  %.0 = phi i1 [ false, %28 ], [ true, %25 ], [ true, %22 ]
  ret i1 %.0
}

; Function Attrs: nounwind uwtable
declare dso_local double @direction(double, double, double, double, double, double) local_unnamed_addr #0

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass