; LLVM IR from atlantis13579/Riemann :: Src/Geometry/Polygon2.ll (ZN7Riemann13PolygonArea2DEPKN5Maths8TVector2IfEEi)

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

%"class.Maths::TVector2" = type { float, float }

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #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: mustprogress nounwind uwtable
define dso_local noundef float @_ZN7Riemann13PolygonArea2DEPKN5Maths8TVector2IfEEi(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca float, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 3
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store float 0.000000e+00, ptr %3, align 4
  br label %59

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store float 0.000000e+00, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %52, %12
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %55

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = srem i32 %20, %21
  store i32 %22, ptr %8, align 4, !tbaa !9
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %"class.Maths::TVector2", ptr %23, i64 %25
  %27 = getelementptr inbounds %"class.Maths::TVector2", ptr %26, i32 0, i32 0
  %28 = load float, ptr %27, align 4, !tbaa !13
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds %"class.Maths::TVector2", ptr %29, i64 %31
  %33 = getelementptr inbounds %"class.Maths::TVector2", ptr %32, i32 0, i32 1
  %34 = load float, ptr %33, align 4, !tbaa !15
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds %"class.Maths::TVector2", ptr %35, i64 %37
  %39 = getelementptr inbounds %"class.Maths::TVector2", ptr %38, i32 0, i32 1
  %40 = load float, ptr %39, align 4, !tbaa !15
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load i32, ptr %8, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %"class.Maths::TVector2", ptr %41, i64 %43
  %45 = getelementptr inbounds %"class.Maths::TVector2", ptr %44, i32 0, i32 0
  %46 = load float, ptr %45, align 4, !tbaa !13
  %47 = fmul float %40, %46
  %48 = fneg float %47
  %49 = call float @llvm.fmuladd.f32(float %28, float %34, float %48)
  %50 = load float, ptr %6, align 4, !tbaa !11
  %51 = fadd float %50, %49
  store float %51, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %52

52:                                               ; preds = %18
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !9
  br label %13, !llvm.loop !16

55:                                               ; preds = %17
  %56 = load float, ptr %6, align 4, !tbaa !11
  %57 = call float @llvm.fabs.f32(float %56)
  %58 = fmul float 5.000000e-01, %57
  store float %58, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %59

59:                                               ; preds = %55, %11
  %60 = load float, ptr %3, align 4
  ret float %60
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTSN5Maths8TVector2IfEE", !12, i64 0, !12, i64 4}
!15 = !{!14, !12, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%"class.Maths::TVector2" = type { float, float }

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #0

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef float @_ZN7Riemann13PolygonArea2DEPKN5Maths8TVector2IfEEi(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp slt i32 %1, 3
  br i1 %3, label %51, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %4 = zext nneg i32 %1 to i64
  %xtraiter = and i64 %4, 1
  %unroll_iter = and i64 %4, 2147483646
  br label %.preheader

.unr-lcssa:                                       ; preds = %.preheader
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %20, label %.preheader.epil

.preheader.epil:                                  ; preds = %.unr-lcssa
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.next.1, 1
  %5 = icmp eq i64 %indvars.iv.next.epil, %4
  %6 = and i64 %indvars.iv.next.epil, 4294967295
  %7 = getelementptr inbounds %"class.Maths::TVector2", ptr %0, i64 %indvars.iv.next.1
  %8 = load float, ptr %7, align 4, !tbaa !5
  %9 = select i1 %5, i64 0, i64 %6
  %10 = getelementptr inbounds %"class.Maths::TVector2", ptr %0, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 4
  %12 = load float, ptr %11, align 4, !tbaa !10
  %13 = getelementptr inbounds i8, ptr %7, i64 4
  %14 = load float, ptr %13, align 4, !tbaa !10
  %15 = load float, ptr %10, align 4, !tbaa !5
  %16 = fneg float %14
  %17 = fmul float %15, %16
  %18 = tail call float @llvm.fmuladd.f32(float %8, float %12, float %17)
  %19 = fadd float %50, %18
  br label %20

20:                                               ; preds = %.unr-lcssa, %.preheader.epil
  %.lcssa = phi float [ %50, %.unr-lcssa ], [ %19, %.preheader.epil ]
  %21 = tail call float @llvm.fabs.f32(float %.lcssa)
  %22 = fmul float %21, 5.000000e-01
  br label %51

.preheader:                                       ; preds = %.preheader, %.preheader.preheader
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next.1, %.preheader ]
  %.01719 = phi float [ 0.000000e+00, %.preheader.preheader ], [ %50, %.preheader ]
  %niter = phi i64 [ 0, %.preheader.preheader ], [ %niter.next.1, %.preheader ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %23 = icmp eq i64 %indvars.iv.next, %4
  %24 = getelementptr inbounds %"class.Maths::TVector2", ptr %0, i64 %indvars.iv
  %25 = load float, ptr %24, align 4, !tbaa !5
  %26 = select i1 %23, i64 0, i64 %indvars.iv.next
  %27 = getelementptr inbounds %"class.Maths::TVector2", ptr %0, i64 %26
  %28 = getelementptr inbounds i8, ptr %27, i64 4
  %29 = load float, ptr %28, align 4, !tbaa !10
  %30 = getelementptr inbounds i8, ptr %24, i64 4
  %31 = load float, ptr %30, align 4, !tbaa !10
  %32 = load float, ptr %27, align 4, !tbaa !5
  %33 = fneg float %31
  %34 = fmul float %32, %33
  %35 = tail call float @llvm.fmuladd.f32(float %25, float %29, float %34)
  %36 = fadd float %.01719, %35
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %37 = icmp eq i64 %indvars.iv.next.1, %4
  %38 = getelementptr inbounds %"class.Maths::TVector2", ptr %0, i64 %indvars.iv.next
  %39 = load float, ptr %38, align 4, !tbaa !5
  %40 = select i1 %37, i64 0, i64 %indvars.iv.next.1
  %41 = getelementptr inbounds %"class.Maths::TVector2", ptr %0, i64 %40
  %42 = getelementptr inbounds i8, ptr %41, i64 4
  %43 = load float, ptr %42, align 4, !tbaa !10
  %44 = getelementptr inbounds i8, ptr %38, i64 4
  %45 = load float, ptr %44, align 4, !tbaa !10
  %46 = load float, ptr %41, align 4, !tbaa !5
  %47 = fneg float %45
  %48 = fmul float %46, %47
  %49 = tail call float @llvm.fmuladd.f32(float %39, float %43, float %48)
  %50 = fadd float %36, %49
  %niter.next.1 = add nuw nsw i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.unr-lcssa, label %.preheader, !llvm.loop !11

51:                                               ; preds = %2, %20
  %.0 = phi float [ %22, %20 ], [ 0.000000e+00, %2 ]
  ret float %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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)"}
!5 = !{!6, !7, i64 0}
!6 = !{!"_ZTSN5Maths8TVector2IfEE", !7, i64 0, !7, i64 4}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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