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

; 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.ImGuiTextEditCallbackData = type { i32, i32, ptr, i16, i32, ptr, i64, i8, i32, 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 i64 @strlen(ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN25ImGuiTextEditCallbackData11InsertCharsEiPKcS1_(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #3 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %14 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 5
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = call i64 @strlen(ptr noundef %15) #5
  store i64 %16, ptr %9, align 8, !tbaa !16
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %24, label %19

19:                                               ; preds = %4
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = call i64 @strlen(ptr noundef %21) #5
  %23 = getelementptr inbounds i8, ptr %20, i64 %22
  store ptr %23, ptr %8, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %19, %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = ptrtoint ptr %25 to i64
  %28 = ptrtoint ptr %26 to i64
  %29 = sub i64 %27, %28
  store i64 %29, ptr %10, align 8, !tbaa !16
  %30 = load i64, ptr %10, align 8, !tbaa !16
  %31 = load i64, ptr %9, align 8, !tbaa !16
  %32 = add i64 %30, %31
  %33 = add i64 %32, 1
  %34 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 6
  %35 = load i64, ptr %34, align 8, !tbaa !17
  %36 = icmp uge i64 %33, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %24
  store i32 1, ptr %11, align 4
  br label %88

38:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  store i64 %40, ptr %12, align 8, !tbaa !16
  %41 = load i64, ptr %9, align 8, !tbaa !16
  %42 = load i64, ptr %12, align 8, !tbaa !16
  %43 = icmp ne i64 %41, %42
  br i1 %43, label %44, label %58

44:                                               ; preds = %38
  %45 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 5
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = load i64, ptr %12, align 8, !tbaa !16
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  %49 = load i64, ptr %10, align 8, !tbaa !16
  %50 = getelementptr inbounds i8, ptr %48, i64 %49
  %51 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 5
  %52 = load ptr, ptr %51, align 8, !tbaa !11
  %53 = load i64, ptr %12, align 8, !tbaa !16
  %54 = getelementptr inbounds i8, ptr %52, i64 %53
  %55 = load i64, ptr %9, align 8, !tbaa !16
  %56 = load i64, ptr %12, align 8, !tbaa !16
  %57 = sub i64 %55, %56
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %50, ptr align 1 %54, i64 %57, i1 false)
  br label %58

58:                                               ; preds = %44, %38
  %59 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 5
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = load i64, ptr %12, align 8, !tbaa !16
  %62 = getelementptr inbounds i8, ptr %60, i64 %61
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i64, ptr %10, align 8, !tbaa !16
  %65 = mul i64 %64, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %62, ptr align 1 %63, i64 %65, i1 false)
  %66 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 5
  %67 = load ptr, ptr %66, align 8, !tbaa !11
  %68 = load i64, ptr %9, align 8, !tbaa !16
  %69 = load i64, ptr %10, align 8, !tbaa !16
  %70 = add i64 %68, %69
  %71 = getelementptr inbounds i8, ptr %67, i64 %70
  store i8 0, ptr %71, align 1, !tbaa !18
  %72 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 7
  store i8 1, ptr %72, align 8, !tbaa !19
  %73 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 8
  %74 = load i32, ptr %73, align 4, !tbaa !20
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = icmp sge i32 %74, %75
  br i1 %76, label %77, label %83

77:                                               ; preds = %58
  %78 = load i64, ptr %10, align 8, !tbaa !16
  %79 = trunc i64 %78 to i32
  %80 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 8
  %81 = load i32, ptr %80, align 4, !tbaa !20
  %82 = add nsw i32 %81, %79
  store i32 %82, ptr %80, align 4, !tbaa !20
  br label %83

83:                                               ; preds = %77, %58
  %84 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 8
  %85 = load i32, ptr %84, align 4, !tbaa !20
  %86 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 10
  store i32 %85, ptr %86, align 4, !tbaa !21
  %87 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %13, i32 0, i32 9
  store i32 %85, ptr %87, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  store i32 0, ptr %11, align 4
  br label %88

88:                                               ; preds = %83, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %89 = load i32, ptr %11, align 4
  switch i32 %89, label %91 [
    i32 0, label %90
    i32 1, label %90
  ]

90:                                               ; preds = %88, %88
  ret void

91:                                               ; preds = %88
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 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 }
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 = !{!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 24}
!12 = !{!"_ZTS25ImGuiTextEditCallbackData", !10, i64 0, !10, i64 4, !6, i64 8, !13, i64 16, !10, i64 20, !6, i64 24, !14, i64 32, !15, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!12, !14, i64 32}
!18 = !{!7, !7, i64 0}
!19 = !{!12, !15, i64 40}
!20 = !{!12, !10, i64 44}
!21 = !{!12, !10, i64 52}
!22 = !{!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"

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN25ImGuiTextEditCallbackData11InsertCharsEiPKcS1_(ptr nocapture noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %6) #3
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %8, label %11

8:                                                ; preds = %4
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #3
  %10 = getelementptr inbounds i8, ptr %2, i64 %9
  br label %11

11:                                               ; preds = %8, %4
  %.0 = phi ptr [ %3, %4 ], [ %10, %8 ]
  %12 = ptrtoint ptr %.0 to i64
  %13 = ptrtoint ptr %2 to i64
  %14 = sub i64 %12, %13
  %15 = add i64 %14, %7
  %16 = add i64 %15, 1
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  %18 = load i64, ptr %17, align 8, !tbaa !14
  %.not26 = icmp ult i64 %16, %18
  br i1 %.not26, label %19, label %40

19:                                               ; preds = %11
  %20 = sext i32 %1 to i64
  %.not27 = icmp eq i64 %7, %20
  br i1 %.not27, label %25, label %21

21:                                               ; preds = %19
  %22 = getelementptr inbounds i8, ptr %6, i64 %20
  %23 = getelementptr inbounds i8, ptr %22, i64 %14
  %24 = sub i64 %7, %20
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %23, ptr align 1 %22, i64 %24, i1 false)
  %.pre = load ptr, ptr %5, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %21, %19
  %26 = phi ptr [ %.pre, %21 ], [ %6, %19 ]
  %27 = getelementptr inbounds i8, ptr %26, i64 %20
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %27, ptr align 1 %2, i64 %14, i1 false)
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 %15
  store i8 0, ptr %29, align 1, !tbaa !15
  %30 = getelementptr inbounds i8, ptr %0, i64 40
  store i8 1, ptr %30, align 8, !tbaa !16
  %31 = getelementptr inbounds i8, ptr %0, i64 44
  %32 = load i32, ptr %31, align 4, !tbaa !17
  %.not28 = icmp slt i32 %32, %1
  br i1 %.not28, label %36, label %33

33:                                               ; preds = %25
  %34 = trunc i64 %14 to i32
  %35 = add nsw i32 %32, %34
  store i32 %35, ptr %31, align 4, !tbaa !17
  br label %36

36:                                               ; preds = %33, %25
  %37 = phi i32 [ %35, %33 ], [ %32, %25 ]
  %38 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %37, ptr %38, align 4, !tbaa !18
  %39 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %37, ptr %39, align 8, !tbaa !19
  br label %40

40:                                               ; preds = %11, %36
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #0

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nofree nounwind willreturn memory(readwrite, inaccessiblemem: none) 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 = { 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, !10, i64 24}
!6 = !{!"_ZTS25ImGuiTextEditCallbackData", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !7, i64 20, !10, i64 24, !12, i64 32, !13, i64 40, !7, i64 44, !7, i64 48, !7, i64 52}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!6, !12, i64 32}
!15 = !{!8, !8, i64 0}
!16 = !{!6, !13, i64 40}
!17 = !{!6, !7, i64 44}
!18 = !{!6, !7, i64 52}
!19 = !{!6, !7, i64 48}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass