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

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

@_tx_thread_preempt_disable = external global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @_tx_queue_cleanup(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %10 = call i32 @__disable_interrupts()
  store i32 %10, ptr %5, align 4, !tbaa !11
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %11, i32 0, i32 20
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = icmp eq ptr %13, @_tx_queue_cleanup
  br i1 %14, label %15, label %102

15:                                               ; preds = %2
  %16 = load i64, ptr %4, align 8, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %17, i32 0, i32 39
  %19 = load i64, ptr %18, align 8, !tbaa !16
  %20 = icmp eq i64 %16, %19
  br i1 %20, label %21, label %101

21:                                               ; preds = %15
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %22, i32 0, i32 21
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  store ptr %24, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %100

27:                                               ; preds = %21
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !18
  %31 = icmp eq i64 %30, 1364542805
  br i1 %31, label %32, label %99

32:                                               ; preds = %27
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %33, i32 0, i32 11
  %35 = load i32, ptr %34, align 8, !tbaa !20
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %98

37:                                               ; preds = %32
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %38, i32 0, i32 20
  store ptr null, ptr %39, align 8, !tbaa !13
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %40, i32 0, i32 11
  %42 = load i32, ptr %41, align 8, !tbaa !20
  %43 = add i32 %42, -1
  store i32 %43, ptr %41, align 8, !tbaa !20
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %44, i32 0, i32 11
  %46 = load i32, ptr %45, align 8, !tbaa !20
  store i32 %46, ptr %7, align 4, !tbaa !11
  %47 = load i32, ptr %7, align 4, !tbaa !11
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %52

49:                                               ; preds = %37
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %50, i32 0, i32 10
  store ptr null, ptr %51, align 8, !tbaa !21
  br label %75

52:                                               ; preds = %37
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %53, i32 0, i32 22
  %55 = load ptr, ptr %54, align 8, !tbaa !22
  store ptr %55, ptr %8, align 8, !tbaa !5
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %56, i32 0, i32 23
  %58 = load ptr, ptr %57, align 8, !tbaa !23
  store ptr %58, ptr %9, align 8, !tbaa !5
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %60, i32 0, i32 23
  store ptr %59, ptr %61, align 8, !tbaa !23
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %63, i32 0, i32 22
  store ptr %62, ptr %64, align 8, !tbaa !22
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %65, i32 0, i32 10
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = icmp eq ptr %67, %68
  br i1 %69, label %70, label %74

70:                                               ; preds = %52
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %72, i32 0, i32 10
  store ptr %71, ptr %73, align 8, !tbaa !21
  br label %74

74:                                               ; preds = %70, %52
  br label %75

75:                                               ; preds = %74, %49
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %76, i32 0, i32 12
  %78 = load i32, ptr %77, align 4, !tbaa !24
  %79 = icmp eq i32 %78, 5
  br i1 %79, label %80, label %97

80:                                               ; preds = %75
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.TX_QUEUE_STRUCT, ptr %81, i32 0, i32 4
  %83 = load i32, ptr %82, align 8, !tbaa !25
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %88

85:                                               ; preds = %80
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %86, i32 0, i32 27
  store i32 11, ptr %87, align 4, !tbaa !26
  br label %91

88:                                               ; preds = %80
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %89, i32 0, i32 27
  store i32 10, ptr %90, align 4, !tbaa !26
  br label %91

91:                                               ; preds = %88, %85
  %92 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %93 = add i32 %92, 1
  store volatile i32 %93, ptr @_tx_thread_preempt_disable, align 4, !tbaa !11
  %94 = load i32, ptr %5, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %94)
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_tx_thread_system_resume(ptr noundef %95)
  %96 = call i32 @__disable_interrupts()
  store i32 %96, ptr %5, align 4, !tbaa !11
  br label %97

97:                                               ; preds = %91, %75
  br label %98

98:                                               ; preds = %97, %32
  br label %99

99:                                               ; preds = %98, %27
  br label %100

100:                                              ; preds = %99, %21
  br label %101

101:                                              ; preds = %100, %15
  br label %102

102:                                              ; preds = %101, %2
  %103 = load i32, ptr %5, align 4, !tbaa !11
  call void @__restore_interrupt(i32 noundef %103)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret void
}

; 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

; 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 192}
!14 = !{!"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, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104, !6, i64 112, !6, i64 120, !10, i64 128, !15, i64 136, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !10, i64 224, !6, i64 232, !12, i64 240, !12, i64 244, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !12, i64 280, !12, i64 284, !12, i64 288, !12, i64 292, !6, i64 296, !6, i64 304, !6, i64 312, !10, i64 320}
!15 = !{!"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}
!16 = !{!14, !10, i64 320}
!17 = !{!14, !6, i64 200}
!18 = !{!19, !10, i64 0}
!19 = !{!"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}
!20 = !{!19, !12, i64 72}
!21 = !{!19, !6, i64 64}
!22 = !{!14, !6, i64 208}
!23 = !{!14, !6, i64 216}
!24 = !{!14, !12, i64 92}
!25 = !{!19, !12, i64 24}
!26 = !{!14, !12, i64 244}


; 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 void @_tx_queue_cleanup(ptr noundef %0, i64 noundef %1) #0 {
  %3 = tail call i32 @__disable_interrupts()
  %4 = getelementptr inbounds i8, ptr %0, i64 192
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = icmp eq ptr %5, @_tx_queue_cleanup
  br i1 %6, label %7, label %47

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 320
  %9 = load i64, ptr %8, align 8, !tbaa !13
  %10 = icmp eq i64 %9, %1
  br i1 %10, label %11, label %47

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 200
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %47, label %14

14:                                               ; preds = %11
  %15 = load i64, ptr %13, align 8, !tbaa !15
  %16 = icmp eq i64 %15, 1364542805
  br i1 %16, label %17, label %47

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %13, i64 72
  %19 = load i32, ptr %18, align 8, !tbaa !17
  %.not29 = icmp eq i32 %19, 0
  br i1 %.not29, label %47, label %20

20:                                               ; preds = %17
  store ptr null, ptr %4, align 8, !tbaa !5
  %21 = add i32 %19, -1
  store i32 %21, ptr %18, align 8, !tbaa !17
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %20
  %24 = getelementptr inbounds i8, ptr %13, i64 64
  store ptr null, ptr %24, align 8, !tbaa !18
  br label %36

25:                                               ; preds = %20
  %26 = getelementptr inbounds i8, ptr %0, i64 208
  %27 = load ptr, ptr %26, align 8, !tbaa !19
  %28 = getelementptr inbounds i8, ptr %0, i64 216
  %29 = load ptr, ptr %28, align 8, !tbaa !20
  %30 = getelementptr inbounds i8, ptr %27, i64 216
  store ptr %29, ptr %30, align 8, !tbaa !20
  %31 = getelementptr inbounds i8, ptr %29, i64 208
  store ptr %27, ptr %31, align 8, !tbaa !19
  %32 = getelementptr inbounds i8, ptr %13, i64 64
  %33 = load ptr, ptr %32, align 8, !tbaa !18
  %34 = icmp eq ptr %33, %0
  br i1 %34, label %35, label %36

35:                                               ; preds = %25
  store ptr %27, ptr %32, align 8, !tbaa !18
  br label %36

36:                                               ; preds = %25, %35, %23
  %37 = getelementptr inbounds i8, ptr %0, i64 92
  %38 = load i32, ptr %37, align 4, !tbaa !21
  %39 = icmp eq i32 %38, 5
  br i1 %39, label %40, label %47

40:                                               ; preds = %36
  %41 = getelementptr inbounds i8, ptr %13, i64 24
  %42 = load i32, ptr %41, align 8, !tbaa !22
  %.not30 = icmp eq i32 %42, 0
  %spec.select = select i1 %.not30, i32 10, i32 11
  %43 = getelementptr inbounds i8, ptr %0, i64 244
  store i32 %spec.select, ptr %43, align 4
  %44 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !23
  %45 = add i32 %44, 1
  store volatile i32 %45, ptr @_tx_thread_preempt_disable, align 4, !tbaa !23
  tail call void @__restore_interrupt(i32 noundef %3)
  tail call void @_tx_thread_system_resume(ptr noundef nonnull %0) #3
  %46 = tail call i32 @__disable_interrupts()
  br label %47

47:                                               ; preds = %7, %14, %36, %40, %17, %11, %2
  %.0 = phi i32 [ %46, %40 ], [ %3, %36 ], [ %3, %17 ], [ %3, %14 ], [ %3, %11 ], [ %3, %7 ], [ %3, %2 ]
  tail call void @__restore_interrupt(i32 noundef %.0)
  ret void
}

; 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

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, !10, i64 192}
!6 = !{!"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, !12, 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}
!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 = !{!"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}
!13 = !{!6, !7, i64 320}
!14 = !{!6, !10, i64 200}
!15 = !{!16, !7, i64 0}
!16 = !{!"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}
!17 = !{!16, !11, i64 72}
!18 = !{!16, !10, i64 64}
!19 = !{!6, !10, i64 208}
!20 = !{!6, !10, i64 216}
!21 = !{!6, !11, i64 92}
!22 = !{!16, !11, i64 24}
!23 = !{!11, !11, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass,TailCallElimPass