; LLVM IR from csviragh/robotsim :: src/utilities (math_utils)

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @CentroidOfPolygon2D(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds double, ptr %14, i64 0
  store double 0.000000e+00, ptr %15, align 8, !tbaa !11
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds double, ptr %16, i64 1
  store double 0.000000e+00, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store double 0.000000e+00, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store double 0.000000e+00, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  store double 0.000000e+00, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store double 0.000000e+00, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %74, %3
  %19 = load i32, ptr %13, align 4, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = sub nsw i32 %20, 1
  %22 = mul nsw i32 %21, 2
  %23 = icmp slt i32 %19, %22
  br i1 %23, label %24, label %77

24:                                               ; preds = %18
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %13, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds double, ptr %25, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !11
  store double %29, ptr %8, align 8, !tbaa !11
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i32, ptr %13, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %30, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  store double %35, ptr %9, align 8, !tbaa !11
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %13, align 4, !tbaa !9
  %38 = add nsw i32 %37, 2
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds double, ptr %36, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !11
  store double %41, ptr %10, align 8, !tbaa !11
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %13, align 4, !tbaa !9
  %44 = add nsw i32 %43, 3
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %42, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !11
  store double %47, ptr %11, align 8, !tbaa !11
  %48 = load double, ptr %8, align 8, !tbaa !11
  %49 = load double, ptr %11, align 8, !tbaa !11
  %50 = load double, ptr %10, align 8, !tbaa !11
  %51 = load double, ptr %9, align 8, !tbaa !11
  %52 = fmul double %50, %51
  %53 = fneg double %52
  %54 = call double @llvm.fmuladd.f64(double %48, double %49, double %53)
  store double %54, ptr %12, align 8, !tbaa !11
  %55 = load double, ptr %12, align 8, !tbaa !11
  %56 = load double, ptr %7, align 8, !tbaa !11
  %57 = fadd double %56, %55
  store double %57, ptr %7, align 8, !tbaa !11
  %58 = load double, ptr %8, align 8, !tbaa !11
  %59 = load double, ptr %10, align 8, !tbaa !11
  %60 = fadd double %58, %59
  %61 = load double, ptr %12, align 8, !tbaa !11
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds double, ptr %62, i64 0
  %64 = load double, ptr %63, align 8, !tbaa !11
  %65 = call double @llvm.fmuladd.f64(double %60, double %61, double %64)
  store double %65, ptr %63, align 8, !tbaa !11
  %66 = load double, ptr %9, align 8, !tbaa !11
  %67 = load double, ptr %11, align 8, !tbaa !11
  %68 = fadd double %66, %67
  %69 = load double, ptr %12, align 8, !tbaa !11
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds double, ptr %70, i64 1
  %72 = load double, ptr %71, align 8, !tbaa !11
  %73 = call double @llvm.fmuladd.f64(double %68, double %69, double %72)
  store double %73, ptr %71, align 8, !tbaa !11
  br label %74

74:                                               ; preds = %24
  %75 = load i32, ptr %13, align 4, !tbaa !9
  %76 = add nsw i32 %75, 2
  store i32 %76, ptr %13, align 4, !tbaa !9
  br label %18, !llvm.loop !13

77:                                               ; preds = %18
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds double, ptr %78, i64 %80
  %82 = load double, ptr %81, align 8, !tbaa !11
  store double %82, ptr %8, align 8, !tbaa !11
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load i32, ptr %13, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds double, ptr %83, i64 %86
  %88 = load double, ptr %87, align 8, !tbaa !11
  store double %88, ptr %9, align 8, !tbaa !11
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds double, ptr %89, i64 0
  %91 = load double, ptr %90, align 8, !tbaa !11
  store double %91, ptr %10, align 8, !tbaa !11
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds double, ptr %92, i64 1
  %94 = load double, ptr %93, align 8, !tbaa !11
  store double %94, ptr %11, align 8, !tbaa !11
  %95 = load double, ptr %8, align 8, !tbaa !11
  %96 = load double, ptr %11, align 8, !tbaa !11
  %97 = load double, ptr %10, align 8, !tbaa !11
  %98 = load double, ptr %9, align 8, !tbaa !11
  %99 = fmul double %97, %98
  %100 = fneg double %99
  %101 = call double @llvm.fmuladd.f64(double %95, double %96, double %100)
  store double %101, ptr %12, align 8, !tbaa !11
  %102 = load double, ptr %12, align 8, !tbaa !11
  %103 = load double, ptr %7, align 8, !tbaa !11
  %104 = fadd double %103, %102
  store double %104, ptr %7, align 8, !tbaa !11
  %105 = load double, ptr %8, align 8, !tbaa !11
  %106 = load double, ptr %10, align 8, !tbaa !11
  %107 = fadd double %105, %106
  %108 = load double, ptr %12, align 8, !tbaa !11
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = getelementptr inbounds double, ptr %109, i64 0
  %111 = load double, ptr %110, align 8, !tbaa !11
  %112 = call double @llvm.fmuladd.f64(double %107, double %108, double %111)
  store double %112, ptr %110, align 8, !tbaa !11
  %113 = load double, ptr %9, align 8, !tbaa !11
  %114 = load double, ptr %11, align 8, !tbaa !11
  %115 = fadd double %113, %114
  %116 = load double, ptr %12, align 8, !tbaa !11
  %117 = load ptr, ptr %4, align 8, !tbaa !5
  %118 = getelementptr inbounds double, ptr %117, i64 1
  %119 = load double, ptr %118, align 8, !tbaa !11
  %120 = call double @llvm.fmuladd.f64(double %115, double %116, double %119)
  store double %120, ptr %118, align 8, !tbaa !11
  %121 = load double, ptr %7, align 8, !tbaa !11
  %122 = fmul double %121, 5.000000e-01
  store double %122, ptr %7, align 8, !tbaa !11
  %123 = load double, ptr %7, align 8, !tbaa !11
  %124 = fmul double 6.000000e+00, %123
  %125 = load ptr, ptr %4, align 8, !tbaa !5
  %126 = getelementptr inbounds double, ptr %125, i64 0
  %127 = load double, ptr %126, align 8, !tbaa !11
  %128 = fdiv double %127, %124
  store double %128, ptr %126, align 8, !tbaa !11
  %129 = load double, ptr %7, align 8, !tbaa !11
  %130 = fmul double 6.000000e+00, %129
  %131 = load ptr, ptr %4, align 8, !tbaa !5
  %132 = getelementptr inbounds double, ptr %131, i64 1
  %133 = load double, ptr %132, align 8, !tbaa !11
  %134 = fdiv double %133, %130
  store double %134, ptr %132, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @CentroidOfPolygon2D(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = shl i32 %2, 1
  %5 = add i32 %4, -2
  %6 = icmp sgt i32 %5, 0
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %7 = zext nneg i32 %5 to i64
  br label %8

8:                                                ; preds = %.lr.ph, %8
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %8 ]
  %.05153 = phi double [ 0.000000e+00, %.lr.ph ], [ %21, %8 ]
  %9 = phi <2 x double> [ zeroinitializer, %.lr.ph ], [ %25, %8 ]
  %10 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %11 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  %12 = load <2 x double>, ptr %10, align 8, !tbaa !5
  %13 = load <2 x double>, ptr %11, align 8, !tbaa !5
  %14 = extractelement <2 x double> %13, i64 0
  %15 = fneg double %14
  %16 = extractelement <2 x double> %12, i64 1
  %17 = fmul double %16, %15
  %18 = extractelement <2 x double> %12, i64 0
  %19 = extractelement <2 x double> %13, i64 1
  %20 = tail call double @llvm.fmuladd.f64(double %18, double %19, double %17)
  %21 = fadd double %.05153, %20
  %22 = fadd <2 x double> %12, %13
  %23 = insertelement <2 x double> poison, double %20, i64 0
  %24 = shufflevector <2 x double> %23, <2 x double> poison, <2 x i32> zeroinitializer
  %25 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %22, <2 x double> %24, <2 x double> %9)
  store <2 x double> %25, ptr %0, align 8, !tbaa !5
  %26 = icmp ult i64 %indvars.iv.next, %7
  br i1 %26, label %8, label %._crit_edge.loopexit, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %8
  %27 = trunc nuw nsw i64 %indvars.iv.next to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  %.051.lcssa = phi double [ 0.000000e+00, %3 ], [ %21, %._crit_edge.loopexit ]
  %.0.lcssa = phi i32 [ 0, %3 ], [ %27, %._crit_edge.loopexit ]
  %28 = phi <2 x double> [ zeroinitializer, %3 ], [ %25, %._crit_edge.loopexit ]
  %29 = zext nneg i32 %.0.lcssa to i64
  %30 = getelementptr inbounds double, ptr %1, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = or disjoint i32 %.0.lcssa, 1
  %33 = zext nneg i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %1, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = load <2 x double>, ptr %1, align 8, !tbaa !5
  %37 = extractelement <2 x double> %36, i64 0
  %38 = fneg double %37
  %39 = fmul double %35, %38
  %40 = extractelement <2 x double> %36, i64 1
  %41 = tail call double @llvm.fmuladd.f64(double %31, double %40, double %39)
  %42 = fadd double %.051.lcssa, %41
  %43 = insertelement <2 x double> poison, double %31, i64 0
  %44 = insertelement <2 x double> %43, double %35, i64 1
  %45 = fadd <2 x double> %44, %36
  %46 = insertelement <2 x double> poison, double %41, i64 0
  %47 = shufflevector <2 x double> %46, <2 x double> poison, <2 x i32> zeroinitializer
  %48 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %45, <2 x double> %47, <2 x double> %28)
  %49 = fmul double %42, 5.000000e-01
  %50 = fmul double %49, 6.000000e+00
  %51 = insertelement <2 x double> poison, double %50, i64 0
  %52 = shufflevector <2 x double> %51, <2 x double> poison, <2 x i32> zeroinitializer
  %53 = fdiv <2 x double> %48, %52
  store <2 x double> %53, ptr %0, align 8, !tbaa !5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; 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>) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass