; LLVM IR from mlcommons/tiny :: benchmark/interface/Middlewares/ST/threadx/common/src (txe_byte_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_BYTE_POOL_STRUCT = type { i64, ptr, i64, i32, ptr, ptr, ptr, i64, ptr, ptr, i32, ptr, ptr }

@_tx_thread_preempt_disable = external global i32, align 4
@_tx_byte_pool_created_ptr = external global ptr, align 8
@_tx_byte_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_byte_pool_create(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store i32 0, ptr %12, align 4, !tbaa !11
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %5
  store i32 2, ptr %12, align 4, !tbaa !11
  br label %88

19:                                               ; preds = %5
  %20 = load i32, ptr %10, align 4, !tbaa !11
  %21 = zext i32 %20 to i64
  %22 = icmp ne i64 %21, 104
  br i1 %22, label %23, label %24

23:                                               ; preds = %19
  store i32 2, ptr %12, align 4, !tbaa !11
  br label %87

24:                                               ; preds = %19
  %25 = call i32 @__disable_interrupts()
  store i32 %25, ptr %11, align 4, !tbaa !11
  %26 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %27 = add i32 %26, 1
  store volatile i32 %27, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %28 = load i32, ptr %11, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %28)
  %29 = load ptr, ptr @_tx_byte_pool_created_ptr, align 8, !tbaa !5
  store ptr %29, ptr %14, align 8, !tbaa !5
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %44, %24
  %31 = load i64, ptr %13, align 8, !tbaa !9
  %32 = load i64, ptr @_tx_byte_pool_created_count, align 8, !tbaa !9
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %34, label %47

34:                                               ; preds = %30
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %14, align 8, !tbaa !5
  %37 = icmp eq ptr %35, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  br label %47

39:                                               ; preds = %34
  %40 = load ptr, ptr %14, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TX_BYTE_POOL_STRUCT, ptr %40, i32 0, i32 11
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  store ptr %42, ptr %14, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %39
  br label %44

44:                                               ; preds = %43
  %45 = load i64, ptr %13, align 8, !tbaa !9
  %46 = add i64 %45, 1
  store i64 %46, ptr %13, align 8, !tbaa !9
  br label %30, !llvm.loop !15

47:                                               ; preds = %38, %30
  %48 = call i32 @__disable_interrupts()
  store i32 %48, ptr %11, align 4, !tbaa !11
  %49 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %50 = add i32 %49, -1
  store volatile i32 %50, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %51 = load i32, ptr %11, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %51)
  call void @_tx_thread_system_preempt_check()
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  %54 = icmp eq ptr %52, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %47
  store i32 2, ptr %12, align 4, !tbaa !11
  br label %86

56:                                               ; preds = %47
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = icmp eq ptr %57, null
  br i1 %58, label %59, label %60

59:                                               ; preds = %56
  store i32 3, ptr %12, align 4, !tbaa !11
  br label %85

60:                                               ; preds = %56
  %61 = load i64, ptr %9, align 8, !tbaa !9
  %62 = icmp ult i64 %61, 100
  br i1 %62, label %63, label %64

63:                                               ; preds = %60
  store i32 5, ptr %12, align 4, !tbaa !11
  br label %84

64:                                               ; preds = %60
  %65 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !5
  store ptr %65, ptr %15, align 8, !tbaa !5
  %66 = load ptr, ptr %15, align 8, !tbaa !5
  %67 = icmp eq ptr %66, @_tx_timer_thread
  br i1 %67, label %68, label %69

68:                                               ; preds = %64
  store i32 19, ptr %12, align 4, !tbaa !11
  br label %69

69:                                               ; preds = %68, %64
  %70 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %71 = call i32 @_tx_ipsr_get()
  %72 = zext i32 %71 to i64
  %73 = or i64 %70, %72
  %74 = icmp ne i64 %73, 0
  br i1 %74, label %75, label %83

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

81:                                               ; preds = %75
  store i32 19, ptr %12, align 4, !tbaa !11
  br label %82

82:                                               ; preds = %81, %75
  br label %83

83:                                               ; preds = %82, %69
  br label %84

84:                                               ; preds = %83, %63
  br label %85

85:                                               ; preds = %84, %59
  br label %86

86:                                               ; preds = %85, %55
  br label %87

87:                                               ; preds = %86, %23
  br label %88

88:                                               ; preds = %87, %18
  %89 = load i32, ptr %12, align 4, !tbaa !11
  %90 = icmp eq i32 %89, 0
  br i1 %90, label %91, label %97

91:                                               ; preds = %88
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = load i64, ptr %9, align 8, !tbaa !9
  %96 = call i32 @_tx_byte_pool_create(ptr noundef %92, ptr noundef %93, ptr noundef %94, i64 noundef %95)
  store i32 %96, ptr %12, align 4, !tbaa !11
  br label %97

97:                                               ; preds = %91, %88
  %98 = load i32, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  ret i32 %98
}

; 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_byte_pool_create(ptr noundef, ptr 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 88}
!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 = 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_byte_pool_created_ptr = external local_unnamed_addr global ptr, align 8
@_tx_byte_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_byte_pool_create(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp ne ptr %0, null
  %.not = icmp eq i32 %4, 104
  %or.cond24 = and i1 %6, %.not
  br i1 %or.cond24, label %7, label %.thread

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

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.030 = phi ptr [ %.0, %.lr.ph ], [ %.027, %7 ]
  %.01929 = phi i64 [ %15, %.lr.ph ], [ 0, %7 ]
  %14 = getelementptr inbounds i8, ptr %.030, i64 88
  %15 = add nuw i64 %.01929, 1
  %.0 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp uge i64 %15, %11
  %17 = icmp eq ptr %.0, %0
  %or.cond = select i1 %16, i1 true, i1 %17
  br i1 %or.cond, label %._crit_edge, label %.lr.ph, !llvm.loop !13

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

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

23:                                               ; preds = %21
  %24 = icmp ult i64 %3, 100
  br i1 %24, label %.thread, label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !11
  %.not26 = icmp eq ptr %26, @_tx_timer_thread
  %27 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %28 = tail call i32 @_tx_ipsr_get()
  %29 = zext i32 %28 to i64
  %30 = or i64 %27, %29
  %.not22 = icmp eq i64 %30, 0
  br i1 %.not22, label %38, label %31

31:                                               ; preds = %25
  %32 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !9
  %33 = tail call i32 @_tx_ipsr_get()
  %34 = zext i32 %33 to i64
  %35 = or i64 %32, %34
  %36 = icmp ult i64 %35, 4042322160
  %brmerge = select i1 %36, i1 true, i1 %.not26
  %37 = select i1 %36, i1 true, i1 %.not26
  %.mux = select i1 %37, i32 19, i32 0
  br i1 %brmerge, label %.thread, label %39

38:                                               ; preds = %25
  br i1 %.not26, label %.thread, label %39

39:                                               ; preds = %31, %38
  %40 = tail call i32 @_tx_byte_pool_create(ptr noundef nonnull %0, ptr noundef %1, ptr noundef nonnull %2, i64 noundef %3) #3
  br label %.thread

.thread:                                          ; preds = %31, %23, %21, %._crit_edge, %5, %39, %38
  %.2 = phi i32 [ %40, %39 ], [ 19, %38 ], [ 5, %23 ], [ 3, %21 ], [ 2, %._crit_edge ], [ 2, %5 ], [ %.mux, %31 ]
  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_byte_pool_create(ptr noundef, ptr 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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass