; LLVM IR from mlcommons/tiny :: benchmark/interface/Middlewares/ST/threadx/common/src/tx_thread_stack_analyze._44aa4f8c (analyze)

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

; Function Attrs: nounwind uwtable
define dso_local void @_tx_thread_stack_analyze(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 ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = call i32 @__disable_interrupts()
  store i32 %8, ptr %3, align 4, !tbaa !9
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %95

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = icmp eq i64 %14, 1414025796
  br i1 %15, label %16, label %94

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

22:                                               ; preds = %16
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %23, i32 0, i32 37
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %92

28:                                               ; preds = %22
  %29 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %29)
  br label %30

30:                                               ; preds = %51, %28
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = ptrtoint ptr %31 to i64
  %34 = ptrtoint ptr %32 to i64
  %35 = sub i64 %33, %34
  %36 = sdiv exact i64 %35, 8
  %37 = udiv i64 %36, 2
  store i64 %37, ptr %7, align 8, !tbaa !17
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i64, ptr %7, align 8, !tbaa !17
  %40 = trunc i64 %39 to i32
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds i64, ptr %38, i64 %41
  store ptr %42, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i64, ptr %43, align 8, !tbaa !17
  %45 = icmp ne i64 %44, 4025479151
  br i1 %45, label %46, label %48

46:                                               ; preds = %30
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %47, ptr %6, align 8, !tbaa !5
  br label %50

48:                                               ; preds = %30
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %49, ptr %5, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %48, %46
  br label %51

51:                                               ; preds = %50
  %52 = load i64, ptr %7, align 8, !tbaa !17
  %53 = icmp ugt i64 %52, 1
  br i1 %53, label %30, label %54, !llvm.loop !18

54:                                               ; preds = %51
  br label %55

55:                                               ; preds = %59, %54
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i64, ptr %56, align 8, !tbaa !17
  %58 = icmp eq i64 %57, 4025479151
  br i1 %58, label %59, label %62

59:                                               ; preds = %55
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds i64, ptr %60, i64 1
  store ptr %61, ptr %4, align 8, !tbaa !5
  br label %55, !llvm.loop !20

62:                                               ; preds = %55
  %63 = call i32 @__disable_interrupts()
  store i32 %63, ptr %3, align 4, !tbaa !9
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %64, i32 0, i32 0
  %66 = load i64, ptr %65, align 8, !tbaa !11
  %67 = icmp eq i64 %66, 1414025796
  br i1 %67, label %68, label %91

68:                                               ; preds = %62
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !15
  %73 = icmp ugt ptr %69, %72
  br i1 %73, label %74, label %90

74:                                               ; preds = %68
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %76, i32 0, i32 37
  %78 = load ptr, ptr %77, align 8, !tbaa !16
  %79 = icmp ult ptr %75, %78
  br i1 %79, label %80, label %89

80:                                               ; preds = %74
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load i64, ptr %81, align 8, !tbaa !17
  %83 = icmp ne i64 %82, 4025479151
  br i1 %83, label %84, label %88

84:                                               ; preds = %80
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.TX_THREAD_STRUCT, ptr %86, i32 0, i32 37
  store ptr %85, ptr %87, align 8, !tbaa !16
  br label %88

88:                                               ; preds = %84, %80
  br label %89

89:                                               ; preds = %88, %74
  br label %90

90:                                               ; preds = %89, %68
  br label %91

91:                                               ; preds = %90, %62
  br label %92

92:                                               ; preds = %91, %22
  br label %93

93:                                               ; preds = %92, %16
  br label %94

94:                                               ; preds = %93, %11
  br label %95

95:                                               ; preds = %94, %1
  %96 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %96)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  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

; 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 = { 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, !13, i64 0}
!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 24}
!16 = !{!12, !6, i64 304}
!17 = !{!13, !13, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

; Function Attrs: nounwind uwtable
define dso_local void @_tx_thread_stack_analyze(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @__disable_interrupts()
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %37, label %3

3:                                                ; preds = %1
  %4 = load i64, ptr %0, align 8, !tbaa !5
  %5 = icmp eq i64 %4, 1414025796
  br i1 %5, label %6, label %37

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %.not32 = icmp eq ptr %8, null
  br i1 %.not32, label %37, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 304
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %.not33 = icmp eq ptr %11, null
  br i1 %.not33, label %37, label %12

12:                                               ; preds = %9
  tail call void @__restore_interrupt(i32 noundef %2)
  br label %13

13:                                               ; preds = %13, %12
  %.026 = phi ptr [ %8, %12 ], [ %..026, %13 ]
  %.025 = phi ptr [ %11, %12 ], [ %.025., %13 ]
  %14 = ptrtoint ptr %.025 to i64
  %15 = ptrtoint ptr %.026 to i64
  %16 = sub i64 %14, %15
  %17 = ashr exact i64 %16, 3
  %18 = lshr i64 %17, 1
  %19 = and i64 %18, 4294967295
  %20 = getelementptr inbounds i64, ptr %.026, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %.not34 = icmp eq i64 %21, 4025479151
  %..026 = select i1 %.not34, ptr %20, ptr %.026
  %.025. = select i1 %.not34, ptr %.025, ptr %20
  %22 = icmp ugt i64 %17, 3
  br i1 %22, label %13, label %.preheader, !llvm.loop !16

.preheader:                                       ; preds = %13
  br i1 %.not34, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.02837 = phi ptr [ %23, %.lr.ph ], [ %20, %.preheader ]
  %23 = getelementptr inbounds i8, ptr %.02837, i64 8
  %.pr = load i64, ptr %23, align 8, !tbaa !15
  %24 = icmp eq i64 %.pr, 4025479151
  br i1 %24, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.028.lcssa = phi ptr [ %20, %.preheader ], [ %23, %.lr.ph ]
  %25 = tail call i32 @__disable_interrupts()
  %26 = load i64, ptr %0, align 8, !tbaa !5
  %27 = icmp eq i64 %26, 1414025796
  br i1 %27, label %28, label %37

28:                                               ; preds = %._crit_edge
  %29 = load ptr, ptr %7, align 8, !tbaa !13
  %30 = icmp ugt ptr %.028.lcssa, %29
  br i1 %30, label %31, label %37

31:                                               ; preds = %28
  %32 = load ptr, ptr %10, align 8, !tbaa !14
  %33 = icmp ult ptr %.028.lcssa, %32
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load i64, ptr %.028.lcssa, align 8, !tbaa !15
  %.not35 = icmp eq i64 %35, 4025479151
  br i1 %.not35, label %37, label %36

36:                                               ; preds = %34
  store ptr %.028.lcssa, ptr %10, align 8, !tbaa !14
  br label %37

37:                                               ; preds = %3, %9, %28, %34, %36, %31, %._crit_edge, %6, %1
  %.0 = phi i32 [ %25, %36 ], [ %25, %34 ], [ %25, %31 ], [ %25, %28 ], [ %25, %._crit_edge ], [ %2, %9 ], [ %2, %6 ], [ %2, %3 ], [ %2, %1 ]
  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

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

!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, !7, i64 0}
!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, !10, i64 24}
!14 = !{!6, !10, i64 304}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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