; 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 }
%struct.TXM_MODULE_ALLOCATED_OBJECT_STRUCT = type { ptr, ptr, ptr, i64 }

@_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 zeroext i8 @_txm_module_manager_created_object_check(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.TXM_MODULE_INSTANCE_STRUCT, ptr %9, i32 0, i32 11
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp uge ptr %8, %11
  br i1 %12, label %13, label %20

13:                                               ; preds = %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TXM_MODULE_INSTANCE_STRUCT, ptr %15, i32 0, i32 12
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = icmp ult ptr %14, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %13
  store i8 1, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %47

20:                                               ; preds = %13, %2
  %21 = load i32, ptr @_txm_module_manager_object_pool_created, align 4, !tbaa !17
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %45

23:                                               ; preds = %20
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr getelementptr inbounds (%struct.TX_BYTE_POOL_STRUCT, ptr @_txm_module_manager_object_pool, i32 0, i32 6), align 8, !tbaa !18
  %26 = icmp uge ptr %24, %25
  br i1 %26, label %27, label %44

27:                                               ; preds = %23
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr getelementptr inbounds (%struct.TX_BYTE_POOL_STRUCT, ptr @_txm_module_manager_object_pool, i32 0, i32 6), align 8, !tbaa !18
  %30 = load i64, ptr getelementptr inbounds (%struct.TX_BYTE_POOL_STRUCT, ptr @_txm_module_manager_object_pool, i32 0, i32 7), align 8, !tbaa !20
  %31 = getelementptr inbounds i8, ptr %29, i64 %30
  %32 = icmp ult ptr %28, %31
  br i1 %32, label %33, label %44

33:                                               ; preds = %27
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %34, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TXM_MODULE_ALLOCATED_OBJECT_STRUCT, ptr %35, i32 -1
  store ptr %36, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TXM_MODULE_ALLOCATED_OBJECT_STRUCT, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !21
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = icmp eq ptr %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %33
  store i8 1, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %47

43:                                               ; preds = %33
  br label %44

44:                                               ; preds = %43, %27, %23
  br label %45

45:                                               ; preds = %44, %20
  br label %46

46:                                               ; preds = %45
  store i8 0, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %47

47:                                               ; preds = %46, %42, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %48 = load i8, ptr %3, align 1
  ret i8 %48
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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


; 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 zeroext range(i8 0, 2) i8 @_txm_module_manager_created_object_check(ptr noundef readonly %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 88
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp ugt ptr %4, %1
  br i1 %.not, label %9, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 96
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %8 = icmp ugt ptr %7, %1
  br i1 %8, label %21, label %9

9:                                                ; preds = %5, %2
  %10 = load i32, ptr @_txm_module_manager_object_pool_created, align 4, !tbaa !16
  %.not12 = icmp eq i32 %10, 0
  br i1 %.not12, label %20, label %11

11:                                               ; preds = %9
  %12 = load ptr, ptr getelementptr inbounds (i8, ptr @_txm_module_manager_object_pool, i64 48), align 8, !tbaa !17
  %.not13 = icmp ule ptr %12, %1
  %13 = load i64, ptr getelementptr inbounds (i8, ptr @_txm_module_manager_object_pool, i64 56), align 8
  %14 = getelementptr inbounds i8, ptr %12, i64 %13
  %15 = icmp ugt ptr %14, %1
  %or.cond = select i1 %.not13, i1 %15, i1 false
  br i1 %or.cond, label %16, label %20

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %1, i64 -32
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  %19 = icmp eq ptr %18, %0
  br i1 %19, label %21, label %20

20:                                               ; preds = %9, %16, %11
  br label %21

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


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