; LLVM IR from Mithreindeir/VelocityRaptor :: VelocityRaptor/src (vrRigidBody)

; 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.vrVec2 = type { float, float }
%struct.vrPolygonShape = type { ptr, i32, ptr, i32, %struct.vrVec2 }

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local float @vrAreaForPoly(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.vrVec2, align 4
  %7 = alloca %struct.vrVec2, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store float 0.000000e+00, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store float 0.000000e+00, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %8

8:                                                ; preds = %54, %1
  %9 = load i32, ptr %5, align 4, !tbaa !11
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.vrPolygonShape, ptr %10, i32 0, i32 1
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = icmp slt i32 %9, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %57

15:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.vrPolygonShape, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = load i32, ptr %5, align 4, !tbaa !11
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds %struct.vrVec2, ptr %18, i64 %20
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %21, i64 8, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %22 = load i32, ptr %5, align 4, !tbaa !11
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.vrPolygonShape, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = sub nsw i32 %25, 1
  %27 = icmp slt i32 %22, %26
  br i1 %27, label %28, label %36

28:                                               ; preds = %15
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.vrPolygonShape, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load i32, ptr %5, align 4, !tbaa !11
  %33 = add nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds %struct.vrVec2, ptr %31, i64 %34
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %35, i64 8, i1 false), !tbaa.struct !17
  br label %41

36:                                               ; preds = %15
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.vrPolygonShape, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  %40 = getelementptr inbounds %struct.vrVec2, ptr %39, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %40, i64 8, i1 false), !tbaa.struct !17
  br label %41

41:                                               ; preds = %36, %28
  %42 = getelementptr inbounds %struct.vrVec2, ptr %6, i32 0, i32 0
  %43 = load float, ptr %42, align 4, !tbaa !18
  %44 = getelementptr inbounds %struct.vrVec2, ptr %7, i32 0, i32 1
  %45 = load float, ptr %44, align 4, !tbaa !19
  %46 = load float, ptr %3, align 4, !tbaa !9
  %47 = call float @llvm.fmuladd.f32(float %43, float %45, float %46)
  store float %47, ptr %3, align 4, !tbaa !9
  %48 = getelementptr inbounds %struct.vrVec2, ptr %6, i32 0, i32 1
  %49 = load float, ptr %48, align 4, !tbaa !19
  %50 = getelementptr inbounds %struct.vrVec2, ptr %7, i32 0, i32 0
  %51 = load float, ptr %50, align 4, !tbaa !18
  %52 = load float, ptr %4, align 4, !tbaa !9
  %53 = call float @llvm.fmuladd.f32(float %49, float %51, float %52)
  store float %53, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %54

54:                                               ; preds = %41
  %55 = load i32, ptr %5, align 4, !tbaa !11
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !11
  br label %8, !llvm.loop !20

57:                                               ; preds = %14
  %58 = load float, ptr %3, align 4, !tbaa !9
  %59 = load float, ptr %4, align 4, !tbaa !9
  %60 = fsub float %58, %59
  %61 = fpext float %60 to double
  %62 = fdiv double %61, 2.000000e+00
  %63 = fptosi double %62 to i32
  %64 = call i32 @llvm.abs.i32(i32 %63, i1 true)
  %65 = sitofp i32 %64 to float
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret float %65
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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, !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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"vrPolygonShape", !6, i64 0, !12, i64 8, !6, i64 16, !12, i64 24, !15, i64 28}
!15 = !{!"vrVec2", !10, i64 0, !10, i64 4}
!16 = !{!14, !6, i64 0}
!17 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}
!18 = !{!15, !10, i64 0}
!19 = !{!15, !10, i64 4}
!20 = distinct !{!20, !21}
!21 = !{!"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"

%struct.vrVec2 = type { float, float }

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local float @vrAreaForPoly(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !13
  %6 = add nsw i32 %3, -1
  %.sroa.5.0..sroa_idx2 = getelementptr inbounds i8, ptr %5, i64 4
  %7 = zext nneg i32 %6 to i64
  %wide.trip.count = zext nneg i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %8 = icmp eq i32 %3, 1
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %24

._crit_edge.loopexit.unr-lcssa:                   ; preds = %24, %.lr.ph
  %.lcssa.ph = phi <2 x float> [ poison, %.lr.ph ], [ %39, %24 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %24 ]
  %.unr = phi <2 x float> [ zeroinitializer, %.lr.ph ], [ %39, %24 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %9 = getelementptr inbounds %struct.vrVec2, ptr %5, i64 %indvars.iv.unr
  %10 = load <2 x float>, ptr %9, align 4, !tbaa !14
  %11 = icmp ult i64 %indvars.iv.unr, %7
  %12 = getelementptr inbounds i8, ptr %9, i64 8
  %.sroa.5.0..sroa_idx.epil = getelementptr inbounds i8, ptr %9, i64 12
  %.sroa.5.0.in.epil = select i1 %11, ptr %.sroa.5.0..sroa_idx.epil, ptr %.sroa.5.0..sroa_idx2
  %.sroa.0.0.in.epil = select i1 %11, ptr %12, ptr %5
  %.sroa.0.0.epil = load float, ptr %.sroa.0.0.in.epil, align 4, !tbaa !14
  %.sroa.5.0.epil = load float, ptr %.sroa.5.0.in.epil, align 4, !tbaa !14
  %13 = insertelement <2 x float> poison, float %.sroa.5.0.epil, i64 0
  %14 = insertelement <2 x float> %13, float %.sroa.0.0.epil, i64 1
  %15 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %10, <2 x float> %14, <2 x float> %.unr)
  br label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %._crit_edge.loopexit.unr-lcssa, %._crit_edge.loopexit.epilog-lcssa
  %.lcssa = phi <2 x float> [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %15, %._crit_edge.loopexit.epilog-lcssa ]
  %shift = shufflevector <2 x float> %.lcssa, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %16 = fsub <2 x float> %.lcssa, %shift
  %17 = extractelement <2 x float> %16, i64 0
  %18 = fpext float %17 to double
  %19 = fmul double %18, 5.000000e-01
  %20 = fptosi double %19 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %21 = phi i32 [ 0, %1 ], [ %20, %._crit_edge.loopexit ]
  %22 = tail call i32 @llvm.abs.i32(i32 %21, i1 true)
  %23 = uitofp nneg i32 %22 to float
  ret float %23

24:                                               ; preds = %24, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %24 ]
  %25 = phi <2 x float> [ zeroinitializer, %.lr.ph.new ], [ %39, %24 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %24 ]
  %26 = getelementptr inbounds %struct.vrVec2, ptr %5, i64 %indvars.iv
  %27 = load <2 x float>, ptr %26, align 4, !tbaa !14
  %28 = icmp ult i64 %indvars.iv, %7
  %29 = getelementptr inbounds i8, ptr %26, i64 8
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %26, i64 12
  %.sroa.5.0.in = select i1 %28, ptr %.sroa.5.0..sroa_idx, ptr %.sroa.5.0..sroa_idx2
  %.sroa.0.0.in = select i1 %28, ptr %29, ptr %5
  %.sroa.0.0 = load float, ptr %.sroa.0.0.in, align 4, !tbaa !14
  %.sroa.5.0 = load float, ptr %.sroa.5.0.in, align 4, !tbaa !14
  %30 = insertelement <2 x float> poison, float %.sroa.5.0, i64 0
  %31 = insertelement <2 x float> %30, float %.sroa.0.0, i64 1
  %32 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %27, <2 x float> %31, <2 x float> %25)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %33 = getelementptr inbounds %struct.vrVec2, ptr %5, i64 %indvars.iv.next
  %34 = load <2 x float>, ptr %33, align 4, !tbaa !14
  %35 = icmp ult i64 %indvars.iv.next, %7
  %36 = getelementptr inbounds i8, ptr %33, i64 8
  %.sroa.5.0..sroa_idx.1 = getelementptr inbounds i8, ptr %33, i64 12
  %.sroa.5.0.in.1 = select i1 %35, ptr %.sroa.5.0..sroa_idx.1, ptr %.sroa.5.0..sroa_idx2
  %.sroa.0.0.in.1 = select i1 %35, ptr %36, ptr %5
  %.sroa.0.0.1 = load float, ptr %.sroa.0.0.in.1, align 4, !tbaa !14
  %.sroa.5.0.1 = load float, ptr %.sroa.5.0.in.1, align 4, !tbaa !14
  %37 = insertelement <2 x float> poison, float %.sroa.5.0.1, i64 0
  %38 = insertelement <2 x float> %37, float %.sroa.0.0.1, i64 1
  %39 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %34, <2 x float> %38, <2 x float> %32)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %24, !llvm.loop !15
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #1

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

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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, !10, i64 8}
!6 = !{!"vrPolygonShape", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !11, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"vrVec2", !12, i64 0, !12, i64 4}
!12 = !{!"float", !8, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass