; LLVM IR from yangfengzzz/DigitalVox4 :: editor/imgui_canvas.ll (ZN7ImGuiEx6Canvas14SaveInputStateEv)

; 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.ImGuiIO = type { i32, i32, %struct.ImVec2, float, float, ptr, ptr, float, float, float, float, float, ptr, ptr, float, i8, ptr, %struct.ImVec2, i8, i8, i8, i8, i8, i8, i8, float, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i8, i8, i8, i8, i8, i8, i8, float, i32, i32, i32, i32, i32, %struct.ImVec2, [641 x i32], [512 x i8], %struct.ImVec2, [5 x i8], float, float, i8, i8, i8, i8, [20 x float], i32, i32, [641 x %struct.ImGuiKeyData], i8, %struct.ImVec2, [5 x %struct.ImVec2], [5 x double], [5 x i8], [5 x i8], [5 x i16], [5 x i16], [5 x i8], [5 x i8], [5 x i8], [5 x float], [5 x float], [5 x float], [20 x float], [20 x float], float, i8, i8, i8, i16, %struct.ImVector.0 }
%struct.ImGuiKeyData = type { i8, float, float, float }
%struct.ImVec2 = type { float, float }
%struct.ImVector.0 = type { i32, i32, ptr }
%"struct.ImGuiEx::Canvas" = type <{ i8, [3 x i8], %struct.ImVec2, %struct.ImVec2, %struct.ImRect, [4 x i8], ptr, i32, i32, i32, %"struct.ImGuiEx::CanvasView", %struct.ImRect, %struct.ImVec2, i32, float, %struct.ImVec2, %struct.ImVec2, [5 x %struct.ImVec2], %struct.ImVec2, [4 x i8] }>
%"struct.ImGuiEx::CanvasView" = type { %struct.ImVec2, float, float }
%struct.ImRect = type { %struct.ImVec2, %struct.ImVec2 }
%struct.ImGuiWindow = type <{ ptr, i32, i32, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, float, float, i32, i32, i32, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i16, i16, i16, i16, [2 x i8], i32, i8, i8, i8, i8, i32, i8, i8, i8, i8, i32, %struct.ImVec2, %struct.ImVec2, %struct.ImVector.6, %struct.ImGuiWindowTempData, %struct.ImRect, %struct.ImRect, %struct.ImRect, %struct.ImRect, %struct.ImRect, %struct.ImRect, %struct.ImRect, %struct.ImVec2ih, %struct.ImVec2ih, i32, float, float, [4 x i8], %struct.ImGuiStorage, %struct.ImVector.10, float, i32, ptr, %struct.ImDrawList, ptr, ptr, ptr, ptr, ptr, ptr, ptr, [2 x i32], [2 x %struct.ImRect], i32, i32, i8, [7 x i8] }>
%struct.ImVector.6 = type { i32, i32, ptr }
%struct.ImGuiWindowTempData = type { %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, float, float, %struct.ImVec1, %struct.ImVec1, %struct.ImVec1, %struct.ImVec2, i32, i16, i16, i32, i8, i8, i8, %struct.ImVec2, %struct.ImGuiMenuColumns, i32, i32, %struct.ImVector.7, ptr, ptr, i32, i32, i32, float, float, %struct.ImVector.8, %struct.ImVector.8 }
%struct.ImVec1 = type { float }
%struct.ImGuiMenuColumns = type <{ i32, i32, i16, i16, i16, i16, i16, [4 x i16], [2 x i8] }>
%struct.ImVector.7 = type { i32, i32, ptr }
%struct.ImVector.8 = type { i32, i32, ptr }
%struct.ImVec2ih = type { i16, i16 }
%struct.ImGuiStorage = type { %struct.ImVector.9 }
%struct.ImVector.9 = type { i32, i32, ptr }
%struct.ImVector.10 = type { i32, i32, ptr }
%struct.ImDrawList = type <{ %struct.ImVector, %struct.ImVector.0, %struct.ImVector.1, i32, i32, ptr, ptr, ptr, ptr, %struct.ImVector.2, %struct.ImVector.3, %struct.ImVector.4, %struct.ImDrawCmdHeader, %struct.ImDrawListSplitter, float, [4 x i8] }>
%struct.ImVector = type { i32, i32, ptr }
%struct.ImVector.1 = type { i32, i32, ptr }
%struct.ImVector.2 = type { i32, i32, ptr }
%struct.ImVector.3 = type { i32, i32, ptr }
%struct.ImVector.4 = type { i32, i32, ptr }
%struct.ImDrawCmdHeader = type <{ %struct.ImVec4, ptr, i32, [4 x i8] }>
%struct.ImVec4 = type { float, float, float, float }
%struct.ImDrawListSplitter = type { i32, i32, %struct.ImVector.5 }
%struct.ImVector.5 = type { i32, i32, 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 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: mustprogress uwtable
define dso_local void @_ZN7ImGuiEx6Canvas14SaveInputStateEv(ptr noundef nonnull align 8 dereferenceable(172) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %6 = call noundef nonnull align 8 dereferenceable(14080) ptr @_ZN5ImGui5GetIOEv()
  store ptr %6, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ImGuiIO, ptr %7, i32 0, i32 52
  %9 = getelementptr inbounds %"struct.ImGuiEx::Canvas", ptr %5, i32 0, i32 15
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %8, i64 8, i1 false), !tbaa.struct !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ImGuiIO, ptr %10, i32 0, i32 65
  %12 = getelementptr inbounds %"struct.ImGuiEx::Canvas", ptr %5, i32 0, i32 16
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %11, i64 8, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %13

13:                                               ; preds = %27, %1
  %14 = load i32, ptr %4, align 4, !tbaa !12
  %15 = icmp slt i32 %14, 5
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %30

17:                                               ; preds = %13
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ImGuiIO, ptr %18, i32 0, i32 66
  %20 = load i32, ptr %4, align 4, !tbaa !12
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [5 x %struct.ImVec2], ptr %19, i64 0, i64 %21
  %23 = getelementptr inbounds %"struct.ImGuiEx::Canvas", ptr %5, i32 0, i32 17
  %24 = load i32, ptr %4, align 4, !tbaa !12
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [5 x %struct.ImVec2], ptr %23, i64 0, i64 %25
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %26, ptr align 4 %22, i64 8, i1 false), !tbaa.struct !9
  br label %27

27:                                               ; preds = %17
  %28 = load i32, ptr %4, align 4, !tbaa !12
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %4, align 4, !tbaa !12
  br label %13, !llvm.loop !14

30:                                               ; preds = %16
  %31 = call noundef ptr @_ZN5ImGui16GetCurrentWindowEv()
  %32 = getelementptr inbounds %struct.ImGuiWindow, ptr %31, i32 0, i32 54
  %33 = getelementptr inbounds %struct.ImGuiWindowTempData, ptr %32, i32 0, i32 3
  %34 = getelementptr inbounds %"struct.ImGuiEx::Canvas", ptr %5, i32 0, i32 18
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %34, ptr align 8 %33, i64 8, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

declare noundef nonnull align 8 dereferenceable(14080) ptr @_ZN5ImGui5GetIOEv() #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN5ImGui16GetCurrentWindowEv() #4

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7ImGuiEx6Canvas14SaveInputStateEv(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(172) %0) local_unnamed_addr #0 align 2 {
  %2 = tail call noundef nonnull align 8 dereferenceable(14080) ptr @_ZN5ImGui5GetIOEv()
  %3 = getelementptr inbounds i8, ptr %2, i64 3316
  %4 = getelementptr inbounds i8, ptr %0, i64 108
  %5 = load i64, ptr %3, align 4
  store i64 %5, ptr %4, align 4
  %6 = getelementptr inbounds i8, ptr %2, i64 13692
  %7 = getelementptr inbounds i8, ptr %0, i64 116
  %8 = load i64, ptr %6, align 4
  store i64 %8, ptr %7, align 4
  %9 = getelementptr inbounds i8, ptr %2, i64 13700
  %10 = getelementptr inbounds i8, ptr %0, i64 124
  %11 = load i64, ptr %9, align 4
  store i64 %11, ptr %10, align 4
  %12 = getelementptr inbounds i8, ptr %2, i64 13708
  %13 = getelementptr inbounds i8, ptr %0, i64 132
  %14 = load i64, ptr %12, align 4
  store i64 %14, ptr %13, align 4
  %15 = getelementptr inbounds i8, ptr %2, i64 13716
  %16 = getelementptr inbounds i8, ptr %0, i64 140
  %17 = load i64, ptr %15, align 4
  store i64 %17, ptr %16, align 4
  %18 = getelementptr inbounds i8, ptr %2, i64 13724
  %19 = getelementptr inbounds i8, ptr %0, i64 148
  %20 = load i64, ptr %18, align 4
  store i64 %20, ptr %19, align 4
  %21 = getelementptr inbounds i8, ptr %2, i64 13732
  %22 = getelementptr inbounds i8, ptr %0, i64 156
  %23 = load i64, ptr %21, align 4
  store i64 %23, ptr %22, align 4
  %24 = tail call noundef ptr @_ZN5ImGui16GetCurrentWindowEv()
  %25 = getelementptr inbounds i8, ptr %24, i64 240
  %26 = getelementptr inbounds i8, ptr %0, i64 164
  %27 = load i64, ptr %25, align 8
  store i64 %27, ptr %26, align 4
  ret void
}

declare noundef nonnull align 8 dereferenceable(14080) ptr @_ZN5ImGui5GetIOEv() local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN5ImGui16GetCurrentWindowEv() local_unnamed_addr #2

attributes #0 = { 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 #1 = { "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" }

!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)"}


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