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

; 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] }>
%"class.cyclone::Contact" = type { [2 x ptr], double, double, %"class.cyclone::Vector3", %"class.cyclone::Vector3", double, %"class.cyclone::Matrix3", %"class.cyclone::Vector3", double, [2 x %"class.cyclone::Vector3"] }
%"class.cyclone::Matrix3" = type { [9 x double] }
%"class.cyclone::Vector3" = type { double, double, double, double }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7cyclone5WorldC2Ejj(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = getelementptr inbounds %"class.cyclone::World", ptr %9, i32 0, i32 2
  store ptr null, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds %"class.cyclone::World", ptr %9, i32 0, i32 3
  %12 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN7cyclone15ContactResolverC1Ejdd(ptr noundef nonnull align 8 dereferenceable(33) %11, i32 noundef %12, double noundef 1.000000e-02, double noundef 1.000000e-02)
  %13 = getelementptr inbounds %"class.cyclone::World", ptr %9, i32 0, i32 4
  store ptr null, ptr %13, align 8, !tbaa !16
  %14 = getelementptr inbounds %"class.cyclone::World", ptr %9, i32 0, i32 6
  %15 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %15, ptr %14, align 8, !tbaa !17
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %17, i64 280)
  %19 = extractvalue { i64, i1 } %18, 1
  %20 = extractvalue { i64, i1 } %18, 0
  %21 = select i1 %19, i64 -1, i64 %20
  %22 = call noalias noundef nonnull ptr @_Znam(i64 noundef %21) #6
  %23 = icmp eq i64 %17, 0
  br i1 %23, label %31, label %24

24:                                               ; preds = %3
  %25 = getelementptr inbounds %"class.cyclone::Contact", ptr %22, i64 %17
  br label %26

26:                                               ; preds = %28, %24
  %27 = phi ptr [ %22, %24 ], [ %29, %28 ]
  invoke void @_ZN7cyclone7ContactC2Ev(ptr noundef nonnull align 8 dereferenceable(280) %27)
          to label %28 unwind label %37

28:                                               ; preds = %26
  %29 = getelementptr inbounds %"class.cyclone::Contact", ptr %27, i64 1
  %30 = icmp eq ptr %29, %25
  br i1 %30, label %31, label %26

31:                                               ; preds = %28, %3
  %32 = getelementptr inbounds %"class.cyclone::World", ptr %9, i32 0, i32 5
  store ptr %22, ptr %32, align 8, !tbaa !18
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = icmp eq i32 %33, 0
  %35 = getelementptr inbounds %"class.cyclone::World", ptr %9, i32 0, i32 0
  %36 = zext i1 %34 to i8
  store i8 %36, ptr %35, align 8, !tbaa !19
  ret void

37:                                               ; preds = %26
  %38 = landingpad { ptr, i32 }
          cleanup
  %39 = extractvalue { ptr, i32 } %38, 0
  store ptr %39, ptr %7, align 8
  %40 = extractvalue { ptr, i32 } %38, 1
  store i32 %40, ptr %8, align 4
  call void @_ZdaPvm(ptr noundef %22, i64 noundef %21) #7
  br label %41

41:                                               ; preds = %37
  %42 = load ptr, ptr %7, align 8
  %43 = load i32, ptr %8, align 4
  %44 = insertvalue { ptr, i32 } poison, ptr %42, 0
  %45 = insertvalue { ptr, i32 } %44, i32 %43, 1
  resume { ptr, i32 } %45
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7cyclone7ContactC2Ev(ptr noundef nonnull align 8 dereferenceable(280)) unnamed_addr #4 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) #5

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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nobuiltin allocsize(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 #4 = { inlinehint 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 #5 = { nobuiltin 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 #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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 = !{!"int", !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, !10, i64 72}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN7cyclone15ContactResolverE", !10, i64 0, !10, i64 4, !15, i64 8, !15, i64 16, !10, i64 24, !10, i64 28, !13, i64 32}
!15 = !{!"double", !7, i64 0}
!16 = !{!12, !6, i64 56}
!17 = !{!12, !10, i64 72}
!18 = !{!12, !6, i64 64}
!19 = !{!12, !13, i64 0}


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

%"class.cyclone::Contact" = type { [2 x ptr], double, double, %"class.cyclone::Vector3", %"class.cyclone::Vector3", double, %"class.cyclone::Matrix3", %"class.cyclone::Vector3", double, [2 x %"class.cyclone::Vector3"] }
%"class.cyclone::Matrix3" = type { [9 x double] }
%"class.cyclone::Vector3" = type { double, double, double, double }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7cyclone5WorldC2Ejj(ptr noundef nonnull align 8 dereferenceable(76) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @_ZN7cyclone15ContactResolverC1Ejdd(ptr noundef nonnull align 8 dereferenceable(33) %5, i32 noundef %2, double noundef 1.000000e-02, double noundef 1.000000e-02)
  %6 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr null, ptr %6, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %0, i64 72
  store i32 %1, ptr %7, align 8, !tbaa !15
  %8 = zext i32 %1 to i64
  %9 = mul nuw nsw i64 %8, 280
  %10 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %9) #5
  %11 = icmp eq i32 %1, 0
  br i1 %11, label %.loopexit, label %12

12:                                               ; preds = %3
  %13 = getelementptr inbounds %"class.cyclone::Contact", ptr %10, i64 %8
  br label %14

14:                                               ; preds = %16, %12
  %15 = phi ptr [ %10, %12 ], [ %17, %16 ]
  invoke void @_ZN7cyclone7ContactC2Ev(ptr noundef nonnull align 8 dereferenceable(280) %15)
          to label %16 unwind label %22

16:                                               ; preds = %14
  %17 = getelementptr inbounds i8, ptr %15, i64 280
  %18 = icmp eq ptr %17, %13
  br i1 %18, label %.loopexit, label %14

.loopexit:                                        ; preds = %16, %3
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %10, ptr %19, align 8, !tbaa !16
  %20 = icmp eq i32 %2, 0
  %21 = zext i1 %20 to i8
  store i8 %21, ptr %0, align 8, !tbaa !17
  ret void

22:                                               ; preds = %14
  %23 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZdaPvm(ptr noundef nonnull %10, i64 noundef %9) #6
  resume { ptr, i32 } %23
}

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN7cyclone7ContactC2Ev(ptr noundef nonnull align 8 dereferenceable(280)) unnamed_addr #3 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPvm(ptr noundef, i64 noundef) local_unnamed_addr #4

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" }
attributes #2 = { nobuiltin allocsize(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 = { inlinehint 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 #4 = { nobuiltin 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 = { builtin allocsize(0) }
attributes #6 = { builtin 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, !10, i64 8}
!6 = !{!"_ZTSN7cyclone5WorldE", !7, i64 0, !10, i64 8, !11, i64 16, !10, i64 56, !10, i64 64, !12, i64 72}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTSN7cyclone15ContactResolverE", !12, i64 0, !12, i64 4, !13, i64 8, !13, i64 16, !12, i64 24, !12, i64 28, !7, i64 32}
!12 = !{!"int", !8, i64 0}
!13 = !{!"double", !8, i64 0}
!14 = !{!6, !10, i64 56}
!15 = !{!6, !12, i64 72}
!16 = !{!6, !10, i64 64}
!17 = !{!6, !7, i64 0}


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