; 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.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 }
%struct.jgVector2 = type { float, float }
%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 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 @jgAreaFree(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.jgArea, ptr %5, i32 0, i32 0
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = call ptr @jgListGet(ptr noundef %7, i32 noundef 0)
  store ptr %8, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !15
  br label %9

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

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

18:                                               ; preds = %9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.jgParticle, ptr %19, i32 0, i32 10
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  call void @jgListRemove(ptr noundef %21, ptr noundef %22)
  br label %23

23:                                               ; preds = %18
  %24 = load i32, ptr %4, align 4, !tbaa !15
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %4, align 4, !tbaa !15
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.jgArea, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = load i32, ptr %4, align 4, !tbaa !15
  %30 = call ptr @jgListGet(ptr noundef %28, i32 noundef %29)
  store ptr %30, ptr %3, align 8, !tbaa !5
  br label %9, !llvm.loop !21

31:                                               ; preds = %17
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.jgArea, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  call void @jgListFree(ptr noundef %34)
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.jgArea, ptr %35, i32 0, i32 3
  %37 = load ptr, ptr %36, align 8, !tbaa !23
  call void @free(ptr noundef %37) #5
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %38) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

declare void @jgListRemove(ptr noundef, ptr noundef) #3

declare void @jgListFree(ptr noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #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 = { 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 = { "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 "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, !6, i64 0}
!10 = !{!"jgArea", !6, i64 0, !11, i64 8, !12, i64 28, !6, i64 40, !14, i64 48, !12, i64 52, !12, i64 60, !13, i64 68, !14, i64 72, !13, i64 76, !13, i64 80, !14, i64 84}
!11 = !{!"jgAABB", !12, i64 0, !12, i64 8, !14, i64 16}
!12 = !{!"jgVector2", !13, i64 0, !13, i64 4}
!13 = !{!"float", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!18, !16, i64 8}
!18 = !{!"jgList", !6, i64 0, !16, i64 8, !16, i64 12}
!19 = !{!20, !6, i64 56}
!20 = !{!"jgParticle", !13, i64 0, !12, i64 4, !12, i64 12, !12, i64 20, !12, i64 28, !12, i64 36, !13, i64 44, !13, i64 48, !14, i64 52, !14, i64 53, !6, i64 56}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!10, !6, i64 40}


; 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 ptr @jgListGet(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @jgAreaFree(ptr noundef %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = tail call ptr @jgListGet(ptr noundef %2, i32 noundef 0)
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !14
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.lcssa = phi ptr [ %4, %1 ], [ %15, %.lr.ph ]
  tail call void @jgListFree(ptr noundef nonnull %.lcssa) #4
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !17
  tail call void @free(ptr noundef %9) #4
  tail call void @free(ptr noundef nonnull %0) #4
  ret void

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.012 = phi i32 [ %12, %.lr.ph ], [ 0, %1 ]
  %.01011 = phi ptr [ %14, %.lr.ph ], [ %3, %1 ]
  %10 = getelementptr inbounds i8, ptr %.01011, i64 56
  %11 = load ptr, ptr %10, align 8, !tbaa !18
  tail call void @jgListRemove(ptr noundef %11, ptr noundef nonnull %0) #4
  %12 = add nuw nsw i32 %.012, 1
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %14 = tail call ptr @jgListGet(ptr noundef %13, i32 noundef %12)
  %15 = load ptr, ptr %0, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 8
  %17 = load i32, ptr %16, align 8, !tbaa !14
  %18 = icmp slt i32 %12, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !20
}

declare void @jgListRemove(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @jgListFree(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

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


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