; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Align.ll (Z13R2AlignPointsiP7R2PointS0_PKdiii)

; 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.R3Matrix = type { [3 x [3 x double]] }
%class.RNArray = type { %class.RNVArray }
%class.RNVArray = type { ptr, i32, i32 }
%class.R2Point = type { [2 x double] }

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z13R2AlignPointsRK7RNArrayIP7R2PointES4_PKdiii(ptr dead_on_unwind noalias writable sret(%class.R3Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7RNArrayIP7R2PointEC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7RNArrayIP7R2PointE6InsertES1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) #1 align 2

; Function Attrs: nounwind
declare void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z13R2AlignPointsiP7R2PointS0_PKdiii(ptr dead_on_unwind noalias writable sret(%class.R3Matrix) align 8 %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7) #1 personality ptr @__gxx_personality_v0 {
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca %class.RNArray, align 8
  %18 = alloca %class.RNArray, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  store ptr %0, ptr %9, align 8
  store i32 %1, ptr %10, align 4, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !9
  store ptr %4, ptr %13, align 8, !tbaa !9
  store i32 %5, ptr %14, align 4, !tbaa !5
  store i32 %6, ptr %15, align 4, !tbaa !5
  store i32 %7, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %17) #3
  call void @_ZN7RNArrayIP7R2PointEC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %17)
  call void @llvm.lifetime.start.p0(i64 16, ptr %18) #3
  invoke void @_ZN7RNArrayIP7R2PointEC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %18)
          to label %22 unwind label %28

22:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  store i32 0, ptr %21, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %45, %22
  %24 = load i32, ptr %21, align 4, !tbaa !5
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %32, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  br label %52

28:                                               ; preds = %8
  %29 = landingpad { ptr, i32 }
          cleanup
  %30 = extractvalue { ptr, i32 } %29, 0
  store ptr %30, ptr %19, align 8
  %31 = extractvalue { ptr, i32 } %29, 1
  store i32 %31, ptr %20, align 4
  br label %63

32:                                               ; preds = %23
  %33 = load ptr, ptr %11, align 8, !tbaa !9
  %34 = load i32, ptr %21, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %class.R2Point, ptr %33, i64 %35
  %37 = invoke noundef ptr @_ZN7RNArrayIP7R2PointE6InsertES1_(ptr noundef nonnull align 8 dereferenceable(16) %17, ptr noundef %36)
          to label %38 unwind label %48

38:                                               ; preds = %32
  %39 = load ptr, ptr %12, align 8, !tbaa !9
  %40 = load i32, ptr %21, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %class.R2Point, ptr %39, i64 %41
  %43 = invoke noundef ptr @_ZN7RNArrayIP7R2PointE6InsertES1_(ptr noundef nonnull align 8 dereferenceable(16) %18, ptr noundef %42)
          to label %44 unwind label %48

44:                                               ; preds = %38
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %21, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %21, align 4, !tbaa !5
  br label %23, !llvm.loop !11

48:                                               ; preds = %38, %32
  %49 = landingpad { ptr, i32 }
          cleanup
  %50 = extractvalue { ptr, i32 } %49, 0
  store ptr %50, ptr %19, align 8
  %51 = extractvalue { ptr, i32 } %49, 1
  store i32 %51, ptr %20, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  br label %62

52:                                               ; preds = %27
  %53 = load ptr, ptr %13, align 8, !tbaa !9
  %54 = load i32, ptr %14, align 4, !tbaa !5
  %55 = load i32, ptr %15, align 4, !tbaa !5
  %56 = load i32, ptr %16, align 4, !tbaa !5
  invoke void @_Z13R2AlignPointsRK7RNArrayIP7R2PointES4_PKdiii(ptr dead_on_unwind writable sret(%class.R3Matrix) align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %17, ptr noundef nonnull align 8 dereferenceable(16) %18, ptr noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56)
          to label %57 unwind label %58

57:                                               ; preds = %52
  call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %18) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %18) #3
  call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %17) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %17) #3
  ret void

58:                                               ; preds = %52
  %59 = landingpad { ptr, i32 }
          cleanup
  %60 = extractvalue { ptr, i32 } %59, 0
  store ptr %60, ptr %19, align 8
  %61 = extractvalue { ptr, i32 } %59, 1
  store i32 %61, ptr %20, align 4
  br label %62

62:                                               ; preds = %58, %48
  call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %18) #3
  br label %63

63:                                               ; preds = %62, %28
  call void @llvm.lifetime.end.p0(i64 16, ptr %18) #3
  call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %17) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %17) #3
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr %19, align 8
  %66 = load i32, ptr %20, align 4
  %67 = insertvalue { ptr, i32 } poison, ptr %65, 0
  %68 = insertvalue { ptr, i32 } %67, i32 %66, 1
  resume { ptr, i32 } %68
}

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 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

%class.R3Matrix = type { [3 x [3 x double]] }
%class.RNArray = type { %class.RNVArray }
%class.RNVArray = type { ptr, i32, i32 }
%class.R2Point = type { [2 x double] }

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

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z13R2AlignPointsRK7RNArrayIP7R2PointES4_PKdiii(ptr dead_on_unwind noalias writable sret(%class.R3Matrix) align 8, ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7RNArrayIP7R2PointEC2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN7RNArrayIP7R2PointE6InsertES1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: nounwind
declare void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z13R2AlignPointsiP7R2PointS0_PKdiii(ptr dead_on_unwind noalias writable sret(%class.R3Matrix) align 8 %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %9 = alloca %class.RNArray, align 8
  %10 = alloca %class.RNArray, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %9) #3
  call void @_ZN7RNArrayIP7R2PointEC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %9)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %10) #3
  invoke void @_ZN7RNArrayIP7R2PointEC2Ev(ptr noundef nonnull align 8 dereferenceable(16) %10)
          to label %.preheader unwind label %12

.preheader:                                       ; preds = %8
  %11 = icmp sgt i32 %1, 0
  br i1 %11, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %19, %.preheader
  invoke void @_Z13R2AlignPointsRK7RNArrayIP7R2PointES4_PKdiii(ptr dead_on_unwind writable sret(%class.R3Matrix) align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef nonnull align 8 dereferenceable(16) %10, ptr noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7)
          to label %22 unwind label %23

12:                                               ; preds = %8
  %13 = landingpad { ptr, i32 }
          cleanup
  br label %26

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %19 ]
  %14 = getelementptr inbounds %class.R2Point, ptr %2, i64 %indvars.iv
  %15 = invoke noundef ptr @_ZN7RNArrayIP7R2PointE6InsertES1_(ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef %14)
          to label %16 unwind label %20

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds %class.R2Point, ptr %3, i64 %indvars.iv
  %18 = invoke noundef ptr @_ZN7RNArrayIP7R2PointE6InsertES1_(ptr noundef nonnull align 8 dereferenceable(16) %10, ptr noundef %17)
          to label %19 unwind label %20

19:                                               ; preds = %16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

20:                                               ; preds = %16, %.lr.ph
  %21 = landingpad { ptr, i32 }
          cleanup
  br label %25

22:                                               ; preds = %._crit_edge
  call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %10) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %10) #3
  call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %9) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %9) #3
  ret void

23:                                               ; preds = %._crit_edge
  %24 = landingpad { ptr, i32 }
          cleanup
  br label %25

25:                                               ; preds = %23, %20
  %.pn = phi { ptr, i32 } [ %21, %20 ], [ %24, %23 ]
  call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %10) #3
  br label %26

26:                                               ; preds = %25, %12
  %.pn.pn = phi { ptr, i32 } [ %.pn, %25 ], [ %13, %12 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %10) #3
  call void @_ZN8RNVArrayD2Ev(ptr noundef nonnull align 8 dereferenceable(16) %9) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %9) #3
  resume { ptr, i32 } %.pn.pn
}

attributes #0 = { mustprogress 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 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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