; LLVM IR from Eukky/TRender :: lib/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, i8, i16, i32, ptr, i32, i32, 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

; 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 i32, align 4
  %10 = alloca i32, align 4
  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
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %21

14:                                               ; preds = %4
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = ptrtoint ptr %15 to i64
  %18 = ptrtoint ptr %16 to i64
  %19 = sub i64 %17, %18
  %20 = trunc i64 %19 to i32
  br label %25

21:                                               ; preds = %4
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = call i64 @strlen(ptr noundef %22) #5
  %24 = trunc i64 %23 to i32
  br label %25

25:                                               ; preds = %21, %14
  %26 = phi i32 [ %20, %14 ], [ %24, %21 ]
  store i32 %26, ptr %9, align 4, !tbaa !9
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 7
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = add nsw i32 %27, %29
  %31 = add nsw i32 %30, 1
  %32 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 8
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = icmp sge i32 %31, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %25
  store i32 1, ptr %10, align 4
  br label %97

36:                                               ; preds = %25
  %37 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 7
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = icmp ne i32 %38, %39
  br i1 %40, label %41, label %60

41:                                               ; preds = %36
  %42 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 6
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %43, i64 %45
  %47 = load i32, ptr %9, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  %50 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 6
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 7
  %56 = load i32, ptr %55, align 8, !tbaa !11
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = sub nsw i32 %56, %57
  %59 = sext i32 %58 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %49, ptr align 1 %54, i64 %59, i1 false)
  br label %60

60:                                               ; preds = %41, %36
  %61 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 6
  %62 = load ptr, ptr %61, align 8, !tbaa !16
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %62, i64 %64
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = mul i64 %68, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %65, ptr align 1 %66, i64 %69, i1 false)
  %70 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 6
  %71 = load ptr, ptr %70, align 8, !tbaa !16
  %72 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 7
  %73 = load i32, ptr %72, align 8, !tbaa !11
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = add nsw i32 %73, %74
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i8, ptr %71, i64 %76
  store i8 0, ptr %77, align 1, !tbaa !17
  %78 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 10
  %79 = load i32, ptr %78, align 4, !tbaa !18
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = icmp sge i32 %79, %80
  br i1 %81, label %82, label %87

82:                                               ; preds = %60
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 10
  %85 = load i32, ptr %84, align 4, !tbaa !18
  %86 = add nsw i32 %85, %83
  store i32 %86, ptr %84, align 4, !tbaa !18
  br label %87

87:                                               ; preds = %82, %60
  %88 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 10
  %89 = load i32, ptr %88, align 4, !tbaa !18
  %90 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 12
  store i32 %89, ptr %90, align 4, !tbaa !19
  %91 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 11
  store i32 %89, ptr %91, align 8, !tbaa !20
  %92 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 9
  store i8 1, ptr %92, align 8, !tbaa !21
  %93 = load i32, ptr %9, align 4, !tbaa !9
  %94 = getelementptr inbounds %struct.ImGuiTextEditCallbackData, ptr %11, i32 0, i32 7
  %95 = load i32, ptr %94, align 8, !tbaa !11
  %96 = add nsw i32 %95, %93
  store i32 %96, ptr %94, align 8, !tbaa !11
  store i32 0, ptr %10, align 4
  br label %97

97:                                               ; preds = %87, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %98 = load i32, ptr %10, align 4
  switch i32 %98, label %100 [
    i32 0, label %99
    i32 1, label %99
  ]

99:                                               ; preds = %97, %97
  ret void

100:                                              ; preds = %97
  unreachable
}

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, !10, i64 32}
!12 = !{!"_ZTS25ImGuiTextEditCallbackData", !10, i64 0, !10, i64 4, !6, i64 8, !13, i64 16, !14, i64 18, !10, i64 20, !6, i64 24, !10, i64 32, !10, i64 36, !13, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !10, i64 36}
!16 = !{!12, !6, i64 24}
!17 = !{!7, !7, i64 0}
!18 = !{!12, !10, i64 44}
!19 = !{!12, !10, i64 52}
!20 = !{!12, !10, i64 48}
!21 = !{!12, !13, i64 40}


; 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 nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #0

; 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 {
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %9, label %5

5:                                                ; preds = %4
  %6 = ptrtoint ptr %3 to i64
  %7 = ptrtoint ptr %2 to i64
  %8 = sub i64 %6, %7
  br label %11

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

11:                                               ; preds = %9, %5
  %.in = phi i64 [ %8, %5 ], [ %10, %9 ]
  %12 = trunc i64 %.in to i32
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  %14 = load i32, ptr %13, align 8, !tbaa !5
  %15 = add i32 %12, 1
  %16 = add i32 %15, %14
  %17 = getelementptr inbounds i8, ptr %0, i64 36
  %18 = load i32, ptr %17, align 4, !tbaa !13
  %.not20 = icmp slt i32 %16, %18
  br i1 %.not20, label %19, label %49

19:                                               ; preds = %11
  %.not21 = icmp eq i32 %14, %1
  br i1 %.not21, label %._crit_edge, label %20

._crit_edge:                                      ; preds = %19
  %.pre = sext i32 %1 to i64
  %.pre24 = shl i64 %.in, 32
  %.pre25 = ashr exact i64 %.pre24, 32
  br label %29

20:                                               ; preds = %19
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = sext i32 %1 to i64
  %24 = getelementptr inbounds i8, ptr %22, i64 %23
  %sext = shl i64 %.in, 32
  %25 = ashr exact i64 %sext, 32
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  %27 = sub nsw i32 %14, %1
  %28 = sext i32 %27 to i64
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %26, ptr align 1 %24, i64 %28, i1 false)
  br label %29

29:                                               ; preds = %._crit_edge, %20
  %.pre-phi26 = phi i64 [ %.pre25, %._crit_edge ], [ %25, %20 ]
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %23, %20 ]
  %30 = getelementptr inbounds i8, ptr %0, i64 24
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = getelementptr inbounds i8, ptr %31, i64 %.pre-phi
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %32, ptr align 1 %2, i64 %.pre-phi26, i1 false)
  %33 = load ptr, ptr %30, align 8, !tbaa !14
  %34 = load i32, ptr %13, align 8, !tbaa !5
  %35 = add nsw i32 %34, %12
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i8, ptr %33, i64 %36
  store i8 0, ptr %37, align 1, !tbaa !15
  %38 = getelementptr inbounds i8, ptr %0, i64 44
  %39 = load i32, ptr %38, align 4, !tbaa !16
  %.not23 = icmp slt i32 %39, %1
  br i1 %.not23, label %42, label %40

40:                                               ; preds = %29
  %41 = add nsw i32 %39, %12
  store i32 %41, ptr %38, align 4, !tbaa !16
  br label %42

42:                                               ; preds = %40, %29
  %43 = phi i32 [ %41, %40 ], [ %39, %29 ]
  %44 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %43, ptr %44, align 4, !tbaa !17
  %45 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %43, ptr %45, align 8, !tbaa !18
  %46 = getelementptr inbounds i8, ptr %0, i64 40
  store i8 1, ptr %46, align 8, !tbaa !19
  %47 = load i32, ptr %13, align 8, !tbaa !5
  %48 = add nsw i32 %47, %12
  store i32 %48, ptr %13, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %11, %42
  ret void
}

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, !7, i64 32}
!6 = !{!"_ZTS25ImGuiTextEditCallbackData", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !12, i64 18, !7, i64 20, !10, i64 24, !7, i64 32, !7, i64 36, !11, 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 = !{!"bool", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!6, !7, i64 36}
!14 = !{!6, !10, i64 24}
!15 = !{!8, !8, i64 0}
!16 = !{!6, !7, i64 44}
!17 = !{!6, !7, i64 52}
!18 = !{!6, !7, i64 48}
!19 = !{!6, !11, i64 40}


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