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

; 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 }

@_tx_thread_current_ptr = external global ptr, align 8
@_tx_thread_system_state = external global i64, align 8
@_tx_thread_preempt_disable = external global i32, align 4

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

14:                                               ; preds = %1
  store i32 0, ptr %6, align 4, !tbaa !9
  %15 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !15
  %16 = call i32 @_tx_ipsr_get()
  %17 = zext i32 %16 to i64
  %18 = or i64 %15, %17
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %30

20:                                               ; preds = %14
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = icmp eq ptr %21, %22
  br i1 %23, label %24, label %29

24:                                               ; preds = %20
  %25 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %24
  store i32 20, ptr %6, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %27, %24
  br label %29

29:                                               ; preds = %28, %20
  br label %30

30:                                               ; preds = %29, %14
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %45

33:                                               ; preds = %30
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %34, i32 0, i32 12
  store i32 3, ptr %35, align 4, !tbaa !11
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %36, i32 0, i32 14
  store i32 1, ptr %37, align 4, !tbaa !16
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %38, i32 0, i32 19
  %40 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %39, i32 0, i32 0
  store i64 0, ptr %40, align 8, !tbaa !17
  %41 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %42 = add i32 %41, 1
  store volatile i32 %42, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %43 = load i32, ptr %4, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %43)
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_tx_thread_system_suspend(ptr noundef %44)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %73

45:                                               ; preds = %30
  br label %70

46:                                               ; preds = %1
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %47, i32 0, i32 12
  %49 = load i32, ptr %48, align 4, !tbaa !11
  %50 = icmp eq i32 %49, 2
  br i1 %50, label %51, label %52

51:                                               ; preds = %46
  store i32 20, ptr %6, align 4, !tbaa !9
  br label %69

52:                                               ; preds = %46
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %53, i32 0, i32 12
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = icmp eq i32 %55, 1
  br i1 %56, label %57, label %58

57:                                               ; preds = %52
  store i32 20, ptr %6, align 4, !tbaa !9
  br label %68

58:                                               ; preds = %52
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %59, i32 0, i32 12
  %61 = load i32, ptr %60, align 4, !tbaa !11
  %62 = icmp eq i32 %61, 3
  br i1 %62, label %63, label %64

63:                                               ; preds = %58
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %67

64:                                               ; preds = %58
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %65, i32 0, i32 13
  store i32 1, ptr %66, align 8, !tbaa !18
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %64, %63
  br label %68

68:                                               ; preds = %67, %57
  br label %69

69:                                               ; preds = %68, %51
  br label %70

70:                                               ; preds = %69, %45
  %71 = load i32, ptr %4, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %71)
  %72 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %72, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %73

73:                                               ; preds = %70, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %74 = load i32, ptr %2, align 4
  ret i32 %74
}

; 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 i32 @_tx_ipsr_get() #2

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

declare void @_tx_thread_system_suspend(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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 92}
!12 = !{!"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, !14, 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}
!13 = !{!"long", !7, i64 0}
!14 = !{!"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}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !10, i64 100}
!17 = !{!12, !13, i64 136}
!18 = !{!12, !10, i64 96}


; 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_current_ptr = external local_unnamed_addr global ptr, align 8
@_tx_thread_system_state = external global i64, align 8
@_tx_thread_preempt_disable = external global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 21) i32 @_tx_thread_suspend(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @__disable_interrupts()
  %3 = getelementptr inbounds i8, ptr %0, i64 92
  %4 = load i32, ptr %3, align 4, !tbaa !5
  switch i32 %4, label %20 [
    i32 0, label %5
    i32 2, label %22
    i32 1, label %22
    i32 3, label %19
  ]

5:                                                ; preds = %1
  %6 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !13
  %7 = load volatile i64, ptr @_tx_thread_system_state, align 8, !tbaa !14
  %8 = tail call i32 @_tx_ipsr_get()
  %9 = zext i32 %8 to i64
  %10 = or i64 %7, %9
  %11 = icmp eq i64 %10, 0
  %12 = icmp eq ptr %6, %0
  %or.cond = select i1 %11, i1 %12, i1 false
  br i1 %or.cond, label %13, label %.thread

13:                                               ; preds = %5
  %14 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !15
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %.thread, label %22

.thread:                                          ; preds = %5, %13
  store i32 3, ptr %3, align 4, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 100
  store i32 1, ptr %15, align 4, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %0, i64 136
  store i64 0, ptr %16, align 8, !tbaa !17
  %17 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !15
  %18 = add i32 %17, 1
  store volatile i32 %18, ptr @_tx_thread_preempt_disable, align 4, !tbaa !15
  tail call void @__restore_interrupt(i32 noundef %2)
  tail call void @_tx_thread_system_suspend(ptr noundef nonnull %0) #3
  br label %23

19:                                               ; preds = %1
  br label %22

20:                                               ; preds = %1
  %21 = getelementptr inbounds i8, ptr %0, i64 96
  store i32 1, ptr %21, align 8, !tbaa !18
  br label %22

22:                                               ; preds = %1, %1, %19, %20, %13
  %.1 = phi i32 [ 20, %13 ], [ 0, %19 ], [ 0, %20 ], [ 20, %1 ], [ 20, %1 ]
  tail call void @__restore_interrupt(i32 noundef %2)
  br label %23

23:                                               ; preds = %22, %.thread
  %.015 = phi i32 [ 0, %.thread ], [ %.1, %22 ]
  ret i32 %.015
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @_tx_ipsr_get() 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_suspend(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, !11, i64 92}
!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 = !{!10, !10, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!6, !11, i64 100}
!17 = !{!6, !7, i64 136}
!18 = !{!6, !11, i64 96}


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