; 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

declare { double, double } @Vec_subtract(double, double, double, double) #1

declare { double, double } @Vec_add(double, double, double, double) #1

declare { double, double } @Vec_multiply(double, double, double noundef) #1

; 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
define dso_local { double, double } @getIntersectionPoint(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7) #2 {
  %9 = alloca %struct.Vec, align 8
  %10 = alloca %struct.Vec, align 8
  %11 = alloca %struct.Vec, align 8
  %12 = alloca %struct.Vec, align 8
  %13 = alloca %struct.Vec, align 8
  %14 = alloca double, align 8
  %15 = alloca %struct.Vec, align 8
  %16 = alloca %struct.Vec, align 8
  %17 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 0
  store double %0, ptr %17, align 8
  %18 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 1
  store double %1, ptr %18, align 8
  %19 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  store double %2, ptr %19, align 8
  %20 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  store double %3, ptr %20, align 8
  %21 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 0
  store double %4, ptr %21, align 8
  %22 = getelementptr inbounds { double, double }, ptr %12, i32 0, i32 1
  store double %5, ptr %22, align 8
  %23 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 0
  store double %6, ptr %23, align 8
  %24 = getelementptr inbounds { double, double }, ptr %13, i32 0, i32 1
  store double %7, ptr %24, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %25 = getelementptr inbounds %struct.Vec, ptr %13, i32 0, i32 0
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Vec, ptr %12, i32 0, i32 0
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = fsub double %26, %28
  %30 = getelementptr inbounds %struct.Vec, ptr %10, i32 0, i32 1
  %31 = load double, ptr %30, align 8, !tbaa !10
  %32 = getelementptr inbounds %struct.Vec, ptr %12, i32 0, i32 1
  %33 = load double, ptr %32, align 8, !tbaa !10
  %34 = fsub double %31, %33
  %35 = getelementptr inbounds %struct.Vec, ptr %13, i32 0, i32 1
  %36 = load double, ptr %35, align 8, !tbaa !10
  %37 = getelementptr inbounds %struct.Vec, ptr %12, i32 0, i32 1
  %38 = load double, ptr %37, align 8, !tbaa !10
  %39 = fsub double %36, %38
  %40 = getelementptr inbounds %struct.Vec, ptr %10, i32 0, i32 0
  %41 = load double, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Vec, ptr %12, i32 0, i32 0
  %43 = load double, ptr %42, align 8, !tbaa !5
  %44 = fsub double %41, %43
  %45 = fmul double %39, %44
  %46 = fneg double %45
  %47 = call double @llvm.fmuladd.f64(double %29, double %34, double %46)
  %48 = getelementptr inbounds %struct.Vec, ptr %13, i32 0, i32 1
  %49 = load double, ptr %48, align 8, !tbaa !10
  %50 = getelementptr inbounds %struct.Vec, ptr %12, i32 0, i32 1
  %51 = load double, ptr %50, align 8, !tbaa !10
  %52 = fsub double %49, %51
  %53 = getelementptr inbounds %struct.Vec, ptr %11, i32 0, i32 0
  %54 = load double, ptr %53, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Vec, ptr %10, i32 0, i32 0
  %56 = load double, ptr %55, align 8, !tbaa !5
  %57 = fsub double %54, %56
  %58 = getelementptr inbounds %struct.Vec, ptr %13, i32 0, i32 0
  %59 = load double, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Vec, ptr %12, i32 0, i32 0
  %61 = load double, ptr %60, align 8, !tbaa !5
  %62 = fsub double %59, %61
  %63 = getelementptr inbounds %struct.Vec, ptr %11, i32 0, i32 1
  %64 = load double, ptr %63, align 8, !tbaa !10
  %65 = getelementptr inbounds %struct.Vec, ptr %10, i32 0, i32 1
  %66 = load double, ptr %65, align 8, !tbaa !10
  %67 = fsub double %64, %66
  %68 = fmul double %62, %67
  %69 = fneg double %68
  %70 = call double @llvm.fmuladd.f64(double %52, double %57, double %69)
  %71 = fdiv double %47, %70
  store double %71, ptr %14, align 8, !tbaa !11
  %72 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 0
  %73 = load double, ptr %72, align 8
  %74 = getelementptr inbounds { double, double }, ptr %11, i32 0, i32 1
  %75 = load double, ptr %74, align 8
  %76 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 0
  %77 = load double, ptr %76, align 8
  %78 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 1
  %79 = load double, ptr %78, align 8
  %80 = call { double, double } @Vec_subtract(double %73, double %75, double %77, double %79)
  %81 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 0
  %82 = extractvalue { double, double } %80, 0
  store double %82, ptr %81, align 8
  %83 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 1
  %84 = extractvalue { double, double } %80, 1
  store double %84, ptr %83, align 8
  %85 = load double, ptr %14, align 8, !tbaa !11
  %86 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 0
  %87 = load double, ptr %86, align 8
  %88 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 1
  %89 = load double, ptr %88, align 8
  %90 = call { double, double } @Vec_multiply(double %87, double %89, double noundef %85)
  %91 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 0
  %92 = extractvalue { double, double } %90, 0
  store double %92, ptr %91, align 8
  %93 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 1
  %94 = extractvalue { double, double } %90, 1
  store double %94, ptr %93, align 8
  %95 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 0
  %96 = load double, ptr %95, align 8
  %97 = getelementptr inbounds { double, double }, ptr %10, i32 0, i32 1
  %98 = load double, ptr %97, align 8
  %99 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 0
  %100 = load double, ptr %99, align 8
  %101 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 1
  %102 = load double, ptr %101, align 8
  %103 = call { double, double } @Vec_add(double %96, double %98, double %100, double %102)
  %104 = getelementptr inbounds { double, double }, ptr %9, i32 0, i32 0
  %105 = extractvalue { double, double } %103, 0
  store double %105, ptr %104, align 8
  %106 = getelementptr inbounds { double, double }, ptr %9, i32 0, i32 1
  %107 = extractvalue { double, double } %103, 1
  store double %107, ptr %106, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %108 = load { double, double }, ptr %9, align 8
  ret { double, double } %108
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !7, i64 0}
!6 = !{!"Vec", !7, i64 0, !7, i64 8}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!7, !7, i64 0}


; 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"

declare { double, double } @Vec_subtract(double, double, double, double) local_unnamed_addr #0

declare { double, double } @Vec_add(double, double, double, double) local_unnamed_addr #0

declare { double, double } @Vec_multiply(double, double, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local { double, double } @getIntersectionPoint(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7) local_unnamed_addr #1 {
  %9 = insertelement <2 x double> poison, double %6, i64 0
  %10 = insertelement <2 x double> %9, double %2, i64 1
  %11 = insertelement <2 x double> poison, double %4, i64 0
  %12 = insertelement <2 x double> %11, double %0, i64 1
  %13 = fsub <2 x double> %10, %12
  %14 = insertelement <2 x double> poison, double %1, i64 0
  %15 = insertelement <2 x double> %14, double %7, i64 1
  %16 = insertelement <2 x double> poison, double %5, i64 0
  %17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> zeroinitializer
  %18 = fsub <2 x double> %15, %17
  %19 = insertelement <2 x double> poison, double %0, i64 0
  %20 = insertelement <2 x double> %19, double %3, i64 1
  %21 = insertelement <2 x double> %11, double %1, i64 1
  %22 = fsub <2 x double> %20, %21
  %23 = shufflevector <2 x double> %18, <2 x double> %13, <2 x i32> <i32 1, i32 2>
  %24 = fneg <2 x double> %23
  %25 = fmul <2 x double> %22, %24
  %26 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %18, <2 x double> %13, <2 x double> %25)
  %27 = extractelement <2 x double> %26, i64 0
  %28 = extractelement <2 x double> %26, i64 1
  %29 = fdiv double %27, %28
  %30 = tail call { double, double } @Vec_subtract(double %2, double %3, double %0, double %1) #3
  %31 = extractvalue { double, double } %30, 0
  %32 = extractvalue { double, double } %30, 1
  %33 = tail call { double, double } @Vec_multiply(double %31, double %32, double noundef %29) #3
  %34 = extractvalue { double, double } %33, 0
  %35 = extractvalue { double, double } %33, 1
  %36 = tail call { double, double } @Vec_add(double %0, double %1, double %34, double %35) #3
  ret { double, double } %36
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

attributes #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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,TailCallElimPass