; LLVM IR from erwincoumans/tiny-differentiable-simulator :: third_party/dear_imgui/imgui.ll (ZN5ImGui11GetDrawDataEv)

; 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.ImGuiContext = type <{ i8, i8, [6 x i8], %struct.ImGuiIO, %struct.ImGuiPlatformIO, %struct.ImGuiStyle, i32, i32, [4 x i8], ptr, float, float, %struct.ImDrawListSharedData, double, i32, i32, i32, i32, i8, i8, i8, i8, i32, ptr, %struct.ImVector.5, %struct.ImVector.5, %struct.ImVector.5, %struct.ImVector.5, %struct.ImGuiStorage, i32, [4 x i8], ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.ImVec2, float, i32, i32, i8, i8, [2 x i8], float, float, i32, i32, float, i8, i8, i8, i8, i8, i8, [2 x i8], i32, i32, [4 x i8], i64, %struct.ImVec2, ptr, i32, i32, i32, i8, i8, [2 x i8], ptr, i32, float, %struct.ImGuiNextWindowData, %struct.ImGuiNextItemData, [4 x i8], %struct.ImVector.6, %struct.ImVector.7, %struct.ImVector.8, %struct.ImVector.9, %struct.ImVector.9, %struct.ImVector.10, float, [4 x i8], ptr, ptr, ptr, i32, i32, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.ImRect, i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, i32, %struct.ImRect, i8, i8, [2 x i8], i32, i32, i32, i32, i32, i32, [4 x i8], %struct.ImGuiNavMoveResult, %struct.ImGuiNavMoveResult, %struct.ImGuiNavMoveResult, ptr, i32, [4 x i8], ptr, ptr, ptr, float, float, i8, [7 x i8], ptr, ptr, i32, i32, i32, i32, i8, [3 x i8], float, i32, i8, i8, i8, i8, i32, i32, i32, [4 x i8], %struct.ImGuiPayload, %struct.ImRect, i32, i32, float, i32, i32, i32, i32, [4 x i8], %struct.ImVector.11, [16 x i8], ptr, %struct.ImPool, %struct.ImVector.13, %struct.ImVector.14, %struct.ImVec2, %struct.ImGuiInputTextState, %struct.ImFont, i32, i32, float, float, [3 x float], %struct.ImVec4, float, i8, i8, [2 x i8], float, float, float, i32, [4 x i8], %struct.ImVector.2, %struct.ImVector.17, %struct.ImVec2, %struct.ImVec2, ptr, %struct.ImGuiDockContext, i8, [3 x i8], float, %struct.ImGuiTextBuffer, %struct.ImVector.20, %struct.ImChunkStream, i8, [3 x i8], i32, ptr, %struct.ImGuiTextBuffer, float, i8, [3 x i8], i32, i32, i32, i8, [3 x i8], i32, [120 x float], i32, float, i32, i32, i32, [3073 x i8], [7 x i8] }>
%struct.ImGuiIO = type { i32, i32, %struct.ImVec2, float, float, ptr, ptr, float, float, float, [22 x i32], float, float, ptr, ptr, float, i8, ptr, %struct.ImVec2, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, float, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.ImVec2, [5 x i8], float, float, i32, i8, i8, i8, i8, [512 x i8], [21 x float], i8, i8, i8, i8, i8, i8, i8, float, i32, i32, i32, i32, i32, %struct.ImVec2, i32, %struct.ImVec2, [5 x %struct.ImVec2], [5 x double], [5 x i8], [5 x i8], [5 x i8], [5 x i8], [5 x i8], [5 x float], [5 x float], [5 x %struct.ImVec2], [5 x float], [512 x float], [512 x float], [21 x float], [21 x float], float, i16, %struct.ImVector }
%struct.ImVector = type { i32, i32, ptr }
%struct.ImGuiPlatformIO = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %struct.ImVector.3, ptr, %struct.ImVector.4 }
%struct.ImVector.3 = type { i32, i32, ptr }
%struct.ImVector.4 = type { i32, i32, ptr }
%struct.ImGuiStyle = type { float, %struct.ImVec2, float, float, %struct.ImVec2, %struct.ImVec2, i32, float, float, float, float, %struct.ImVec2, float, float, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, float, float, float, float, float, float, float, float, float, float, i32, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, float, i8, i8, i8, float, float, [50 x %struct.ImVec4] }
%struct.ImDrawListSharedData = type { %struct.ImVec2, ptr, float, float, float, %struct.ImVec4, i32, [12 x %struct.ImVec2], [64 x i8], ptr }
%struct.ImVector.5 = type { i32, i32, ptr }
%struct.ImGuiStorage = type { %struct.ImVector.0 }
%struct.ImVector.0 = type { i32, i32, ptr }
%struct.ImGuiNextWindowData = type { i32, i32, i32, i32, i32, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, i8, i8, %struct.ImRect, ptr, ptr, float, i32, i32, %struct.ImGuiWindowClass, %struct.ImVec2 }
%struct.ImGuiWindowClass = type <{ i32, i32, i32, i32, i32, i32, i8, i8, [2 x i8] }>
%struct.ImGuiNextItemData = type <{ i32, float, i32, i32, i8, [3 x i8] }>
%struct.ImVector.6 = type { i32, i32, ptr }
%struct.ImVector.7 = type { i32, i32, ptr }
%struct.ImVector.8 = type { i32, i32, ptr }
%struct.ImVector.9 = type { i32, i32, ptr }
%struct.ImVector.10 = type { i32, i32, ptr }
%struct.ImGuiNavMoveResult = type <{ ptr, i32, i32, float, float, float, %struct.ImRect, [4 x i8] }>
%struct.ImGuiPayload = type <{ ptr, i32, i32, i32, i32, [33 x i8], i8, i8, [5 x i8] }>
%struct.ImRect = type { %struct.ImVec2, %struct.ImVec2 }
%struct.ImVector.11 = type { i32, i32, ptr }
%struct.ImPool = type <{ %struct.ImVector.12, %struct.ImGuiStorage, i32, [4 x i8] }>
%struct.ImVector.12 = type { i32, i32, ptr }
%struct.ImVector.13 = type { i32, i32, ptr }
%struct.ImVector.14 = type { i32, i32, ptr }
%struct.ImGuiInputTextState = type { i32, i32, i32, %struct.ImVector, %struct.ImVector.2, %struct.ImVector.2, i8, i32, float, %"struct.ImStb::STB_TexteditState", float, i8, i8, i8, i32, ptr, ptr }
%"struct.ImStb::STB_TexteditState" = type { i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, float, %"struct.ImStb::StbUndoState" }
%"struct.ImStb::StbUndoState" = type { [99 x %"struct.ImStb::StbUndoRecord"], [999 x i16], i16, i16, i32, i32 }
%"struct.ImStb::StbUndoRecord" = type { i32, i32, i32, i32 }
%struct.ImFont = type <{ %struct.ImVector.15, float, float, %struct.ImVector, %struct.ImVector.16, ptr, %struct.ImVec2, ptr, ptr, i16, i16, i16, i8, i8, float, float, float, i32, [2 x i8], [6 x i8] }>
%struct.ImVector.15 = type { i32, i32, ptr }
%struct.ImVector.16 = type { i32, i32, ptr }
%struct.ImVec4 = type { float, float, float, float }
%struct.ImVector.2 = type { i32, i32, ptr }
%struct.ImVector.17 = type { i32, i32, ptr }
%struct.ImVec2 = type { float, float }
%struct.ImGuiDockContext = type <{ %struct.ImGuiStorage, %struct.ImVector.18, %struct.ImVector.19, i8, [7 x i8] }>
%struct.ImVector.18 = type { i32, i32, ptr }
%struct.ImVector.19 = type { i32, i32, ptr }
%struct.ImVector.20 = type { i32, i32, ptr }
%struct.ImChunkStream = type { %struct.ImVector.2 }
%struct.ImGuiTextBuffer = type { %struct.ImVector.2 }
%struct.ImGuiViewportP = type { %struct.ImGuiViewport.base, i32, i32, [2 x i32], i32, i32, %struct.ImVec2, float, float, i16, i8, ptr, [2 x ptr], %struct.ImDrawData, %struct.ImDrawDataBuilder, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2 }
%struct.ImGuiViewport.base = type <{ i32, i32, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, float, [4 x i8], ptr, i32, [4 x i8], ptr, ptr, ptr, ptr, i8, i8, i8 }>
%struct.ImDrawData = type { i8, ptr, i32, i32, i32, %struct.ImVec2, %struct.ImVec2, %struct.ImVec2, ptr }
%struct.ImDrawDataBuilder = type { [2 x %struct.ImVector.32] }
%struct.ImVector.32 = type { i32, i32, ptr }

@GImGui = external dso_local global ptr, align 8

; 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 noundef ptr @_ZN5ImGui11GetDrawDataEv() #1 {
  %1 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  %2 = load ptr, ptr @GImGui, align 8, !tbaa !5
  store ptr %2, ptr %1, align 8, !tbaa !5
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.ImGuiContext, ptr %3, i32 0, i32 80
  %5 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8ImVectorIP14ImGuiViewportPEixEi(ptr noundef nonnull align 8 dereferenceable(16) %4, i32 noundef 0)
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ImGuiViewportP, ptr %6, i32 0, i32 13
  %8 = getelementptr inbounds %struct.ImDrawData, ptr %7, i32 0, i32 0
  %9 = load i8, ptr %8, align 8, !tbaa !9, !range !19, !noundef !20
  %10 = trunc i8 %9 to i1
  br i1 %10, label %11, label %17

11:                                               ; preds = %0
  %12 = load ptr, ptr %1, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ImGuiContext, ptr %12, i32 0, i32 80
  %14 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8ImVectorIP14ImGuiViewportPEixEi(ptr noundef nonnull align 8 dereferenceable(16) %13, i32 noundef 0)
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ImGuiViewportP, ptr %15, i32 0, i32 13
  br label %18

17:                                               ; preds = %0
  br label %18

18:                                               ; preds = %17, %11
  %19 = phi ptr [ %16, %11 ], [ null, %17 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret ptr %19
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN8ImVectorIP14ImGuiViewportPEixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2 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 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 #3 = { 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 = !{!10, !15, i64 168}
!10 = !{!"_ZTS14ImGuiViewportP", !11, i64 0, !12, i64 100, !12, i64 104, !7, i64 108, !12, i64 116, !12, i64 120, !13, i64 124, !14, i64 132, !14, i64 136, !16, i64 140, !15, i64 142, !6, i64 144, !7, i64 152, !17, i64 168, !18, i64 232, !13, i64 264, !13, i64 272, !13, i64 280, !13, i64 288, !13, i64 296}
!11 = !{!"_ZTS13ImGuiViewport", !12, i64 0, !12, i64 4, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !14, i64 40, !6, i64 48, !12, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !15, i64 96, !15, i64 97, !15, i64 98}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS6ImVec2", !14, i64 0, !14, i64 4}
!14 = !{!"float", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!"_ZTS10ImDrawData", !15, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !13, i64 28, !13, i64 36, !13, i64 44, !6, i64 56}
!18 = !{!"_ZTS17ImDrawDataBuilder", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}


; 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"

@GImGui = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN5ImGui11GetDrawDataEv() local_unnamed_addr #0 {
  %1 = load ptr, ptr @GImGui, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %1, i64 7488
  %3 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8ImVectorIP14ImGuiViewportPEixEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef 0)
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 168
  %6 = load i8, ptr %5, align 8, !tbaa !9, !range !19, !noundef !20
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %8, label %12

8:                                                ; preds = %0
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZN8ImVectorIP14ImGuiViewportPEixEi(ptr noundef nonnull align 8 dereferenceable(16) %2, i32 noundef 0)
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 168
  br label %12

12:                                               ; preds = %0, %8
  %13 = phi ptr [ %11, %8 ], [ null, %0 ]
  ret ptr %13
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN8ImVectorIP14ImGuiViewportPEixEi(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #1 align 2

attributes #0 = { 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 #1 = { 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !15, i64 168}
!10 = !{!"_ZTS14ImGuiViewportP", !11, i64 0, !12, i64 100, !12, i64 104, !7, i64 108, !12, i64 116, !12, i64 120, !13, i64 124, !14, i64 132, !14, i64 136, !16, i64 140, !15, i64 142, !6, i64 144, !7, i64 152, !17, i64 168, !18, i64 232, !13, i64 264, !13, i64 272, !13, i64 280, !13, i64 288, !13, i64 296}
!11 = !{!"_ZTS13ImGuiViewport", !12, i64 0, !12, i64 4, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !14, i64 40, !6, i64 48, !12, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !15, i64 96, !15, i64 97, !15, i64 98}
!12 = !{!"int", !7, i64 0}
!13 = !{!"_ZTS6ImVec2", !14, i64 0, !14, i64 4}
!14 = !{!"float", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!"_ZTS10ImDrawData", !15, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !13, i64 28, !13, i64 36, !13, i64 44, !6, i64 56}
!18 = !{!"_ZTS17ImDrawDataBuilder", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}


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