; LLVM IR from idmillington/cyclone-physics :: src/world.ll (ZN7cyclone5World10runPhysicsEd)

; 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"

%"class.cyclone::World" = type <{ i8, [7 x i8], ptr, %"class.cyclone::ContactResolver", ptr, ptr, i32, [4 x i8] }>
%"class.cyclone::ContactResolver" = type <{ i32, i32, double, double, i32, i32, i8, [7 x i8] }>
%"struct.cyclone::World::BodyRegistration" = type { ptr, ptr }

; 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: mustprogress uwtable
declare dso_local noundef i32 @_ZN7cyclone5World16generateContactsEv(ptr noundef nonnull align 8 dereferenceable(76)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7cyclone5World10runPhysicsEd(ptr noundef nonnull align 8 dereferenceable(76) %0, double noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = getelementptr inbounds %"class.cyclone::World", ptr %7, i32 0, i32 2
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  store ptr %9, ptr %5, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %13, %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %21

13:                                               ; preds = %10
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %"struct.cyclone::World::BodyRegistration", ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = load double, ptr %4, align 8, !tbaa !9
  call void @_ZN7cyclone9RigidBody9integrateEd(ptr noundef nonnull align 8 dereferenceable(536) %16, double noundef %17)
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.cyclone::World::BodyRegistration", ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !18
  store ptr %20, ptr %5, align 8, !tbaa !5
  br label %10, !llvm.loop !19

21:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %22 = call noundef i32 @_ZN7cyclone5World16generateContactsEv(ptr noundef nonnull align 8 dereferenceable(76) %7)
  store i32 %22, ptr %6, align 4, !tbaa !21
  %23 = getelementptr inbounds %"class.cyclone::World", ptr %7, i32 0, i32 0
  %24 = load i8, ptr %23, align 8, !tbaa !22, !range !23, !noundef !24
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %30

26:                                               ; preds = %21
  %27 = getelementptr inbounds %"class.cyclone::World", ptr %7, i32 0, i32 3
  %28 = load i32, ptr %6, align 4, !tbaa !21
  %29 = mul i32 %28, 4
  call void @_ZN7cyclone15ContactResolver13setIterationsEj(ptr noundef nonnull align 8 dereferenceable(33) %27, i32 noundef %29)
  br label %30

30:                                               ; preds = %26, %21
  %31 = getelementptr inbounds %"class.cyclone::World", ptr %7, i32 0, i32 3
  %32 = getelementptr inbounds %"class.cyclone::World", ptr %7, i32 0, i32 5
  %33 = load ptr, ptr %32, align 8, !tbaa !25
  %34 = load i32, ptr %6, align 4, !tbaa !21
  %35 = load double, ptr %4, align 8, !tbaa !9
  call void @_ZN7cyclone15ContactResolver15resolveContactsEPNS_7ContactEjd(ptr noundef nonnull align 8 dereferenceable(33) %31, ptr noundef %33, i32 noundef %34, double noundef %35)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare void @_ZN7cyclone9RigidBody9integrateEd(ptr noundef nonnull align 8 dereferenceable(536), double noundef) #2

declare void @_ZN7cyclone15ContactResolver13setIterationsEj(ptr noundef nonnull align 8 dereferenceable(33), i32 noundef) #2

declare void @_ZN7cyclone15ContactResolver15resolveContactsEPNS_7ContactEjd(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i32 noundef, double noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTSN7cyclone5WorldE", !13, i64 0, !6, i64 8, !14, i64 16, !6, i64 56, !6, i64 64, !15, i64 72}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN7cyclone15ContactResolverE", !15, i64 0, !15, i64 4, !10, i64 8, !10, i64 16, !15, i64 24, !15, i64 28, !13, i64 32}
!15 = !{!"int", !7, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTSN7cyclone5World16BodyRegistrationE", !6, i64 0, !6, i64 8}
!18 = !{!17, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!15, !15, i64 0}
!22 = !{!12, !13, i64 0}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = !{!12, !6, i64 64}


; 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: mustprogress uwtable
declare dso_local noundef i32 @_ZN7cyclone5World16generateContactsEv(ptr noundef nonnull align 8 dereferenceable(76)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7cyclone5World10runPhysicsEd(ptr noundef nonnull align 8 dereferenceable(76) %0, double noundef %1) local_unnamed_addr #0 align 2 {
  %.0.in7 = getelementptr inbounds i8, ptr %0, i64 8
  %.08 = load ptr, ptr %.0.in7, align 8, !tbaa !5
  %.not9 = icmp eq ptr %.08, null
  br i1 %.not9, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.010 = phi ptr [ %.0, %.lr.ph ], [ %.08, %2 ]
  %3 = load ptr, ptr %.010, align 8, !tbaa !9
  tail call void @_ZN7cyclone9RigidBody9integrateEd(ptr noundef nonnull align 8 dereferenceable(536) %3, double noundef %1)
  %.0.in = getelementptr inbounds i8, ptr %.010, i64 8
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %2
  %4 = tail call noundef i32 @_ZN7cyclone5World16generateContactsEv(ptr noundef nonnull align 8 dereferenceable(76) %0)
  %5 = load i8, ptr %0, align 8, !tbaa !13, !range !19, !noundef !20
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %7, label %10

7:                                                ; preds = %._crit_edge
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = shl i32 %4, 2
  tail call void @_ZN7cyclone15ContactResolver13setIterationsEj(ptr noundef nonnull align 8 dereferenceable(33) %8, i32 noundef %9)
  br label %10

10:                                               ; preds = %7, %._crit_edge
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  %13 = load ptr, ptr %12, align 8, !tbaa !21
  tail call void @_ZN7cyclone15ContactResolver15resolveContactsEPNS_7ContactEjd(ptr noundef nonnull align 8 dereferenceable(33) %11, ptr noundef %13, i32 noundef %4, double noundef %1)
  ret void
}

declare void @_ZN7cyclone9RigidBody9integrateEd(ptr noundef nonnull align 8 dereferenceable(536), double noundef) local_unnamed_addr #1

declare void @_ZN7cyclone15ContactResolver13setIterationsEj(ptr noundef nonnull align 8 dereferenceable(33), i32 noundef) local_unnamed_addr #1

declare void @_ZN7cyclone15ContactResolver15resolveContactsEPNS_7ContactEjd(ptr noundef nonnull align 8 dereferenceable(33), ptr noundef, i32 noundef, double noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { "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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN7cyclone5World16BodyRegistrationE", !6, i64 0, !6, i64 8}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTSN7cyclone5WorldE", !15, i64 0, !6, i64 8, !16, i64 16, !6, i64 56, !6, i64 64, !17, i64 72}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSN7cyclone15ContactResolverE", !17, i64 0, !17, i64 4, !18, i64 8, !18, i64 16, !17, i64 24, !17, i64 28, !15, i64 32}
!17 = !{!"int", !7, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!14, !6, i64 64}


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