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

; 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_preempt_disable = external global i32, align 4
@_tx_thread_mutex_release = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @_tx_thread_terminate(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, 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 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  %8 = call i32 @__disable_interrupts()
  store i32 %8, ptr %3, align 4, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %9, i32 0, i32 19
  call void @_tx_timer_system_deactivate(ptr noundef %10)
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %11, i32 0, i32 12
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %15, label %17

15:                                               ; preds = %1
  %16 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %16)
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %96

17:                                               ; preds = %1
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %18, i32 0, i32 12
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = icmp ne i32 %20, 1
  br i1 %21, label %22, label %93

22:                                               ; preds = %17
  %23 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %24 = add i32 %23, 1
  store volatile i32 %24, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %25, i32 0, i32 38
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  store ptr %27, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %28, i32 0, i32 12
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %51

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

45:                                               ; preds = %32
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  call void %46(ptr noundef %47, i32 noundef 1)
  br label %48

48:                                               ; preds = %45, %32
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_tx_thread_system_suspend(ptr noundef %49)
  %50 = call i32 @__disable_interrupts()
  store i32 %50, ptr %3, align 4, !tbaa !9
  br label %81

51:                                               ; preds = %22
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %52, i32 0, i32 12
  store i32 2, ptr %53, align 4, !tbaa !11
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %54, i32 0, i32 14
  store i32 1, ptr %55, align 4, !tbaa !16
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %56, i32 0, i32 20
  %58 = load ptr, ptr %57, align 8, !tbaa !18
  store ptr %58, ptr %4, align 8, !tbaa !5
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %59, i32 0, i32 39
  %61 = load i64, ptr %60, align 8, !tbaa !19
  store i64 %61, ptr %7, align 8, !tbaa !20
  %62 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %62)
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %69

65:                                               ; preds = %51
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = load i64, ptr %7, align 8, !tbaa !20
  call void %66(ptr noundef %67, i64 noundef %68)
  br label %69

69:                                               ; preds = %65, %51
  %70 = call i32 @__disable_interrupts()
  store i32 %70, ptr %3, align 4, !tbaa !9
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %71, i32 0, i32 14
  store i32 0, ptr %72, align 4, !tbaa !16
  %73 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %73)
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %79

76:                                               ; preds = %69
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  call void %77(ptr noundef %78, i32 noundef 1)
  br label %79

79:                                               ; preds = %76, %69
  %80 = call i32 @__disable_interrupts()
  store i32 %80, ptr %3, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %79, %48
  %82 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %82)
  %83 = load ptr, ptr @_tx_thread_mutex_release, align 8, !tbaa !5
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %88

85:                                               ; preds = %81
  %86 = load ptr, ptr @_tx_thread_mutex_release, align 8, !tbaa !5
  %87 = load ptr, ptr %2, align 8, !tbaa !5
  call void %86(ptr noundef %87)
  br label %88

88:                                               ; preds = %85, %81
  %89 = call i32 @__disable_interrupts()
  store i32 %89, ptr %3, align 4, !tbaa !9
  %90 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %91 = add i32 %90, -1
  store volatile i32 %91, ptr @_tx_thread_preempt_disable, align 4, !tbaa !9
  %92 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %92)
  br label %95

93:                                               ; preds = %17
  %94 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %94)
  br label %95

95:                                               ; preds = %93, %88
  br label %96

96:                                               ; preds = %95, %15
  call void @_tx_thread_system_preempt_check()
  %97 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  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 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %97
}

; 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

declare void @_tx_timer_system_deactivate(ptr noundef) #3

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

declare void @_tx_thread_system_suspend(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 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 = !{!12, !6, i64 312}
!16 = !{!12, !10, i64 100}
!17 = !{!12, !13, i64 136}
!18 = !{!12, !6, i64 192}
!19 = !{!12, !13, i64 320}
!20 = !{!13, !13, i64 0}


; 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
@_tx_thread_mutex_release = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @_tx_thread_terminate(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @__disable_interrupts()
  %3 = getelementptr inbounds i8, ptr %0, i64 136
  tail call void @_tx_timer_system_deactivate(ptr noundef nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 92
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.off = add i32 %5, -1
  %switch = icmp ult i32 %.off, 2
  br i1 %switch, label %35, label %6

6:                                                ; preds = %1
  %7 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !13
  %8 = add i32 %7, 1
  store volatile i32 %8, ptr @_tx_thread_preempt_disable, align 4, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 312
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %11 = icmp eq i32 %5, 0
  store i32 2, ptr %4, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 100
  store i32 1, ptr %12, align 4, !tbaa !15
  br i1 %11, label %13, label %18

13:                                               ; preds = %6
  store i64 0, ptr %3, align 8, !tbaa !16
  %14 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !13
  %15 = add i32 %14, 1
  store volatile i32 %15, ptr @_tx_thread_preempt_disable, align 4, !tbaa !13
  tail call void @__restore_interrupt(i32 noundef %2)
  %.not39 = icmp eq ptr %10, null
  br i1 %.not39, label %17, label %16

16:                                               ; preds = %13
  tail call void %10(ptr noundef nonnull %0, i32 noundef 1) #3
  br label %17

17:                                               ; preds = %16, %13
  tail call void @_tx_thread_system_suspend(ptr noundef nonnull %0) #3
  br label %27

18:                                               ; preds = %6
  %19 = getelementptr inbounds i8, ptr %0, i64 192
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %0, i64 320
  %22 = load i64, ptr %21, align 8, !tbaa !18
  tail call void @__restore_interrupt(i32 noundef %2)
  %.not37 = icmp eq ptr %20, null
  br i1 %.not37, label %24, label %23

23:                                               ; preds = %18
  tail call void %20(ptr noundef nonnull %0, i64 noundef %22) #3
  br label %24

24:                                               ; preds = %23, %18
  %25 = tail call i32 @__disable_interrupts()
  store i32 0, ptr %12, align 4, !tbaa !15
  tail call void @__restore_interrupt(i32 noundef %25)
  %.not38 = icmp eq ptr %10, null
  br i1 %.not38, label %27, label %26

26:                                               ; preds = %24
  tail call void %10(ptr noundef nonnull %0, i32 noundef 1) #3
  br label %27

27:                                               ; preds = %24, %26, %17
  %28 = tail call i32 @__disable_interrupts()
  tail call void @__restore_interrupt(i32 noundef %28)
  %29 = load ptr, ptr @_tx_thread_mutex_release, align 8, !tbaa !19
  %.not40 = icmp eq ptr %29, null
  br i1 %.not40, label %31, label %30

30:                                               ; preds = %27
  tail call void %29(ptr noundef nonnull %0) #3
  br label %31

31:                                               ; preds = %30, %27
  %32 = tail call i32 @__disable_interrupts()
  %33 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !13
  %34 = add i32 %33, -1
  store volatile i32 %34, ptr @_tx_thread_preempt_disable, align 4, !tbaa !13
  br label %35

35:                                               ; preds = %1, %31
  %.sink = phi i32 [ %32, %31 ], [ %2, %1 ]
  tail call void @__restore_interrupt(i32 noundef %.sink)
  tail call void @_tx_thread_system_preempt_check() #3
  ret i32 0
}

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

declare void @_tx_timer_system_deactivate(ptr noundef) local_unnamed_addr #2

; 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

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 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 = !{!11, !11, i64 0}
!14 = !{!6, !10, i64 312}
!15 = !{!6, !11, i64 100}
!16 = !{!6, !7, i64 136}
!17 = !{!6, !10, i64 192}
!18 = !{!6, !7, i64 320}
!19 = !{!10, !10, i64 0}


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