; LLVM IR from eclipse-threadx/threadx :: common_modules/module_manager/src (txm_module_manager_util)

; 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.TX_BYTE_POOL_STRUCT = type { i64, ptr, i64, i32, ptr, ptr, ptr, i64, ptr, ptr, i32, ptr, ptr }
%struct.TXM_MODULE_INSTANCE_STRUCT = type { i64, ptr, i64, i64, ptr, i64, ptr, ptr, i64, ptr, i64, ptr, ptr, ptr, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, [8 x %struct.TXM_MODULE_MPU_INFO_STRUCT], i64, i64, %struct.TX_THREAD_STRUCT, %struct.TX_THREAD_STRUCT, %struct.TX_QUEUE_STRUCT, [104 x i64], i64, i64, i64, i64, i64, i32, ptr, i64, ptr, ptr }
%struct.TXM_MODULE_MPU_INFO_STRUCT = type { i64, i64 }
%struct.TX_THREAD_STRUCT = type { i64, i64, ptr, ptr, ptr, i64, i64, i64, ptr, ptr, ptr, i32, ptr, ptr, i32, i32, i32, i32, i32, ptr, ptr, i64, %struct.TX_TIMER_INTERNAL_STRUCT, ptr, ptr, ptr, ptr, i64, ptr, i32, i32, ptr, ptr, ptr, i32, i32, i32, i32, ptr, ptr, ptr, i64 }
%struct.TX_TIMER_INTERNAL_STRUCT = type { i64, i64, ptr, i64, ptr, ptr, ptr }
%struct.TX_QUEUE_STRUCT = type { i64, ptr, i32, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr, ptr }

@_txm_module_manager_object_pool_created = external global i32, align 4
@_txm_module_manager_object_pool = external global %struct.TX_BYTE_POOL_STRUCT, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @_txm_module_manager_object_memory_check(ptr noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  %8 = load i32, ptr @_txm_module_manager_object_pool_created, align 4, !tbaa !11
  %9 = icmp eq i32 %8, 1
  br i1 %9, label %10, label %25

10:                                               ; preds = %3
  %11 = load i64, ptr %6, align 8, !tbaa !9
  %12 = load ptr, ptr getelementptr inbounds (%struct.TX_BYTE_POOL_STRUCT, ptr @_txm_module_manager_object_pool, i32 0, i32 6), align 8, !tbaa !13
  %13 = ptrtoint ptr %12 to i64
  %14 = icmp uge i64 %11, %13
  br i1 %14, label %15, label %25

15:                                               ; preds = %10
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = add i64 %16, %17
  %19 = load ptr, ptr getelementptr inbounds (%struct.TX_BYTE_POOL_STRUCT, ptr @_txm_module_manager_object_pool, i32 0, i32 6), align 8, !tbaa !13
  %20 = load i64, ptr getelementptr inbounds (%struct.TX_BYTE_POOL_STRUCT, ptr @_txm_module_manager_object_pool, i32 0, i32 7), align 8, !tbaa !15
  %21 = getelementptr inbounds i8, ptr %19, i64 %20
  %22 = ptrtoint ptr %21 to i64
  %23 = icmp ule i64 %18, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %15
  store i32 0, ptr %4, align 4
  br label %51

25:                                               ; preds = %15, %10, %3
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TXM_MODULE_INSTANCE_STRUCT, ptr %26, i32 0, i32 3
  %28 = load i64, ptr %27, align 8, !tbaa !16
  %29 = and i64 %28, 2
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %49, label %31

31:                                               ; preds = %25
  %32 = load i64, ptr %6, align 8, !tbaa !9
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.TXM_MODULE_INSTANCE_STRUCT, ptr %33, i32 0, i32 11
  %35 = load ptr, ptr %34, align 8, !tbaa !21
  %36 = ptrtoint ptr %35 to i64
  %37 = icmp uge i64 %32, %36
  br i1 %37, label %38, label %48

38:                                               ; preds = %31
  %39 = load i64, ptr %6, align 8, !tbaa !9
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = add i64 %39, %40
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.TXM_MODULE_INSTANCE_STRUCT, ptr %42, i32 0, i32 12
  %44 = load ptr, ptr %43, align 8, !tbaa !22
  %45 = ptrtoint ptr %44 to i64
  %46 = icmp ule i64 %41, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %38
  store i32 0, ptr %4, align 4
  br label %51

48:                                               ; preds = %38, %31
  br label %49

49:                                               ; preds = %48, %25
  br label %50

50:                                               ; preds = %49
  store i32 244, ptr %4, align 4
  br label %51

51:                                               ; preds = %50, %47, %24
  %52 = load i32, ptr %4, align 4
  ret i32 %52
}

attributes #0 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 48}
!14 = !{!"TX_BYTE_POOL_STRUCT", !10, i64 0, !6, i64 8, !10, i64 16, !12, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !6, i64 64, !6, i64 72, !12, i64 80, !6, i64 88, !6, i64 96}
!15 = !{!14, !10, i64 56}
!16 = !{!17, !10, i64 24}
!17 = !{!"TXM_MODULE_INSTANCE_STRUCT", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !6, i64 72, !10, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !10, i64 112, !10, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !7, i64 200, !10, i64 328, !10, i64 336, !18, i64 344, !18, i64 688, !20, i64 1032, !7, i64 1136, !10, i64 1968, !10, i64 1976, !10, i64 1984, !10, i64 1992, !10, i64 2000, !12, i64 2008, !6, i64 2016, !10, i64 2024, !6, i64 2032, !6, i64 2040}
!18 = !{!"TX_THREAD_STRUCT", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !12, i64 88, !6, i64 96, !6, i64 104, !12, i64 112, !12, i64 116, !12, i64 120, !12, i64 124, !12, i64 128, !6, i64 136, !6, i64 144, !10, i64 152, !19, i64 160, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !10, i64 248, !6, i64 256, !12, i64 264, !12, i64 268, !6, i64 272, !6, i64 280, !6, i64 288, !12, i64 296, !12, i64 300, !12, i64 304, !12, i64 308, !6, i64 312, !6, i64 320, !6, i64 328, !10, i64 336}
!19 = !{!"TX_TIMER_INTERNAL_STRUCT", !10, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!20 = !{!"TX_QUEUE_STRUCT", !10, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !12, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!21 = !{!17, !6, i64 88}
!22 = !{!17, !6, i64 96}


; 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.TX_BYTE_POOL_STRUCT = type { i64, ptr, i64, i32, ptr, ptr, ptr, i64, ptr, ptr, i32, ptr, ptr }

@_txm_module_manager_object_pool_created = external local_unnamed_addr global i32, align 4
@_txm_module_manager_object_pool = external local_unnamed_addr global %struct.TX_BYTE_POOL_STRUCT, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 245) i32 @_txm_module_manager_object_memory_check(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @_txm_module_manager_object_pool_created, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %6, label %14

6:                                                ; preds = %3
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @_txm_module_manager_object_pool, i64 48), align 8, !tbaa !9
  %8 = ptrtoint ptr %7 to i64
  %.not = icmp ugt i64 %8, %1
  br i1 %.not, label %14, label %9

9:                                                ; preds = %6
  %10 = add i64 %2, %1
  %11 = load i64, ptr getelementptr inbounds (i8, ptr @_txm_module_manager_object_pool, i64 56), align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %7, i64 %11
  %13 = ptrtoint ptr %12 to i64
  %.not10 = icmp ugt i64 %10, %13
  br i1 %.not10, label %14, label %28

14:                                               ; preds = %9, %6, %3
  %15 = getelementptr inbounds i8, ptr %0, i64 24
  %16 = load i64, ptr %15, align 8, !tbaa !14
  %17 = and i64 %16, 2
  %.not11 = icmp eq i64 %17, 0
  br i1 %.not11, label %18, label %27

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %0, i64 88
  %20 = load ptr, ptr %19, align 8, !tbaa !19
  %21 = ptrtoint ptr %20 to i64
  %.not12 = icmp ugt i64 %21, %1
  br i1 %.not12, label %27, label %22

22:                                               ; preds = %18
  %23 = add i64 %2, %1
  %24 = getelementptr inbounds i8, ptr %0, i64 96
  %25 = load ptr, ptr %24, align 8, !tbaa !20
  %26 = ptrtoint ptr %25 to i64
  %.not13 = icmp ugt i64 %23, %26
  br i1 %.not13, label %27, label %28

27:                                               ; preds = %14, %22, %18
  br label %28

28:                                               ; preds = %22, %9, %27
  %.0 = phi i32 [ 244, %27 ], [ 0, %9 ], [ 0, %22 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 48}
!10 = !{!"TX_BYTE_POOL_STRUCT", !11, i64 0, !12, i64 8, !11, i64 16, !6, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !11, i64 56, !12, i64 64, !12, i64 72, !6, i64 80, !12, i64 88, !12, i64 96}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !11, i64 56}
!14 = !{!15, !11, i64 24}
!15 = !{!"TXM_MODULE_INSTANCE_STRUCT", !11, i64 0, !12, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !11, i64 40, !12, i64 48, !12, i64 56, !11, i64 64, !12, i64 72, !11, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !11, i64 112, !11, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !7, i64 200, !11, i64 328, !11, i64 336, !16, i64 344, !16, i64 688, !18, i64 1032, !7, i64 1136, !11, i64 1968, !11, i64 1976, !11, i64 1984, !11, i64 1992, !11, i64 2000, !6, i64 2008, !12, i64 2016, !11, i64 2024, !12, i64 2032, !12, i64 2040}
!16 = !{!"TX_THREAD_STRUCT", !11, i64 0, !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !6, i64 88, !12, i64 96, !12, i64 104, !6, i64 112, !6, i64 116, !6, i64 120, !6, i64 124, !6, i64 128, !12, i64 136, !12, i64 144, !11, i64 152, !17, i64 160, !12, i64 216, !12, i64 224, !12, i64 232, !12, i64 240, !11, i64 248, !12, i64 256, !6, i64 264, !6, i64 268, !12, i64 272, !12, i64 280, !12, i64 288, !6, i64 296, !6, i64 300, !6, i64 304, !6, i64 308, !12, i64 312, !12, i64 320, !12, i64 328, !11, i64 336}
!17 = !{!"TX_TIMER_INTERNAL_STRUCT", !11, i64 0, !11, i64 8, !12, i64 16, !11, i64 24, !12, i64 32, !12, i64 40, !12, i64 48}
!18 = !{!"TX_QUEUE_STRUCT", !11, i64 0, !12, i64 8, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !6, i64 72, !12, i64 80, !12, i64 88, !12, i64 96}
!19 = !{!15, !12, i64 88}
!20 = !{!15, !12, i64 96}


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