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

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @vrParticleSystemBoundaries(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %5

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

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

14:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.vrParticleSystem, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.vrArray, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds ptr, ptr %19, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.vrParticle, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.vrVec2, ptr %25, i32 0, i32 0
  %27 = load float, ptr %26, align 4, !tbaa !18
  %28 = fcmp ole float %27, 0x3FC99999A0000000
  br i1 %28, label %29, label %43

29:                                               ; preds = %14
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.vrParticle, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.vrVec2, ptr %31, i32 0, i32 0
  store float 0x3FC9999AA0000000, ptr %32, align 4, !tbaa !18
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.vrParticle, ptr %33, i32 0, i32 2
  %35 = getelementptr inbounds %struct.vrVec2, ptr %34, i32 0, i32 0
  %36 = load float, ptr %35, align 4, !tbaa !21
  %37 = fpext float %36 to double
  %38 = fmul double -2.000000e-01, %37
  %39 = fptrunc double %38 to float
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.vrParticle, ptr %40, i32 0, i32 2
  %42 = getelementptr inbounds %struct.vrVec2, ptr %41, i32 0, i32 0
  store float %39, ptr %42, align 4, !tbaa !21
  br label %64

43:                                               ; preds = %14
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.vrParticle, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds %struct.vrVec2, ptr %45, i32 0, i32 0
  %47 = load float, ptr %46, align 4, !tbaa !18
  %48 = fcmp oge float %47, 0x4017333340000000
  br i1 %48, label %49, label %63

49:                                               ; preds = %43
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.vrParticle, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds %struct.vrVec2, ptr %51, i32 0, i32 0
  store float 0x4017333340000000, ptr %52, align 4, !tbaa !18
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.vrParticle, ptr %53, i32 0, i32 2
  %55 = getelementptr inbounds %struct.vrVec2, ptr %54, i32 0, i32 0
  %56 = load float, ptr %55, align 4, !tbaa !21
  %57 = fpext float %56 to double
  %58 = fmul double -2.000000e-01, %57
  %59 = fptrunc double %58 to float
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.vrParticle, ptr %60, i32 0, i32 2
  %62 = getelementptr inbounds %struct.vrVec2, ptr %61, i32 0, i32 0
  store float %59, ptr %62, align 4, !tbaa !21
  br label %63

63:                                               ; preds = %49, %43
  br label %64

64:                                               ; preds = %63, %29
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.vrParticle, ptr %65, i32 0, i32 0
  %67 = getelementptr inbounds %struct.vrVec2, ptr %66, i32 0, i32 1
  %68 = load float, ptr %67, align 4, !tbaa !22
  %69 = fcmp ole float %68, 0x3FC99999A0000000
  br i1 %69, label %70, label %84

70:                                               ; preds = %64
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.vrParticle, ptr %71, i32 0, i32 0
  %73 = getelementptr inbounds %struct.vrVec2, ptr %72, i32 0, i32 1
  store float 0x3FC9999AA0000000, ptr %73, align 4, !tbaa !22
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.vrParticle, ptr %74, i32 0, i32 2
  %76 = getelementptr inbounds %struct.vrVec2, ptr %75, i32 0, i32 1
  %77 = load float, ptr %76, align 4, !tbaa !23
  %78 = fpext float %77 to double
  %79 = fmul double -2.000000e-01, %78
  %80 = fptrunc double %79 to float
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.vrParticle, ptr %81, i32 0, i32 2
  %83 = getelementptr inbounds %struct.vrVec2, ptr %82, i32 0, i32 1
  store float %80, ptr %83, align 4, !tbaa !23
  br label %105

84:                                               ; preds = %64
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.vrParticle, ptr %85, i32 0, i32 0
  %87 = getelementptr inbounds %struct.vrVec2, ptr %86, i32 0, i32 1
  %88 = load float, ptr %87, align 4, !tbaa !22
  %89 = fcmp oge float %88, 0x4017333340000000
  br i1 %89, label %90, label %104

90:                                               ; preds = %84
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.vrParticle, ptr %91, i32 0, i32 0
  %93 = getelementptr inbounds %struct.vrVec2, ptr %92, i32 0, i32 1
  store float 0x4017333340000000, ptr %93, align 4, !tbaa !22
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.vrParticle, ptr %94, i32 0, i32 2
  %96 = getelementptr inbounds %struct.vrVec2, ptr %95, i32 0, i32 1
  %97 = load float, ptr %96, align 4, !tbaa !23
  %98 = fpext float %97 to double
  %99 = fmul double -2.000000e-01, %98
  %100 = fptrunc double %99 to float
  %101 = load ptr, ptr %4, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.vrParticle, ptr %101, i32 0, i32 2
  %103 = getelementptr inbounds %struct.vrVec2, ptr %102, i32 0, i32 1
  store float %100, ptr %103, align 4, !tbaa !23
  br label %104

104:                                              ; preds = %90, %84
  br label %105

105:                                              ; preds = %104, %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %3, align 4, !tbaa !9
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %3, align 4, !tbaa !9
  br label %5, !llvm.loop !24

109:                                              ; preds = %13
  ret void
}

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 = !{!"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, !6, i64 0}
!12 = !{!"vrParticleSystem", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !14, i64 36, !6, i64 48}
!13 = !{!"float", !7, i64 0}
!14 = !{!"vrVec2", !13, i64 0, !13, i64 4}
!15 = !{!16, !10, i64 8}
!16 = !{!"vrArray", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!17 = !{!16, !6, i64 0}
!18 = !{!19, !13, i64 0}
!19 = !{!"vrParticle", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !13, i64 56, !13, i64 60, !13, i64 64, !20, i64 68}
!20 = !{!"vrColor", !13, i64 0, !13, i64 4, !13, i64 8}
!21 = !{!19, !13, i64 16}
!22 = !{!19, !13, i64 4}
!23 = !{!19, !13, i64 20}
!24 = distinct !{!24, !25}
!25 = !{!"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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @vrParticleSystemBoundaries(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !12
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %6 = load ptr, ptr %2, align 8, !tbaa !15
  %wide.trip.count = zext nneg i32 %4 to i64
  br label %7

._crit_edge:                                      ; preds = %30, %1
  ret void

7:                                                ; preds = %.lr.ph, %30
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %30 ]
  %8 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %10 = load float, ptr %9, align 4, !tbaa !17
  %11 = fcmp ugt float %10, 0x3FC99999A0000000
  br i1 %11, label %12, label %.sink.split

12:                                               ; preds = %7
  %13 = fcmp ult float %10, 0x4017333340000000
  br i1 %13, label %19, label %.sink.split

.sink.split:                                      ; preds = %12, %7
  %.sink = phi float [ 0x3FC9999AA0000000, %7 ], [ 0x4017333340000000, %12 ]
  store float %.sink, ptr %9, align 4, !tbaa !17
  %14 = getelementptr inbounds i8, ptr %9, i64 16
  %15 = load float, ptr %14, align 4, !tbaa !20
  %16 = fpext float %15 to double
  %17 = fmul double %16, -2.000000e-01
  %18 = fptrunc double %17 to float
  store float %18, ptr %14, align 4, !tbaa !20
  br label %19

19:                                               ; preds = %.sink.split, %12
  %20 = getelementptr inbounds i8, ptr %9, i64 4
  %21 = load float, ptr %20, align 4, !tbaa !21
  %22 = fcmp ugt float %21, 0x3FC99999A0000000
  br i1 %22, label %23, label %.sink.split27

23:                                               ; preds = %19
  %24 = fcmp ult float %21, 0x4017333340000000
  br i1 %24, label %30, label %.sink.split27

.sink.split27:                                    ; preds = %23, %19
  %.sink34 = phi float [ 0x3FC9999AA0000000, %19 ], [ 0x4017333340000000, %23 ]
  store float %.sink34, ptr %20, align 4, !tbaa !21
  %25 = getelementptr inbounds i8, ptr %9, i64 20
  %26 = load float, ptr %25, align 4, !tbaa !22
  %27 = fpext float %26 to double
  %28 = fmul double %27, -2.000000e-01
  %29 = fptrunc double %28 to float
  store float %29, ptr %25, align 4, !tbaa !22
  br label %30

30:                                               ; preds = %.sink.split27, %23
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %7, !llvm.loop !23
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, 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" }

!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 = !{!"vrParticleSystem", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !11, i64 36, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"vrVec2", !10, i64 0, !10, i64 4}
!12 = !{!13, !14, i64 8}
!13 = !{!"vrArray", !7, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!14 = !{!"int", !8, i64 0}
!15 = !{!13, !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !10, i64 0}
!18 = !{!"vrParticle", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !19, i64 68}
!19 = !{!"vrColor", !10, i64 0, !10, i64 4, !10, i64 8}
!20 = !{!18, !10, i64 16}
!21 = !{!18, !10, i64 4}
!22 = !{!18, !10, i64 20}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass