; LLVM IR from hadryansalles/Luz :: deps/imgui/imgui.ll (ZN5ImGui14DebugAllocHookEP19ImGuiDebugAllocInfoiPvm)

; 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.ImGuiDebugAllocInfo = type { i32, i32, i16, [6 x %struct.ImGuiDebugAllocEntry] }
%struct.ImGuiDebugAllocEntry = type { i32, i16, i16 }

; 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 nounwind uwtable
define dso_local void @_ZN5ImGui14DebugAllocHookEP19ImGuiDebugAllocInfoiPvm(ptr noundef %0, i32 noundef %1, ptr noundef %2, i64 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, 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 i64 %3, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.ImGuiDebugAllocInfo, ptr %10, i32 0, i32 3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ImGuiDebugAllocInfo, ptr %12, i32 0, i32 2
  %14 = load i16, ptr %13, align 4, !tbaa !13
  %15 = sext i16 %14 to i64
  %16 = getelementptr inbounds [6 x %struct.ImGuiDebugAllocEntry], ptr %11, i64 0, i64 %15
  store ptr %16, ptr %9, align 8, !tbaa !5
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.ImGuiDebugAllocEntry, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !16
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = icmp ne i32 %19, %20
  br i1 %21, label %22, label %46

22:                                               ; preds = %4
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ImGuiDebugAllocInfo, ptr %23, i32 0, i32 2
  %25 = load i16, ptr %24, align 4, !tbaa !13
  %26 = sext i16 %25 to i32
  %27 = add nsw i32 %26, 1
  %28 = srem i32 %27, 6
  %29 = trunc i32 %28 to i16
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.ImGuiDebugAllocInfo, ptr %30, i32 0, i32 2
  store i16 %29, ptr %31, align 4, !tbaa !13
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ImGuiDebugAllocInfo, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ImGuiDebugAllocInfo, ptr %34, i32 0, i32 2
  %36 = load i16, ptr %35, align 4, !tbaa !13
  %37 = sext i16 %36 to i64
  %38 = getelementptr inbounds [6 x %struct.ImGuiDebugAllocEntry], ptr %33, i64 0, i64 %37
  store ptr %38, ptr %9, align 8, !tbaa !5
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ImGuiDebugAllocEntry, ptr %40, i32 0, i32 0
  store i32 %39, ptr %41, align 4, !tbaa !16
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ImGuiDebugAllocEntry, ptr %42, i32 0, i32 2
  store i16 0, ptr %43, align 2, !tbaa !18
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ImGuiDebugAllocEntry, ptr %44, i32 0, i32 1
  store i16 0, ptr %45, align 4, !tbaa !19
  br label %46

46:                                               ; preds = %22, %4
  %47 = load i64, ptr %8, align 8, !tbaa !11
  %48 = icmp ne i64 %47, -1
  br i1 %48, label %49, label %58

49:                                               ; preds = %46
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ImGuiDebugAllocEntry, ptr %50, i32 0, i32 1
  %52 = load i16, ptr %51, align 4, !tbaa !19
  %53 = add i16 %52, 1
  store i16 %53, ptr %51, align 4, !tbaa !19
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.ImGuiDebugAllocInfo, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 4, !tbaa !20
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %55, align 4, !tbaa !20
  br label %67

58:                                               ; preds = %46
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ImGuiDebugAllocEntry, ptr %59, i32 0, i32 2
  %61 = load i16, ptr %60, align 2, !tbaa !18
  %62 = add i16 %61, 1
  store i16 %62, ptr %60, align 2, !tbaa !18
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ImGuiDebugAllocInfo, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 4, !tbaa !21
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %64, align 4, !tbaa !21
  br label %67

67:                                               ; preds = %58, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !15, i64 8}
!14 = !{!"_ZTS19ImGuiDebugAllocInfo", !10, i64 0, !10, i64 4, !15, i64 8, !7, i64 12}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !10, i64 0}
!17 = !{!"_ZTS20ImGuiDebugAllocEntry", !10, i64 0, !15, i64 4, !15, i64 6}
!18 = !{!17, !15, i64 6}
!19 = !{!17, !15, i64 4}
!20 = !{!14, !10, i64 0}
!21 = !{!14, !10, i64 4}


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

%struct.ImGuiDebugAllocEntry = type { i32, i16, i16 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN5ImGui14DebugAllocHookEP19ImGuiDebugAllocInfoiPvm(ptr nocapture noundef %0, i32 noundef %1, ptr nocapture noundef readnone %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i16, ptr %6, align 4, !tbaa !5
  %8 = sext i16 %7 to i64
  %9 = getelementptr inbounds [6 x %struct.ImGuiDebugAllocEntry], ptr %5, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %.not = icmp eq i32 %10, %1
  br i1 %.not, label %20, label %11

11:                                               ; preds = %4
  %12 = sext i16 %7 to i32
  %13 = add nsw i32 %12, 1
  %14 = srem i32 %13, 6
  %15 = trunc nsw i32 %14 to i16
  store i16 %15, ptr %6, align 4, !tbaa !5
  %16 = sext i32 %14 to i64
  %17 = getelementptr inbounds [6 x %struct.ImGuiDebugAllocEntry], ptr %5, i64 0, i64 %16
  store i32 %1, ptr %17, align 4, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %17, i64 6
  store i16 0, ptr %18, align 2, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %17, i64 4
  store i16 0, ptr %19, align 4, !tbaa !14
  br label %20

20:                                               ; preds = %11, %4
  %.0 = phi ptr [ %17, %11 ], [ %9, %4 ]
  %.not17 = icmp eq i64 %3, -1
  br i1 %.not17, label %25, label %21

21:                                               ; preds = %20
  %22 = getelementptr inbounds i8, ptr %.0, i64 4
  %23 = load i16, ptr %22, align 4, !tbaa !14
  %24 = add i16 %23, 1
  store i16 %24, ptr %22, align 4, !tbaa !14
  br label %30

25:                                               ; preds = %20
  %26 = getelementptr inbounds i8, ptr %.0, i64 6
  %27 = load i16, ptr %26, align 2, !tbaa !13
  %28 = add i16 %27, 1
  store i16 %28, ptr %26, align 2, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %0, i64 4
  br label %30

30:                                               ; preds = %25, %21
  %.sink = phi ptr [ %29, %25 ], [ %0, %21 ]
  %31 = load i32, ptr %.sink, align 4, !tbaa !15
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %.sink, align 4, !tbaa !15
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync 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" }

!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 8}
!6 = !{!"_ZTS19ImGuiDebugAllocInfo", !7, i64 0, !7, i64 4, !10, i64 8, !8, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"_ZTS20ImGuiDebugAllocEntry", !7, i64 0, !10, i64 4, !10, i64 6}
!13 = !{!12, !10, i64 6}
!14 = !{!12, !10, i64 4}
!15 = !{!7, !7, i64 0}


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