; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes/R3MeshPropertySet.ll (ZN17R3MeshPropertySet10SortByNameEv)

; 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.R3MeshPropertySet = type { ptr, %class.RNArray }
%class.RNArray = type { %class.RNVArray }
%class.RNVArray = type { ptr, i32, i32 }

; 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: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN17R3MeshPropertySet10SortByNameEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %61, %1
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = getelementptr inbounds %struct.R3MeshPropertySet, ptr %7, i32 0, i32 1
  %11 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %10)
  %12 = icmp slt i32 %9, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %8
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %64

14:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %5, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %57, %14
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = getelementptr inbounds %struct.R3MeshPropertySet, ptr %7, i32 0, i32 1
  %20 = call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %19)
  %21 = icmp slt i32 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %60

23:                                               ; preds = %17
  %24 = getelementptr inbounds %struct.R3MeshPropertySet, ptr %7, i32 0, i32 1
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP14R3MeshPropertyEixEi(ptr noundef nonnull align 8 dereferenceable(16) %24, i32 noundef %25)
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = call noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096) %27)
  %29 = getelementptr inbounds %struct.R3MeshPropertySet, ptr %7, i32 0, i32 1
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP14R3MeshPropertyEixEi(ptr noundef nonnull align 8 dereferenceable(16) %29, i32 noundef %30)
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = call noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096) %32)
  %34 = call i32 @strcmp(ptr noundef %28, ptr noundef %33) #7
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %36, label %56

36:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %37 = getelementptr inbounds %struct.R3MeshPropertySet, ptr %7, i32 0, i32 1
  %38 = load i32, ptr %3, align 4, !tbaa !9
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP14R3MeshPropertyEixEi(ptr noundef nonnull align 8 dereferenceable(16) %37, i32 noundef %38)
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  store ptr %40, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.R3MeshPropertySet, ptr %7, i32 0, i32 1
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP14R3MeshPropertyEixEi(ptr noundef nonnull align 8 dereferenceable(16) %41, i32 noundef %42)
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.R3MeshPropertySet, ptr %7, i32 0, i32 1
  %46 = getelementptr inbounds %struct.R3MeshPropertySet, ptr %7, i32 0, i32 1
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = call noundef ptr @_ZNK8RNVArray8KthEntryEi(ptr noundef nonnull align 8 dereferenceable(16) %46, i32 noundef %47)
  %49 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RNArrayIP14R3MeshPropertyE13EntryContentsEPPv(ptr noundef nonnull align 8 dereferenceable(16) %45, ptr noundef %48)
  store ptr %44, ptr %49, align 8, !tbaa !5
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.R3MeshPropertySet, ptr %7, i32 0, i32 1
  %52 = getelementptr inbounds %struct.R3MeshPropertySet, ptr %7, i32 0, i32 1
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = call noundef ptr @_ZNK8RNVArray8KthEntryEi(ptr noundef nonnull align 8 dereferenceable(16) %52, i32 noundef %53)
  %55 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RNArrayIP14R3MeshPropertyE13EntryContentsEPPv(ptr noundef nonnull align 8 dereferenceable(16) %51, ptr noundef %54)
  store ptr %50, ptr %55, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %56

56:                                               ; preds = %36, %23
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %5, align 4, !tbaa !9
  br label %17, !llvm.loop !11

60:                                               ; preds = %22
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %3, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %3, align 4, !tbaa !9
  br label %8, !llvm.loop !13

64:                                               ; preds = %13
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK8RNVArray8KthEntryEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #5 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 = { 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 #3 = { 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 = { 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 = { 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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 nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN17R3MeshPropertySet10SortByNameEv(ptr noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph15, label %._crit_edge

.loopexit:                                        ; preds = %27, %.lr.ph15
  %5 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %6 = icmp slt i32 %7, %5
  br i1 %6, label %.lr.ph15, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.loopexit, %1
  ret void

.lr.ph15:                                         ; preds = %1, %.loopexit
  %.014 = phi i32 [ %7, %.loopexit ], [ 0, %1 ]
  %7 = add nuw nsw i32 %.014, 1
  %8 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph15, %27
  %.01213 = phi i32 [ %28, %27 ], [ %7, %.lr.ph15 ]
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP14R3MeshPropertyEixEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %.014)
  %11 = load ptr, ptr %10, align 8, !tbaa !7
  %12 = tail call noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096) %11)
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP14R3MeshPropertyEixEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %.01213)
  %14 = load ptr, ptr %13, align 8, !tbaa !7
  %15 = tail call noundef ptr @_ZNK14R3MeshProperty4NameEv(ptr noundef nonnull align 8 dereferenceable(1096) %14)
  %16 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) %15) #5
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %27

18:                                               ; preds = %.lr.ph
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP14R3MeshPropertyEixEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %.014)
  %20 = load ptr, ptr %19, align 8, !tbaa !7
  %21 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN7RNArrayIP14R3MeshPropertyEixEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %.01213)
  %22 = load ptr, ptr %21, align 8, !tbaa !7
  %23 = tail call noundef ptr @_ZNK8RNVArray8KthEntryEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %.014)
  %24 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RNArrayIP14R3MeshPropertyE13EntryContentsEPPv(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef %23)
  store ptr %22, ptr %24, align 8, !tbaa !7
  %25 = tail call noundef ptr @_ZNK8RNVArray8KthEntryEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef %.01213)
  %26 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK7RNArrayIP14R3MeshPropertyE13EntryContentsEPPv(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef %25)
  store ptr %20, ptr %26, align 8, !tbaa !7
  br label %27

27:                                               ; preds = %.lr.ph, %18
  %28 = add nuw nsw i32 %.01213, 1
  %29 = tail call noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16) %2)
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %.lr.ph, label %.loopexit, !llvm.loop !11
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK8RNVArray8NEntriesEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK8RNVArray8KthEntryEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #4 align 2

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 #2 = { 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 #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 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 = { nounwind willreturn memory(read) }

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


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