; LLVM IR from mlcommons/tiny :: benchmark/interface/Middlewares/ST/threadx/common/src (txe_block_pool_create)

; 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_THREAD_STRUCT = type { i64, i64, ptr, ptr, ptr, i64, i64, i64, ptr, 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, ptr, i32, i32, i32, i32, ptr, ptr, ptr, i64 }
%struct.TX_TIMER_INTERNAL_STRUCT = type { i64, i64, ptr, i64, ptr, ptr, ptr }
%struct.TX_BLOCK_POOL_STRUCT = type { i64, ptr, i32, i32, ptr, ptr, i64, i32, ptr, i32, ptr, ptr }

@_tx_thread_preempt_disable = external global i32, align 4
@_tx_block_pool_created_ptr = external global ptr, align 8
@_tx_block_pool_created_count = external global i64, align 8
@_tx_thread_current_ptr = external global ptr, align 8
@_tx_timer_thread = external global %struct.TX_THREAD_STRUCT, align 8
@_tx_thread_system_state = external global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @_txe_block_pool_create(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  store i32 0, ptr %14, align 4, !tbaa !11
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %6
  store i32 2, ptr %14, align 4, !tbaa !11
  br label %96

21:                                               ; preds = %6
  %22 = load i32, ptr %12, align 4, !tbaa !11
  %23 = zext i32 %22 to i64
  %24 = icmp ne i64 %23, 88
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  store i32 2, ptr %14, align 4, !tbaa !11
  br label %95

26:                                               ; preds = %21
  %27 = call i32 @__disable_interrupts()
  store i32 %27, ptr %13, align 4, !tbaa !11
  %28 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %29 = add i32 %28, 1
  store volatile i32 %29, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %30 = load i32, ptr %13, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %30)
  %31 = load ptr, ptr @_tx_block_pool_created_ptr, align 8, !tbaa !5
  store ptr %31, ptr %16, align 8, !tbaa !5
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %46, %26
  %33 = load i64, ptr %15, align 8, !tbaa !9
  %34 = load i64, ptr @_tx_block_pool_created_count, align 8, !tbaa !9
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %36, label %49

36:                                               ; preds = %32
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %16, align 8, !tbaa !5
  %39 = icmp eq ptr %37, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %36
  br label %49

41:                                               ; preds = %36
  %42 = load ptr, ptr %16, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.TX_BLOCK_POOL_STRUCT, ptr %42, i32 0, i32 10
  %44 = load ptr, ptr %43, align 8, !tbaa !13
  store ptr %44, ptr %16, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %41
  br label %46

46:                                               ; preds = %45
  %47 = load i64, ptr %15, align 8, !tbaa !9
  %48 = add i64 %47, 1
  store i64 %48, ptr %15, align 8, !tbaa !9
  br label %32, !llvm.loop !15

49:                                               ; preds = %40, %32
  %50 = call i32 @__disable_interrupts()
  store i32 %50, ptr %13, align 4, !tbaa !11
  %51 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %52 = add i32 %51, -1
  store volatile i32 %52, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %53 = load i32, ptr %13, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %53)
  call void @_tx_thread_system_preempt_check()
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load ptr, ptr %16, align 8, !tbaa !5
  %56 = icmp eq ptr %54, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %49
  store i32 2, ptr %14, align 4, !tbaa !11
  br label %94

58:                                               ; preds = %49
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = icmp eq ptr %59, null
  br i1 %60, label %61, label %62

61:                                               ; preds = %58
  store i32 3, ptr %14, align 4, !tbaa !11
  br label %93

62:                                               ; preds = %58
  %63 = load i64, ptr %9, align 8, !tbaa !9
  %64 = udiv i64 %63, 8
  %65 = mul i64 %64, 8
  %66 = add i64 %65, 8
  %67 = load i64, ptr %11, align 8, !tbaa !9
  %68 = udiv i64 %67, 8
  %69 = mul i64 %68, 8
  %70 = icmp ugt i64 %66, %69
  br i1 %70, label %71, label %72

71:                                               ; preds = %62
  store i32 5, ptr %14, align 4, !tbaa !11
  br label %92

72:                                               ; preds = %62
  %73 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !5
  store ptr %73, ptr %17, align 8, !tbaa !5
  %74 = load ptr, ptr %17, align 8, !tbaa !5
  %75 = icmp eq ptr %74, @_tx_timer_thread
  br i1 %75, label %76, label %77

76:                                               ; preds = %72
  store i32 19, ptr %14, align 4, !tbaa !11
  br label %77

77:                                               ; preds = %76, %72
  %78 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %79 = call i32 @_tx_ipsr_get()
  %80 = zext i32 %79 to i64
  %81 = or i64 %78, %80
  %82 = icmp ne i64 %81, 0
  br i1 %82, label %83, label %91

83:                                               ; preds = %77
  %84 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %85 = call i32 @_tx_ipsr_get()
  %86 = zext i32 %85 to i64
  %87 = or i64 %84, %86
  %88 = icmp ult i64 %87, 4042322160
  br i1 %88, label %89, label %90

89:                                               ; preds = %83
  store i32 19, ptr %14, align 4, !tbaa !11
  br label %90

90:                                               ; preds = %89, %83
  br label %91

91:                                               ; preds = %90, %77
  br label %92

92:                                               ; preds = %91, %71
  br label %93

93:                                               ; preds = %92, %61
  br label %94

94:                                               ; preds = %93, %57
  br label %95

95:                                               ; preds = %94, %25
  br label %96

96:                                               ; preds = %95, %20
  %97 = load i32, ptr %14, align 4, !tbaa !11
  %98 = icmp eq i32 %97, 0
  br i1 %98, label %99, label %106

99:                                               ; preds = %96
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = load i64, ptr %9, align 8, !tbaa !9
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  %104 = load i64, ptr %11, align 8, !tbaa !9
  %105 = call i32 @_tx_block_pool_create(ptr noundef %100, ptr noundef %101, i64 noundef %102, ptr noundef %103, i64 noundef %104)
  store i32 %105, ptr %14, align 4, !tbaa !11
  br label %106

106:                                              ; preds = %99, %96
  %107 = load i32, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  ret i32 %107
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @__disable_interrupts() #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @__restore_interrupt(i32 noundef) #2

declare void @_tx_thread_system_preempt_check() #3

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @_tx_ipsr_get() #2

declare i32 @_tx_block_pool_create(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #3

; 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 = { alwaysinline 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 = { "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 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 72}
!14 = !{!"TX_BLOCK_POOL_STRUCT", !10, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !6, i64 24, !6, i64 32, !10, i64 40, !12, i64 48, !6, i64 56, !12, i64 64, !6, i64 72, !6, i64 80}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%struct.TX_THREAD_STRUCT = type { i64, i64, ptr, ptr, ptr, i64, i64, i64, ptr, 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, ptr, i32, i32, i32, i32, ptr, ptr, ptr, i64 }
%struct.TX_TIMER_INTERNAL_STRUCT = type { i64, i64, ptr, i64, ptr, ptr, ptr }

@_tx_thread_preempt_disable = external global i32, align 4
@_tx_block_pool_created_ptr = external local_unnamed_addr global ptr, align 8
@_tx_block_pool_created_count = external local_unnamed_addr global i64, align 8
@_tx_thread_current_ptr = external local_unnamed_addr global ptr, align 8
@_tx_timer_thread = external global %struct.TX_THREAD_STRUCT, align 8
@_tx_thread_system_state = external global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @_txe_block_pool_create(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = icmp ne ptr %0, null
  %.not = icmp eq i32 %5, 88
  %or.cond26 = and i1 %7, %.not
  br i1 %or.cond26, label %8, label %.thread

8:                                                ; preds = %6
  %9 = tail call i32 @__disable_interrupts()
  %10 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  %11 = add i32 %10, 1
  store volatile i32 %11, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  tail call void @__restore_interrupt(i32 noundef %9)
  %12 = load i64, ptr @_tx_block_pool_created_count, align 8, !tbaa !9
  %.029 = load ptr, ptr @_tx_block_pool_created_ptr, align 8, !tbaa !11
  %13 = icmp eq i64 %12, 0
  %14 = icmp eq ptr %.029, %0
  %or.cond30 = select i1 %13, i1 true, i1 %14
  br i1 %or.cond30, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.032 = phi ptr [ %.0, %.lr.ph ], [ %.029, %8 ]
  %.02131 = phi i64 [ %16, %.lr.ph ], [ 0, %8 ]
  %15 = getelementptr inbounds i8, ptr %.032, i64 72
  %16 = add nuw i64 %.02131, 1
  %.0 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp uge i64 %16, %12
  %18 = icmp eq ptr %.0, %0
  %or.cond = select i1 %17, i1 true, i1 %18
  br i1 %or.cond, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %8
  %.lcssa = phi i1 [ %14, %8 ], [ %18, %.lr.ph ]
  %19 = tail call i32 @__disable_interrupts()
  %20 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  %21 = add i32 %20, -1
  store volatile i32 %21, ptr @_tx_thread_preempt_disable, align 4, !tbaa !5
  tail call void @__restore_interrupt(i32 noundef %19)
  tail call void @_tx_thread_system_preempt_check() #3
  br i1 %.lcssa, label %.thread, label %22

22:                                               ; preds = %._crit_edge
  %23 = icmp eq ptr %3, null
  br i1 %23, label %.thread, label %24

24:                                               ; preds = %22
  %25 = and i64 %2, -8
  %26 = add i64 %25, 8
  %27 = and i64 %4, -8
  %28 = icmp ugt i64 %26, %27
  br i1 %28, label %.thread, label %29

29:                                               ; preds = %24
  %30 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !11
  %.not28 = icmp eq ptr %30, @_tx_timer_thread
  %31 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %32 = tail call i32 @_tx_ipsr_get()
  %33 = zext i32 %32 to i64
  %34 = or i64 %31, %33
  %.not24 = icmp eq i64 %34, 0
  br i1 %.not24, label %42, label %35

35:                                               ; preds = %29
  %36 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %37 = tail call i32 @_tx_ipsr_get()
  %38 = zext i32 %37 to i64
  %39 = or i64 %36, %38
  %40 = icmp ult i64 %39, 4042322160
  %brmerge = select i1 %40, i1 true, i1 %.not28
  %41 = select i1 %40, i1 true, i1 %.not28
  %.mux = select i1 %41, i32 19, i32 0
  br i1 %brmerge, label %.thread, label %43

42:                                               ; preds = %29
  br i1 %.not28, label %.thread, label %43

43:                                               ; preds = %35, %42
  %44 = tail call i32 @_tx_block_pool_create(ptr noundef nonnull %0, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %3, i64 noundef %4) #3
  br label %.thread

.thread:                                          ; preds = %35, %24, %22, %._crit_edge, %6, %43, %42
  %.2 = phi i32 [ %44, %43 ], [ 19, %42 ], [ 5, %24 ], [ 3, %22 ], [ 2, %._crit_edge ], [ 2, %6 ], [ %.mux, %35 ]
  ret i32 %.2
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @__disable_interrupts() local_unnamed_addr #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @__restore_interrupt(i32 noundef) local_unnamed_addr #1

declare void @_tx_thread_system_preempt_check() local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @_tx_ipsr_get() local_unnamed_addr #1

declare i32 @_tx_block_pool_create(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

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 = { alwaysinline 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 = { "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 = !{!"int", !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 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass