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

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

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

12:                                               ; preds = %0
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  call void %13(ptr noundef %14, i32 noundef 0)
  br label %15

15:                                               ; preds = %12, %0
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %16, i32 0, i32 17
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %19, i32 0, i32 18
  %21 = load i64, ptr %20, align 8, !tbaa !16
  call void %18(i64 noundef %21)
  %22 = load ptr, ptr @_tx_thread_mutex_release, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %27

24:                                               ; preds = %15
  %25 = load ptr, ptr @_tx_thread_mutex_release, align 8, !tbaa !5
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  call void %25(ptr noundef %26)
  br label %27

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

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

47:                                               ; preds = %44, %27
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_tx_thread_system_suspend(ptr noundef %48)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #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_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, !6, i64 312}
!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 120}
!16 = !{!12, !13, i64 128}
!17 = !{!12, !10, i64 92}
!18 = !{!12, !10, i64 100}
!19 = !{!12, !13, i64 136}


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

; Function Attrs: nounwind uwtable
define dso_local void @_tx_thread_shell_entry() local_unnamed_addr #0 {
  %1 = load ptr, ptr @_tx_thread_current_ptr, align 8, !tbaa !5
  %2 = tail call i32 @__disable_interrupts()
  %3 = getelementptr inbounds i8, ptr %1, i64 312
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  tail call void @__restore_interrupt(i32 noundef %2)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %6, label %5

5:                                                ; preds = %0
  tail call void %4(ptr noundef nonnull %1, i32 noundef 0) #3
  br label %6

6:                                                ; preds = %5, %0
  %7 = getelementptr inbounds i8, ptr %1, i64 120
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %1, i64 128
  %10 = load i64, ptr %9, align 8, !tbaa !15
  tail call void %8(i64 noundef %10) #3
  %11 = load ptr, ptr @_tx_thread_mutex_release, align 8, !tbaa !5
  %.not18 = icmp eq ptr %11, null
  br i1 %.not18, label %13, label %12

12:                                               ; preds = %6
  tail call void %11(ptr noundef nonnull %1) #3
  br label %13

13:                                               ; preds = %12, %6
  %14 = tail call i32 @__disable_interrupts()
  %15 = load ptr, ptr %3, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %1, i64 92
  store i32 1, ptr %16, align 4, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %1, i64 100
  store i32 1, ptr %17, align 4, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %1, i64 136
  store i64 0, ptr %18, align 8, !tbaa !18
  %19 = load volatile i32, ptr @_tx_thread_preempt_disable, align 4, !tbaa !19
  %20 = add i32 %19, 1
  store volatile i32 %20, ptr @_tx_thread_preempt_disable, align 4, !tbaa !19
  tail call void @__restore_interrupt(i32 noundef %14)
  %.not19 = icmp eq ptr %15, null
  br i1 %.not19, label %22, label %21

21:                                               ; preds = %13
  tail call void %15(ptr noundef nonnull %1, i32 noundef 1) #3
  br label %22

22:                                               ; preds = %21, %13
  tail call void @_tx_thread_system_suspend(ptr noundef nonnull %1) #3
  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_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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 312}
!10 = !{!"TX_THREAD_STRUCT", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 48, !11, 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, !11, i64 128, !13, i64 136, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !11, 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, !11, i64 320}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"TX_TIMER_INTERNAL_STRUCT", !11, i64 0, !11, i64 8, !6, i64 16, !11, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!14 = !{!10, !6, i64 120}
!15 = !{!10, !11, i64 128}
!16 = !{!10, !12, i64 92}
!17 = !{!10, !12, i64 100}
!18 = !{!10, !11, i64 136}
!19 = !{!12, !12, i64 0}


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