; LLVM IR from mvr/jiggle :: src (Particle)

; 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.jgVector2 = type { float, float }
%struct.jgParticle = type { float, %struct.jgVector2, %struct.jgVector2, %struct.jgVector2, %struct.jgVector2, %struct.jgVector2, float, float, i8, i8, ptr }
%struct.jgList = type { ptr, i32, i32 }
%struct.jgArea = type { ptr, %struct.jgAABB, %struct.jgVector2, ptr, i8, %struct.jgVector2, %struct.jgVector2, float, i8, float, float, i8 }
%struct.jgAABB = type { %struct.jgVector2, %struct.jgVector2, i8 }

; 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: 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: inlinehint nounwind uwtable
declare hidden <2 x float> @jgVector2Add(<2 x float>, <2 x float>) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @jgVector2Divide(<2 x float>, float noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @jgVector2Subtract(<2 x float>, <2 x float>) #2

; Function Attrs: nounwind uwtable
define dso_local <2 x float> @jgParticleAreaNormal(ptr noundef %0) #3 {
  %2 = alloca %struct.jgVector2, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.jgVector2, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.jgVector2, align 4
  %8 = alloca %struct.jgVector2, align 4
  %9 = alloca %struct.jgVector2, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.jgParticle, ptr %10, i32 0, i32 0
  %12 = load float, ptr %11, align 8, !tbaa !9
  %13 = fcmp oeq float %12, 0x7FF0000000000000
  br i1 %13, label %14, label %16

14:                                               ; preds = %1
  %15 = call <2 x float> @jgv(float noundef 0.000000e+00, float noundef 0.000000e+00)
  store <2 x float> %15, ptr %2, align 4
  br label %70

16:                                               ; preds = %1
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.jgParticle, ptr %17, i32 0, i32 10
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = getelementptr inbounds %struct.jgList, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %16
  %24 = call <2 x float> @jgv(float noundef 0.000000e+00, float noundef 0.000000e+00)
  store <2 x float> %24, ptr %2, align 4
  br label %70

25:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %26 = call <2 x float> @jgv(float noundef 0.000000e+00, float noundef 0.000000e+00)
  store <2 x float> %26, ptr %4, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.jgParticle, ptr %27, i32 0, i32 10
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = call ptr @jgListGet(ptr noundef %29, i32 noundef 0)
  store ptr %30, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !18
  br label %31

31:                                               ; preds = %46, %25
  %32 = load i32, ptr %6, align 4, !tbaa !18
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.jgParticle, ptr %33, i32 0, i32 10
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = getelementptr inbounds %struct.jgList, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !15
  %38 = icmp slt i32 %32, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %54

40:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.jgArea, ptr %41, i32 0, i32 2
  %43 = load <2 x float>, ptr %4, align 4
  %44 = load <2 x float>, ptr %42, align 4
  %45 = call <2 x float> @jgVector2Add(<2 x float> %43, <2 x float> %44)
  store <2 x float> %45, ptr %7, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %7, i64 8, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %46

46:                                               ; preds = %40
  %47 = load i32, ptr %6, align 4, !tbaa !18
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %6, align 4, !tbaa !18
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.jgParticle, ptr %49, i32 0, i32 10
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = load i32, ptr %6, align 4, !tbaa !18
  %53 = call ptr @jgListGet(ptr noundef %51, i32 noundef %52)
  store ptr %53, ptr %5, align 8, !tbaa !5
  br label %31, !llvm.loop !21

54:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.jgParticle, ptr %55, i32 0, i32 10
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = getelementptr inbounds %struct.jgList, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %58, align 8, !tbaa !15
  %60 = sitofp i32 %59 to float
  %61 = load <2 x float>, ptr %4, align 4
  %62 = call <2 x float> @jgVector2Divide(<2 x float> %61, float noundef %60)
  store <2 x float> %62, ptr %8, align 4
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.jgParticle, ptr %63, i32 0, i32 1
  %65 = load <2 x float>, ptr %64, align 4
  %66 = load <2 x float>, ptr %8, align 4
  %67 = call <2 x float> @jgVector2Subtract(<2 x float> %65, <2 x float> %66)
  store <2 x float> %67, ptr %9, align 4
  %68 = load <2 x float>, ptr %9, align 4
  %69 = call <2 x float> @jgVector2Normalize(<2 x float> %68)
  store <2 x float> %69, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %70

70:                                               ; preds = %54, %23, %14
  %71 = load <2 x float>, ptr %2, align 4
  ret <2 x float> %71
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @jgv(float noundef, float noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @jgListGet(ptr noundef, i32 noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @jgVector2Normalize(<2 x float>) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint nounwind uwtable "min-legal-vector-width"="64" "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 uwtable "min-legal-vector-width"="64" "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 = { inlinehint 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 #5 = { 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, !11, i64 0}
!10 = !{!"jgParticle", !11, i64 0, !12, i64 4, !12, i64 12, !12, i64 20, !12, i64 28, !12, i64 36, !11, i64 44, !11, i64 48, !13, i64 52, !13, i64 53, !6, i64 56}
!11 = !{!"float", !7, i64 0}
!12 = !{!"jgVector2", !11, i64 0, !11, i64 4}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!10, !6, i64 56}
!15 = !{!16, !17, i64 8}
!16 = !{!"jgList", !6, i64 0, !17, i64 8, !17, i64 12}
!17 = !{!"int", !7, i64 0}
!18 = !{!17, !17, i64 0}
!19 = !{i64 0, i64 4, !20, i64 4, i64 4, !20}
!20 = !{!11, !11, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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: inlinehint nounwind uwtable
declare hidden <2 x float> @jgVector2Add(<2 x float>, <2 x float>) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @jgVector2Divide(<2 x float>, float noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @jgVector2Subtract(<2 x float>, <2 x float>) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local <2 x float> @jgParticleAreaNormal(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = load float, ptr %0, align 8, !tbaa !5
  %3 = fcmp oeq float %2, 0x7FF0000000000000
  br i1 %3, label %4, label %6

4:                                                ; preds = %1
  %5 = tail call <2 x float> @jgv(float noundef 0.000000e+00, float noundef 0.000000e+00)
  br label %36

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 56
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !14
  %11 = icmp eq i32 %10, 0
  %12 = tail call <2 x float> @jgv(float noundef 0.000000e+00, float noundef 0.000000e+00)
  br i1 %11, label %36, label %13

13:                                               ; preds = %6
  %14 = load ptr, ptr %7, align 8, !tbaa !13
  %15 = tail call ptr @jgListGet(ptr noundef %14, i32 noundef 0)
  %16 = load ptr, ptr %7, align 8, !tbaa !13
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %13
  %.sroa.05.0.lcssa = phi <2 x float> [ %12, %13 ], [ %28, %.lr.ph ]
  %.lcssa = phi i32 [ %18, %13 ], [ %34, %.lr.ph ]
  %20 = sitofp i32 %.lcssa to float
  %21 = tail call <2 x float> @jgVector2Divide(<2 x float> %.sroa.05.0.lcssa, float noundef %20)
  %22 = getelementptr inbounds i8, ptr %0, i64 4
  %23 = load <2 x float>, ptr %22, align 4
  %24 = tail call <2 x float> @jgVector2Subtract(<2 x float> %23, <2 x float> %21)
  %25 = tail call <2 x float> @jgVector2Normalize(<2 x float> %24)
  br label %36

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.sroa.05.019 = phi <2 x float> [ %28, %.lr.ph ], [ %12, %13 ]
  %.018 = phi ptr [ %31, %.lr.ph ], [ %15, %13 ]
  %.01517 = phi i32 [ %29, %.lr.ph ], [ 0, %13 ]
  %26 = getelementptr inbounds i8, ptr %.018, i64 28
  %27 = load <2 x float>, ptr %26, align 4
  %28 = tail call <2 x float> @jgVector2Add(<2 x float> %.sroa.05.019, <2 x float> %27)
  %29 = add nuw nsw i32 %.01517, 1
  %30 = load ptr, ptr %7, align 8, !tbaa !13
  %31 = tail call ptr @jgListGet(ptr noundef %30, i32 noundef %29)
  %32 = load ptr, ptr %7, align 8, !tbaa !13
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  %34 = load i32, ptr %33, align 8, !tbaa !14
  %35 = icmp slt i32 %29, %34
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !17

36:                                               ; preds = %6, %._crit_edge, %4
  %.sroa.014.0 = phi <2 x float> [ %5, %4 ], [ %25, %._crit_edge ], [ %12, %6 ]
  ret <2 x float> %.sroa.014.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @jgv(float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @jgListGet(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @jgVector2Normalize(<2 x float>) local_unnamed_addr #0

attributes #0 = { inlinehint nounwind uwtable "min-legal-vector-width"="64" "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"="64" "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 = { inlinehint 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" }

!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 = !{!"jgParticle", !7, i64 0, !10, i64 4, !10, i64 12, !10, i64 20, !10, i64 28, !10, i64 36, !7, i64 44, !7, i64 48, !11, i64 52, !11, i64 53, !12, i64 56}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"jgVector2", !7, i64 0, !7, i64 4}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !12, i64 56}
!14 = !{!15, !16, i64 8}
!15 = !{!"jgList", !12, i64 0, !16, i64 8, !16, i64 12}
!16 = !{!"int", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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