; LLVM IR from ThePhysicsGuys/Physics3D :: Physics3D/geometry (computationBuffer)

; 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.P3D::Vector" = type { %union.anon }
%union.anon = type { [3 x float] }
%"struct.P3D::ComputationBuffers" = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32 }
%"struct.P3D::MinkowskiPointIndices" = type { [2 x %"struct.P3D::Vector"] }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3P3D18ComputationBuffers25createVertexBuffersUnsafeEi(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = sext i32 %6 to i64
  %8 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %7, i64 12)
  %9 = extractvalue { i64, i1 } %8, 1
  %10 = extractvalue { i64, i1 } %8, 0
  %11 = select i1 %9, i64 -1, i64 %10
  %12 = call noalias noundef nonnull ptr @_Znam(i64 noundef %11) #5
  %13 = icmp eq i64 %7, 0
  br i1 %13, label %20, label %14

14:                                               ; preds = %2
  %15 = getelementptr inbounds %"struct.P3D::Vector", ptr %12, i64 %7
  br label %16

16:                                               ; preds = %16, %14
  %17 = phi ptr [ %12, %14 ], [ %18, %16 ]
  call void @_ZN3P3D6VectorIfLm3EEC2Ev(ptr noundef nonnull align 4 dereferenceable(12) %17) #6
  %18 = getelementptr inbounds %"struct.P3D::Vector", ptr %17, i64 1
  %19 = icmp eq ptr %18, %15
  br i1 %19, label %20, label %16

20:                                               ; preds = %16, %2
  %21 = getelementptr inbounds %"struct.P3D::ComputationBuffers", ptr %5, i32 0, i32 0
  store ptr %12, ptr %21, align 8, !tbaa !11
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %23, i64 24)
  %25 = extractvalue { i64, i1 } %24, 1
  %26 = extractvalue { i64, i1 } %24, 0
  %27 = select i1 %25, i64 -1, i64 %26
  %28 = call noalias noundef nonnull ptr @_Znam(i64 noundef %27) #5
  %29 = icmp eq i64 %23, 0
  br i1 %29, label %36, label %30

30:                                               ; preds = %20
  %31 = getelementptr inbounds %"struct.P3D::MinkowskiPointIndices", ptr %28, i64 %23
  br label %32

32:                                               ; preds = %32, %30
  %33 = phi ptr [ %28, %30 ], [ %34, %32 ]
  call void @_ZN3P3D21MinkowskiPointIndicesC2Ev(ptr noundef nonnull align 4 dereferenceable(24) %33) #6
  %34 = getelementptr inbounds %"struct.P3D::MinkowskiPointIndices", ptr %33, i64 1
  %35 = icmp eq ptr %34, %31
  br i1 %35, label %36, label %32

36:                                               ; preds = %32, %20
  %37 = getelementptr inbounds %"struct.P3D::ComputationBuffers", ptr %5, i32 0, i32 5
  store ptr %28, ptr %37, align 8, !tbaa !13
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = getelementptr inbounds %"struct.P3D::ComputationBuffers", ptr %5, i32 0, i32 6
  store i32 %38, ptr %39, align 8, !tbaa !14
  ret void
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3P3D6VectorIfLm3EEC2Ev(ptr noundef nonnull align 4 dereferenceable(12)) unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3P3D21MinkowskiPointIndicesC2Ev(ptr noundef nonnull align 4 dereferenceable(24)) unnamed_addr #4 align 2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { mustprogress 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 #4 = { inlinehint mustprogress 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 = { builtin allocsize(0) }
attributes #6 = { 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 0}
!12 = !{!"_ZTSN3P3D18ComputationBuffersE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52}
!13 = !{!12, !6, i64 40}
!14 = !{!12, !10, i64 48}


; 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.P3D::Vector" = type { %union.anon }
%union.anon = type { [3 x float] }
%"struct.P3D::MinkowskiPointIndices" = type { [2 x %"struct.P3D::Vector"] }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3P3D18ComputationBuffers25createVertexBuffersUnsafeEi(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(56) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = sext i32 %1 to i64
  %4 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %3, i64 12)
  %5 = extractvalue { i64, i1 } %4, 1
  %6 = extractvalue { i64, i1 } %4, 0
  %7 = select i1 %5, i64 -1, i64 %6
  %8 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %7) #5
  %9 = icmp eq i32 %1, 0
  br i1 %9, label %.loopexit3, label %10

10:                                               ; preds = %2
  %11 = getelementptr inbounds %"struct.P3D::Vector", ptr %8, i64 %3
  br label %12

12:                                               ; preds = %12, %10
  %13 = phi ptr [ %8, %10 ], [ %14, %12 ]
  tail call void @_ZN3P3D6VectorIfLm3EEC2Ev(ptr noundef nonnull align 4 dereferenceable(12) %13) #6
  %14 = getelementptr inbounds i8, ptr %13, i64 12
  %15 = icmp eq ptr %14, %11
  br i1 %15, label %.loopexit3, label %12

.loopexit3:                                       ; preds = %12, %2
  store ptr %8, ptr %0, align 8, !tbaa !5
  %16 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %3, i64 24)
  %17 = extractvalue { i64, i1 } %16, 1
  %18 = extractvalue { i64, i1 } %16, 0
  %19 = select i1 %17, i64 -1, i64 %18
  %20 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %19) #5
  br i1 %9, label %.loopexit, label %21

21:                                               ; preds = %.loopexit3
  %22 = getelementptr inbounds %"struct.P3D::MinkowskiPointIndices", ptr %20, i64 %3
  br label %23

23:                                               ; preds = %23, %21
  %24 = phi ptr [ %20, %21 ], [ %25, %23 ]
  tail call void @_ZN3P3D21MinkowskiPointIndicesC2Ev(ptr noundef nonnull align 4 dereferenceable(24) %24) #6
  %25 = getelementptr inbounds i8, ptr %24, i64 24
  %26 = icmp eq ptr %25, %22
  br i1 %26, label %.loopexit, label %23

.loopexit:                                        ; preds = %23, %.loopexit3
  %27 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %20, ptr %27, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %1, ptr %28, align 8, !tbaa !12
  ret void
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3P3D6VectorIfLm3EEC2Ev(ptr noundef nonnull align 4 dereferenceable(12)) unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3P3D21MinkowskiPointIndicesC2Ev(ptr noundef nonnull align 4 dereferenceable(24)) unnamed_addr #4 align 2

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { mustprogress 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 #4 = { inlinehint mustprogress 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 = { builtin allocsize(0) }
attributes #6 = { 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 = !{!"_ZTSN3P3D18ComputationBuffersE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 52}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 40}
!12 = !{!6, !10, i64 48}


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