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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @_tx_queue_flush(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  store ptr null, ptr %4, align 8, !tbaa !5
  %7 = call i32 @__disable_interrupts()
  store i32 %7, ptr %3, align 4, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %8, i32 0, i32 4
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %48

12:                                               ; preds = %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %13, i32 0, i32 4
  store i32 0, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %15, i32 0, i32 3
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %18, i32 0, i32 5
  store i32 %17, ptr %19, align 4, !tbaa !15
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %20, i32 0, i32 6
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %23, i32 0, i32 8
  store ptr %22, ptr %24, align 8, !tbaa !17
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %25, i32 0, i32 6
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %28, i32 0, i32 9
  store ptr %27, ptr %29, align 8, !tbaa !18
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %30, i32 0, i32 11
  %32 = load i32, ptr %31, align 8, !tbaa !19
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %47

34:                                               ; preds = %12
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %35, i32 0, i32 10
  %37 = load ptr, ptr %36, align 8, !tbaa !20
  store ptr %37, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %38, i32 0, i32 11
  %40 = load i32, ptr %39, align 8, !tbaa !19
  store i32 %40, ptr %5, align 4, !tbaa !9
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %41, i32 0, i32 10
  store ptr null, ptr %42, align 8, !tbaa !20
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %43, i32 0, i32 11
  store i32 0, ptr %44, align 8, !tbaa !19
  %45 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %46 = add i32 %45, 1
  store volatile i32 %46, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %34, %12
  br label %48

48:                                               ; preds = %47, %1
  %49 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %49)
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %52, label %84

52:                                               ; preds = %48
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %53, ptr %6, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %64, %52
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = icmp ne i64 %56, 0
  br i1 %57, label %58, label %79

58:                                               ; preds = %54
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = add i32 %59, -1
  store i32 %60, ptr %5, align 4, !tbaa !9
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = icmp eq ptr %61, null
  br i1 %62, label %63, label %64

63:                                               ; preds = %58
  br label %79

64:                                               ; preds = %58
  %65 = call i32 @__disable_interrupts()
  store i32 %65, ptr %3, align 4, !tbaa !9
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %66, i32 0, i32 20
  store ptr null, ptr %67, align 8, !tbaa !21
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %68, i32 0, i32 27
  store i32 0, ptr %69, align 4, !tbaa !24
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %70, i32 0, i32 22
  %72 = load ptr, ptr %71, align 8, !tbaa !25
  store ptr %72, ptr %6, align 8, !tbaa !5
  %73 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %74 = add i32 %73, 1
  store volatile i32 %74, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %75 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %75)
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %76, i32 0, i32 23
  %78 = load ptr, ptr %77, align 8, !tbaa !26
  call void @_tx_thread_system_resume(ptr noundef %78)
  br label %54, !llvm.loop !27

79:                                               ; preds = %63, %54
  %80 = call i32 @__disable_interrupts()
  store i32 %80, ptr %3, align 4, !tbaa !9
  %81 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %82 = add i32 %81, -1
  store volatile i32 %82, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %83 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %83)
  call void @_tx_thread_system_preempt_check()
  br label %84

84:                                               ; preds = %79, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 0
}

; 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_resume(ptr noundef) #3

declare void @_tx_thread_system_preempt_check() #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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"TX_QUEUE_STRUCT", !13, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !10, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !10, i64 20}
!15 = !{!12, !10, i64 28}
!16 = !{!12, !6, i64 32}
!17 = !{!12, !6, i64 48}
!18 = !{!12, !6, i64 56}
!19 = !{!12, !10, i64 72}
!20 = !{!12, !6, i64 64}
!21 = !{!22, !6, i64 192}
!22 = !{!"TX_THREAD_STRUCT", !13, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !6, i64 112, !6, i64 120, !13, i64 128, !23, i64 136, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !13, i64 224, !6, i64 232, !10, i64 240, !10, i64 244, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !10, i64 280, !10, i64 284, !10, i64 288, !10, i64 292, !6, i64 296, !6, i64 304, !6, i64 312, !13, i64 320}
!23 = !{!"TX_TIMER_INTERNAL_STRUCT", !13, i64 0, !13, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!24 = !{!22, !10, i64 244}
!25 = !{!22, !6, i64 208}
!26 = !{!22, !6, i64 216}
!27 = distinct !{!27, !28}
!28 = !{!"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"

@_tx_thread_preempt_disable = external global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @_tx_queue_flush(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @__disable_interrupts()
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.thread, label %5

5:                                                ; preds = %1
  store i32 0, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %7, ptr %8, align 4, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %10, ptr %11, align 8, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %10, ptr %12, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %0, i64 72
  %14 = load i32, ptr %13, align 8, !tbaa !17
  %.not27 = icmp eq i32 %14, 0
  br i1 %.not27, label %.thread, label %15

.thread:                                          ; preds = %5, %1
  tail call void @__restore_interrupt(i32 noundef %2)
  br label %35

15:                                               ; preds = %5
  %16 = getelementptr inbounds i8, ptr %0, i64 64
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  store ptr null, ptr %16, align 8, !tbaa !18
  store i32 0, ptr %13, align 8, !tbaa !17
  %18 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !19
  %19 = add i32 %18, 1
  store volatile i32 %19, ptr @_tx_thread_preempt_disable, align 4, !tbaa !19
  tail call void @__restore_interrupt(i32 noundef %2)
  %20 = icmp eq ptr %17, null
  br i1 %20, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %.lr.ph
  %.034 = phi ptr [ %26, %.lr.ph ], [ %17, %15 ]
  %.133 = phi i32 [ %21, %.lr.ph ], [ %14, %15 ]
  %21 = add i32 %.133, -1
  %22 = tail call i32 @__disable_interrupts()
  %23 = getelementptr inbounds i8, ptr %.034, i64 192
  store ptr null, ptr %23, align 8, !tbaa !20
  %24 = getelementptr inbounds i8, ptr %.034, i64 244
  store i32 0, ptr %24, align 4, !tbaa !23
  %25 = getelementptr inbounds i8, ptr %.034, i64 208
  %26 = load ptr, ptr %25, align 8, !tbaa !24
  %27 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !19
  %28 = add i32 %27, 1
  store volatile i32 %28, ptr @_tx_thread_preempt_disable, align 4, !tbaa !19
  tail call void @__restore_interrupt(i32 noundef %22)
  %29 = getelementptr inbounds i8, ptr %26, i64 216
  %30 = load ptr, ptr %29, align 8, !tbaa !25
  tail call void @_tx_thread_system_resume(ptr noundef %30) #3
  %.not29 = icmp eq i32 %21, 0
  %31 = icmp eq ptr %26, null
  %or.cond = select i1 %.not29, i1 true, i1 %31
  br i1 %or.cond, label %._crit_edge, label %.lr.ph, !llvm.loop !26

._crit_edge:                                      ; preds = %.lr.ph, %15
  %32 = tail call i32 @__disable_interrupts()
  %33 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !19
  %34 = add i32 %33, -1
  store volatile i32 %34, ptr @_tx_thread_preempt_disable, align 4, !tbaa !19
  tail call void @__restore_interrupt(i32 noundef %32)
  tail call void @_tx_thread_system_preempt_check() #3
  br label %35

35:                                               ; preds = %.thread, %._crit_edge
  ret i32 0
}

; 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_resume(ptr noundef) local_unnamed_addr #2

declare void @_tx_thread_system_preempt_check() 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, !11, i64 24}
!6 = !{!"TX_QUEUE_STRUCT", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !11, i64 72, !10, i64 80, !10, i64 88, !10, i64 96}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 20}
!13 = !{!6, !11, i64 28}
!14 = !{!6, !10, i64 32}
!15 = !{!6, !10, i64 48}
!16 = !{!6, !10, i64 56}
!17 = !{!6, !11, i64 72}
!18 = !{!6, !10, i64 64}
!19 = !{!11, !11, i64 0}
!20 = !{!21, !10, i64 192}
!21 = !{!"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, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !10, i64 112, !10, i64 120, !7, i64 128, !22, i64 136, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !7, i64 224, !10, i64 232, !11, i64 240, !11, i64 244, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !11, i64 280, !11, i64 284, !11, i64 288, !11, i64 292, !10, i64 296, !10, i64 304, !10, i64 312, !7, i64 320}
!22 = !{!"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}
!23 = !{!21, !11, i64 244}
!24 = !{!21, !10, i64 208}
!25 = !{!21, !10, i64 216}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass