; LLVM IR from Samson-Mano/EM_Propogation_simulation :: EM_Propogation_simulation/src/ImGui/imgui.ll (ZN14ImGuiTextIndex6appendEPKcii)

; 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.ImGuiTextIndex = type <{ %struct.ImVector.10, i32, [4 x i8] }>
%struct.ImVector.10 = type { i32, i32, ptr }

@.str.3 = external hidden unnamed_addr constant [117 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [63 x i8], align 1
@__PRETTY_FUNCTION__._ZN14ImGuiTextIndex6appendEPKcii = external hidden unnamed_addr constant [52 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare noundef ptr @memchr(ptr noundef, i32 noundef, i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14ImGuiTextIndex6appendEPKcii(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #3 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %12 = load ptr, ptr %5, align 8
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp sge i32 %13, 0
  br i1 %14, label %15, label %24

15:                                               ; preds = %4
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp sge i32 %16, %17
  br i1 %18, label %19, label %24

19:                                               ; preds = %15
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = getelementptr inbounds %struct.ImGuiTextIndex, ptr %12, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = icmp sge i32 %20, %22
  br label %24

24:                                               ; preds = %19, %15, %4
  %25 = phi i1 [ false, %15 ], [ false, %4 ], [ %23, %19 ]
  br i1 %25, label %26, label %27

26:                                               ; preds = %24
  br label %29

27:                                               ; preds = %24
  call void @__assert_fail(ptr noundef @.str.17, ptr noundef @.str.3, i32 noundef 2619, ptr noundef @__PRETTY_FUNCTION__._ZN14ImGuiTextIndex6appendEPKcii) #6
  unreachable

28:                                               ; No predecessors!
  br label %29

29:                                               ; preds = %28, %26
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = icmp eq i32 %30, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  br label %90

34:                                               ; preds = %29
  %35 = getelementptr inbounds %struct.ImGuiTextIndex, ptr %12, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %48, label %38

38:                                               ; preds = %34
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ImGuiTextIndex, ptr %12, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = sub nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i8, ptr %39, i64 %43
  %45 = load i8, ptr %44, align 1, !tbaa !14
  %46 = sext i8 %45 to i32
  %47 = icmp eq i32 %46, 10
  br i1 %47, label %48, label %51

48:                                               ; preds = %38, %34
  %49 = getelementptr inbounds %struct.ImGuiTextIndex, ptr %12, i32 0, i32 0
  %50 = getelementptr inbounds %struct.ImGuiTextIndex, ptr %12, i32 0, i32 1
  call void @_ZN8ImVectorIiE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(16) %49, ptr noundef nonnull align 4 dereferenceable(4) %50)
  br label %51

51:                                               ; preds = %48, %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i8, ptr %52, i64 %54
  store ptr %55, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i8, ptr %56, i64 %58
  store ptr %59, ptr %10, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %83, %51
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = ptrtoint ptr %62 to i64
  %65 = ptrtoint ptr %63 to i64
  %66 = sub i64 %64, %65
  %67 = call noundef ptr @memchr(ptr noundef %61, i32 noundef 10, i64 noundef %66) #8
  store ptr %67, ptr %10, align 8, !tbaa !5
  %68 = icmp ne ptr %67, null
  br i1 %68, label %70, label %69

69:                                               ; preds = %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  br label %84

70:                                               ; preds = %60
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i32 1
  store ptr %72, ptr %10, align 8, !tbaa !5
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = icmp ult ptr %72, %73
  br i1 %74, label %75, label %83

75:                                               ; preds = %70
  %76 = getelementptr inbounds %struct.ImGuiTextIndex, ptr %12, i32 0, i32 0
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = ptrtoint ptr %77 to i64
  %80 = ptrtoint ptr %78 to i64
  %81 = sub i64 %79, %80
  %82 = trunc i64 %81 to i32
  store i32 %82, ptr %11, align 4, !tbaa !9
  call void @_ZN8ImVectorIiE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(16) %76, ptr noundef nonnull align 4 dereferenceable(4) %11)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  br label %83

83:                                               ; preds = %75, %70
  br label %60, !llvm.loop !15

84:                                               ; preds = %69
  %85 = getelementptr inbounds %struct.ImGuiTextIndex, ptr %12, i32 0, i32 1
  %86 = load i32, ptr %85, align 8, !tbaa !11
  %87 = load i32, ptr %8, align 4, !tbaa !9
  %88 = call noundef i32 @_ZL5ImMaxIiET_S0_S0_(i32 noundef %86, i32 noundef %87)
  %89 = getelementptr inbounds %struct.ImGuiTextIndex, ptr %12, i32 0, i32 1
  store i32 %88, ptr %89, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  br label %90

90:                                               ; preds = %84, %33
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL5ImMaxIiET_S0_S0_(i32 noundef, i32 noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #2 = { 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 #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 = { 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 = { 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 = { noreturn nounwind }
attributes #7 = { nounwind }
attributes #8 = { 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 = !{!12, !10, i64 16}
!12 = !{!"_ZTS14ImGuiTextIndex", !13, i64 0, !10, i64 16}
!13 = !{!"_ZTS8ImVectorIiE", !10, i64 0, !10, i64 4, !6, i64 8}
!14 = !{!7, !7, 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"

@.str.3 = external hidden unnamed_addr constant [117 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [63 x i8], align 1
@__PRETTY_FUNCTION__._ZN14ImGuiTextIndex6appendEPKcii = external hidden unnamed_addr constant [52 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare noundef ptr @memchr(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14ImGuiTextIndex6appendEPKcii(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #3 align 2 {
  %5 = alloca i32, align 4
  %6 = icmp slt i32 %2, 0
  %.not = icmp slt i32 %3, %2
  %or.cond = or i1 %6, %.not
  br i1 %or.cond, label %.critedge, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %.not24 = icmp sgt i32 %9, %3
  br i1 %.not24, label %.critedge, label %10

.critedge:                                        ; preds = %4, %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.17, ptr noundef nonnull @.str.3, i32 noundef 2619, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN14ImGuiTextIndex6appendEPKcii) #6
  unreachable

10:                                               ; preds = %7
  %11 = icmp eq i32 %2, %3
  br i1 %11, label %42, label %12

12:                                               ; preds = %10
  %13 = icmp eq i32 %9, 0
  br i1 %13, label %20, label %14

14:                                               ; preds = %12
  %15 = sext i32 %9 to i64
  %16 = getelementptr i8, ptr %1, i64 %15
  %17 = getelementptr i8, ptr %16, i64 -1
  %18 = load i8, ptr %17, align 1, !tbaa !12
  %19 = icmp eq i8 %18, 10
  br i1 %19, label %20, label %21

20:                                               ; preds = %14, %12
  tail call void @_ZN8ImVectorIiE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 4 dereferenceable(4) %8)
  br label %21

21:                                               ; preds = %20, %14
  %22 = zext nneg i32 %3 to i64
  %23 = getelementptr inbounds i8, ptr %1, i64 %22
  %24 = zext nneg i32 %2 to i64
  %25 = getelementptr inbounds i8, ptr %1, i64 %24
  %26 = ptrtoint ptr %23 to i64
  %gepdiff = sub nsw i64 %22, %24
  %27 = tail call noundef ptr @memchr(ptr noundef %25, i32 noundef 10, i64 noundef %gepdiff) #7
  %.not2526 = icmp eq ptr %27, null
  br i1 %.not2526, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %21
  %28 = ptrtoint ptr %1 to i64
  br label %31

._crit_edge:                                      ; preds = %39, %21
  %29 = load i32, ptr %8, align 8, !tbaa !5
  %30 = call noundef i32 @_ZL5ImMaxIiET_S0_S0_(i32 noundef %29, i32 noundef %3)
  store i32 %30, ptr %8, align 8, !tbaa !5
  br label %42

31:                                               ; preds = %.lr.ph, %39
  %32 = phi ptr [ %27, %.lr.ph ], [ %41, %39 ]
  %33 = getelementptr inbounds i8, ptr %32, i64 1
  %34 = icmp ult ptr %33, %23
  br i1 %34, label %35, label %._crit_edge27

._crit_edge27:                                    ; preds = %31
  %.pre = ptrtoint ptr %33 to i64
  br label %39

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #8
  %36 = ptrtoint ptr %33 to i64
  %37 = sub i64 %36, %28
  %38 = trunc i64 %37 to i32
  store i32 %38, ptr %5, align 4, !tbaa !13
  call void @_ZN8ImVectorIiE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 4 dereferenceable(4) %5)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #8
  br label %39

39:                                               ; preds = %._crit_edge27, %35
  %.pre-phi = phi i64 [ %.pre, %._crit_edge27 ], [ %36, %35 ]
  %40 = sub i64 %26, %.pre-phi
  %41 = call noundef ptr @memchr(ptr noundef nonnull %33, i32 noundef 10, i64 noundef %40) #7
  %.not25 = icmp eq ptr %41, null
  br i1 %.not25, label %._crit_edge, label %31, !llvm.loop !14

42:                                               ; preds = %10, %._crit_edge
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL5ImMaxIiET_S0_S0_(i32 noundef, i32 noundef) local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #2 = { 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 #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 = { 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 = { 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 = { noreturn nounwind }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { 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, !8, i64 16}
!6 = !{!"_ZTS14ImGuiTextIndex", !7, i64 0, !8, i64 16}
!7 = !{!"_ZTS8ImVectorIiE", !8, i64 0, !8, i64 4, !11, i64 8}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!9, !9, i64 0}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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