; LLVM IR from DarrenSweeney/3D-Physics-Engine :: Physics Engine/Imgui/imgui.ll (ZN15ImGuiTextFilter5BuildEv)

; 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.ImGuiTextFilter::TextRange" = type { ptr, ptr }
%struct.ImGuiTextFilter = type <{ [256 x i8], %class.ImVector.7, i32, [4 x i8] }>
%class.ImVector.7 = type { i64, i64, 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
define dso_local void @_ZN15ImGuiTextFilter5BuildEv(ptr noundef nonnull align 8 dereferenceable(284) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %"struct.ImGuiTextFilter::TextRange", align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %struct.ImGuiTextFilter, ptr %5, i32 0, i32 1
  call void @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef 0)
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #6
  %7 = getelementptr inbounds %struct.ImGuiTextFilter, ptr %5, i32 0, i32 0
  %8 = getelementptr inbounds [256 x i8], ptr %7, i64 0, i64 0
  %9 = getelementptr inbounds %struct.ImGuiTextFilter, ptr %5, i32 0, i32 0
  %10 = getelementptr inbounds [256 x i8], ptr %9, i64 0, i64 0
  %11 = getelementptr inbounds %struct.ImGuiTextFilter, ptr %5, i32 0, i32 0
  %12 = getelementptr inbounds [256 x i8], ptr %11, i64 0, i64 0
  %13 = call i64 @strlen(ptr noundef %12) #7
  %14 = getelementptr inbounds i8, ptr %10, i64 %13
  call void @_ZN15ImGuiTextFilter9TextRangeC2EPKcS2_(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef %8, ptr noundef %14)
  %15 = getelementptr inbounds %struct.ImGuiTextFilter, ptr %5, i32 0, i32 1
  call void @_ZN15ImGuiTextFilter9TextRange5splitEcR8ImVectorIS0_E(ptr noundef nonnull align 8 dereferenceable(16) %3, i8 noundef signext 44, ptr noundef nonnull align 8 dereferenceable(24) %15)
  %16 = getelementptr inbounds %struct.ImGuiTextFilter, ptr %5, i32 0, i32 2
  store i32 0, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  store i64 0, ptr %4, align 8, !tbaa !14
  br label %17

17:                                               ; preds = %44, %1
  %18 = load i64, ptr %4, align 8, !tbaa !14
  %19 = getelementptr inbounds %struct.ImGuiTextFilter, ptr %5, i32 0, i32 1
  %20 = call noundef i64 @_ZNK8ImVectorIN15ImGuiTextFilter9TextRangeEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %19)
  %21 = icmp ne i64 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  br label %47

23:                                               ; preds = %17
  %24 = getelementptr inbounds %struct.ImGuiTextFilter, ptr %5, i32 0, i32 1
  %25 = load i64, ptr %4, align 8, !tbaa !14
  %26 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %24, i64 noundef %25)
  call void @_ZN15ImGuiTextFilter9TextRange11trim_blanksEv(ptr noundef nonnull align 8 dereferenceable(16) %26)
  %27 = getelementptr inbounds %struct.ImGuiTextFilter, ptr %5, i32 0, i32 1
  %28 = load i64, ptr %4, align 8, !tbaa !14
  %29 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 noundef %28)
  %30 = call noundef zeroext i1 @_ZNK15ImGuiTextFilter9TextRange5emptyEv(ptr noundef nonnull align 8 dereferenceable(16) %29)
  br i1 %30, label %31, label %32

31:                                               ; preds = %23
  br label %44

32:                                               ; preds = %23
  %33 = getelementptr inbounds %struct.ImGuiTextFilter, ptr %5, i32 0, i32 1
  %34 = load i64, ptr %4, align 8, !tbaa !14
  %35 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %33, i64 noundef %34)
  %36 = call noundef signext i8 @_ZNK15ImGuiTextFilter9TextRange5frontEv(ptr noundef nonnull align 8 dereferenceable(16) %35)
  %37 = sext i8 %36 to i32
  %38 = icmp ne i32 %37, 45
  br i1 %38, label %39, label %43

39:                                               ; preds = %32
  %40 = getelementptr inbounds %struct.ImGuiTextFilter, ptr %5, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %40, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %39, %32
  br label %44

44:                                               ; preds = %43, %31
  %45 = load i64, ptr %4, align 8, !tbaa !14
  %46 = add i64 %45, 1
  store i64 %46, ptr %4, align 8, !tbaa !14
  br label %17, !llvm.loop !15

47:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #6
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN15ImGuiTextFilter9TextRange5splitEcR8ImVectorIS0_E(ptr noundef nonnull align 8 dereferenceable(16), i8 noundef signext, ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK8ImVectorIN15ImGuiTextFilter9TextRangeEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #5 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #5 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK15ImGuiTextFilter9TextRange5emptyEv(ptr noundef nonnull align 8 dereferenceable(16)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef signext i8 @_ZNK15ImGuiTextFilter9TextRange5frontEv(ptr noundef nonnull align 8 dereferenceable(16)) #3 align 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 = { 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 #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 = { 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 #5 = { 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 #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, !13, i64 280}
!10 = !{!"_ZTS15ImGuiTextFilter", !7, i64 0, !11, i64 256, !13, i64 280}
!11 = !{!"_ZTS8ImVectorIN15ImGuiTextFilter9TextRangeEE", !12, i64 0, !12, i64 8, !6, i64 16}
!12 = !{!"long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%"struct.ImGuiTextFilter::TextRange" = type { ptr, ptr }

; 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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN15ImGuiTextFilter5BuildEv(ptr noundef nonnull align 8 dereferenceable(284) %0) local_unnamed_addr #1 align 2 {
  %2 = alloca %"struct.ImGuiTextFilter::TextRange", align 8
  %3 = getelementptr inbounds i8, ptr %0, i64 256
  tail call void @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef 0)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #6
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #7
  %5 = getelementptr inbounds i8, ptr %0, i64 %4
  call void @_ZN15ImGuiTextFilter9TextRangeC2EPKcS2_(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull %0, ptr noundef nonnull %5)
  call void @_ZN15ImGuiTextFilter9TextRange5splitEcR8ImVectorIS0_E(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 noundef signext 44, ptr noundef nonnull align 8 dereferenceable(24) %3)
  %6 = getelementptr inbounds i8, ptr %0, i64 280
  store i32 0, ptr %6, align 8, !tbaa !5
  %7 = call noundef i64 @_ZNK8ImVectorIN15ImGuiTextFilter9TextRangeEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not6 = icmp eq i64 %7, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %17, %1
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #6
  ret void

.lr.ph:                                           ; preds = %1, %17
  %.07 = phi i64 [ %18, %17 ], [ 0, %1 ]
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %.07)
  call void @_ZN15ImGuiTextFilter9TextRange11trim_blanksEv(ptr noundef nonnull align 8 dereferenceable(16) %8)
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %.07)
  %10 = call noundef zeroext i1 @_ZNK15ImGuiTextFilter9TextRange5emptyEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  br i1 %10, label %17, label %11

11:                                               ; preds = %.lr.ph
  %12 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %.07)
  %13 = call noundef signext i8 @_ZNK15ImGuiTextFilter9TextRange5frontEv(ptr noundef nonnull align 8 dereferenceable(16) %12)
  %.not5 = icmp eq i8 %13, 45
  br i1 %.not5, label %17, label %14

14:                                               ; preds = %11
  %15 = load i32, ptr %6, align 8, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %6, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %11, %14, %.lr.ph
  %18 = add i64 %.07, 1
  %19 = call noundef i64 @_ZNK8ImVectorIN15ImGuiTextFilter9TextRangeEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3)
  %.not = icmp eq i64 %18, %19
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN15ImGuiTextFilter9TextRange5splitEcR8ImVectorIS0_E(ptr noundef nonnull align 8 dereferenceable(16), i8 noundef signext, ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEE6resizeEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK8ImVectorIN15ImGuiTextFilter9TextRangeEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #5 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZN8ImVectorIN15ImGuiTextFilter9TextRangeEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #5 align 2

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

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

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

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 = { 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 #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 = { 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 #5 = { 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 #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, !12, i64 280}
!6 = !{!"_ZTS15ImGuiTextFilter", !7, i64 0, !9, i64 256, !12, i64 280}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"_ZTS8ImVectorIN15ImGuiTextFilter9TextRangeEE", !10, i64 0, !10, i64 8, !11, i64 16}
!10 = !{!"long", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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