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

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

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

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

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

; 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 @jgAreaUpdateAABB(ptr noundef %0, float noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca %struct.jgAABB, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.jgVector2, align 4
  %9 = alloca %struct.jgAABB, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.jgArea, ptr %10, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 20, ptr %5) #5
  call void (ptr, ...) @jgAABBNull(ptr dead_on_unwind writable sret(%struct.jgAABB) align 4 %5)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 4 %5, i64 20, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 20, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.jgArea, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = call ptr @jgListGet(ptr noundef %14, i32 noundef 0)
  store ptr %15, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !18
  br label %16

16:                                               ; preds = %33, %2
  %17 = load i32, ptr %7, align 4, !tbaa !18
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.jgArea, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = getelementptr inbounds %struct.jgList, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !20
  %23 = icmp slt i32 %17, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %41

25:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.jgParticle, ptr %26, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %27, i64 8, i1 false), !tbaa.struct !22
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.jgArea, ptr %28, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 20, ptr %9) #5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.jgArea, ptr %30, i32 0, i32 1
  %32 = load <2 x float>, ptr %8, align 4
  call void @jgAABBExpandToInclude(ptr dead_on_unwind writable sret(%struct.jgAABB) align 4 %9, ptr noundef byval(%struct.jgAABB) align 8 %31, <2 x float> %32)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %29, ptr align 4 %9, i64 20, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 20, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %33

33:                                               ; preds = %25
  %34 = load i32, ptr %7, align 4, !tbaa !18
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %7, align 4, !tbaa !18
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.jgArea, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = load i32, ptr %7, align 4, !tbaa !18
  %40 = call ptr @jgListGet(ptr noundef %38, i32 noundef %39)
  store ptr %40, ptr %6, align 8, !tbaa !5
  br label %16, !llvm.loop !23

41:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  ret void
}

declare void @jgAABBNull(ptr dead_on_unwind writable sret(%struct.jgAABB) align 4, ...) #4

declare void @jgAABBExpandToInclude(ptr dead_on_unwind writable sret(%struct.jgAABB) align 4, ptr noundef byval(%struct.jgAABB) align 8, <2 x float>) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9, i64 16, i64 1, !12}
!12 = !{!13, !13, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"jgArea", !6, i64 0, !16, i64 8, !17, i64 28, !6, i64 40, !13, i64 48, !17, i64 52, !17, i64 60, !10, i64 68, !13, i64 72, !10, i64 76, !10, i64 80, !13, i64 84}
!16 = !{!"jgAABB", !17, i64 0, !17, i64 8, !13, i64 16}
!17 = !{!"jgVector2", !10, i64 0, !10, i64 4}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!21, !19, i64 8}
!21 = !{!"jgList", !6, i64 0, !19, i64 8, !19, i64 12}
!22 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}
!23 = distinct !{!23, !24}
!24 = !{!"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.jgAABB = type { %struct.jgVector2, %struct.jgVector2, i8 }
%struct.jgVector2 = type { float, float }

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

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

; Function Attrs: mustprogress 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) #2

; Function Attrs: mustprogress 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 @jgAreaUpdateAABB(ptr noundef %0, float noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.jgAABB, align 4
  %4 = alloca %struct.jgAABB, align 4
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %3) #5
  call void (ptr, ...) @jgAABBNull(ptr dead_on_unwind nonnull writable sret(%struct.jgAABB) align 4 %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %5, ptr noundef nonnull align 4 dereferenceable(20) %3, i64 20, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %3) #5
  %6 = load ptr, ptr %0, align 8, !tbaa !12
  %7 = call ptr @jgListGet(ptr noundef %6, i32 noundef 0)
  %8 = load ptr, ptr %0, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !17
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %2
  ret void

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.011 = phi ptr [ %15, %.lr.ph ], [ %7, %2 ]
  %.0910 = phi i32 [ %13, %.lr.ph ], [ 0, %2 ]
  %12 = getelementptr inbounds i8, ptr %.011, i64 4
  %.sroa.0.0.copyload = load <2 x float>, ptr %12, align 4
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %4) #5
  call void @jgAABBExpandToInclude(ptr dead_on_unwind nonnull writable sret(%struct.jgAABB) align 4 %4, ptr noundef nonnull byval(%struct.jgAABB) align 8 %5, <2 x float> %.sroa.0.0.copyload) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %5, ptr noundef nonnull align 4 dereferenceable(20) %4, i64 20, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %4) #5
  %13 = add nuw nsw i32 %.0910, 1
  %14 = load ptr, ptr %0, align 8, !tbaa !12
  %15 = call ptr @jgListGet(ptr noundef %14, i32 noundef %13)
  %16 = load ptr, ptr %0, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !17
  %19 = icmp slt i32 %13, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !20
}

declare void @jgAABBNull(ptr dead_on_unwind writable sret(%struct.jgAABB) align 4, ...) local_unnamed_addr #4

declare void @jgAABBExpandToInclude(ptr dead_on_unwind writable sret(%struct.jgAABB) align 4, ptr noundef byval(%struct.jgAABB) align 8, <2 x float>) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{i64 0, i64 4, !6, i64 4, i64 4, !6, i64 8, i64 4, !6, i64 12, i64 4, !6, i64 16, i64 1, !10}
!6 = !{!7, !7, i64 0}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"jgArea", !14, i64 0, !15, i64 8, !16, i64 28, !14, i64 40, !11, i64 48, !16, i64 52, !16, i64 60, !7, i64 68, !11, i64 72, !7, i64 76, !7, i64 80, !11, i64 84}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"jgAABB", !16, i64 0, !16, i64 8, !11, i64 16}
!16 = !{!"jgVector2", !7, i64 0, !7, i64 4}
!17 = !{!18, !19, i64 8}
!18 = !{!"jgList", !14, i64 0, !19, i64 8, !19, i64 12}
!19 = !{!"int", !8, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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