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

; 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_TIMER_STRUCT = type { i64, ptr, %struct.TX_TIMER_INTERNAL_STRUCT, ptr, ptr }
%struct.TX_TIMER_INTERNAL_STRUCT = type { i64, i64, ptr, i64, ptr, ptr, ptr }

@_tx_timer_list_start = external global ptr, align 8
@_tx_timer_list_end = external global ptr, align 8
@_tx_timer_current_ptr = external global ptr, align 8
@_tx_timer_expired_timer_ptr = external global ptr, align 8

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

18:                                               ; preds = %1
  store i32 0, ptr %9, align 4, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr @_tx_timer_list_start, align 8, !tbaa !5
  %21 = icmp uge ptr %19, %20
  br i1 %21, label %22, label %28

22:                                               ; preds = %18
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr @_tx_timer_list_end, align 8, !tbaa !5
  %25 = icmp ult ptr %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  store i32 1, ptr %9, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %26, %22
  br label %28

28:                                               ; preds = %27, %18
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %31, label %78

31:                                               ; preds = %28
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr @_tx_timer_current_ptr, align 8, !tbaa !5
  %34 = icmp uge ptr %32, %33
  br i1 %34, label %35, label %43

35:                                               ; preds = %31
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr @_tx_timer_current_ptr, align 8, !tbaa !5
  %38 = ptrtoint ptr %36 to i64
  %39 = ptrtoint ptr %37 to i64
  %40 = sub i64 %38, %39
  %41 = sdiv exact i64 %40, 8
  %42 = add i64 %41, 1
  store i64 %42, ptr %8, align 8, !tbaa !14
  br label %59

43:                                               ; preds = %31
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load ptr, ptr @_tx_timer_list_start, align 8, !tbaa !5
  %46 = ptrtoint ptr %44 to i64
  %47 = ptrtoint ptr %45 to i64
  %48 = sub i64 %46, %47
  %49 = sdiv exact i64 %48, 8
  store i64 %49, ptr %8, align 8, !tbaa !14
  %50 = load i64, ptr %8, align 8, !tbaa !14
  %51 = load ptr, ptr @_tx_timer_list_end, align 8, !tbaa !5
  %52 = load ptr, ptr @_tx_timer_current_ptr, align 8, !tbaa !5
  %53 = ptrtoint ptr %51 to i64
  %54 = ptrtoint ptr %52 to i64
  %55 = sub i64 %53, %54
  %56 = sdiv exact i64 %55, 8
  %57 = add i64 %56, 1
  %58 = add i64 %50, %57
  store i64 %58, ptr %8, align 8, !tbaa !14
  br label %59

59:                                               ; preds = %43, %35
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %60, i32 0, i32 0
  %62 = load i64, ptr %61, align 8, !tbaa !15
  %63 = icmp ugt i64 %62, 32
  br i1 %63, label %64, label %73

64:                                               ; preds = %59
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %65, i32 0, i32 0
  %67 = load i64, ptr %66, align 8, !tbaa !15
  %68 = sub i64 %67, 32
  %69 = load i64, ptr %8, align 8, !tbaa !14
  %70 = add i64 %68, %69
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %71, i32 0, i32 0
  store i64 %70, ptr %72, align 8, !tbaa !15
  br label %77

73:                                               ; preds = %59
  %74 = load i64, ptr %8, align 8, !tbaa !14
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %75, i32 0, i32 0
  store i64 %74, ptr %76, align 8, !tbaa !15
  br label %77

77:                                               ; preds = %73, %64
  br label %108

78:                                               ; preds = %28
  %79 = load ptr, ptr @_tx_timer_expired_timer_ptr, align 8, !tbaa !5
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = icmp ne ptr %79, %80
  br i1 %81, label %82, label %101

82:                                               ; preds = %78
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %83, i32 0, i32 0
  %85 = load i64, ptr %84, align 8, !tbaa !15
  %86 = icmp ugt i64 %85, 32
  br i1 %86, label %87, label %94

87:                                               ; preds = %82
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %88, i32 0, i32 0
  %90 = load i64, ptr %89, align 8, !tbaa !15
  %91 = sub i64 %90, 32
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %92, i32 0, i32 0
  store i64 %91, ptr %93, align 8, !tbaa !15
  br label %100

94:                                               ; preds = %82
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %95, i32 0, i32 1
  %97 = load i64, ptr %96, align 8, !tbaa !16
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %98, i32 0, i32 0
  store i64 %97, ptr %99, align 8, !tbaa !15
  br label %100

100:                                              ; preds = %94, %87
  br label %107

101:                                              ; preds = %78
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %102, i32 0, i32 1
  %104 = load i64, ptr %103, align 8, !tbaa !16
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %105, i32 0, i32 0
  store i64 %104, ptr %106, align 8, !tbaa !15
  br label %107

107:                                              ; preds = %101, %100
  br label %108

108:                                              ; preds = %107, %77
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %109, i32 0, i32 4
  %111 = load ptr, ptr %110, align 8, !tbaa !17
  store ptr %111, ptr %6, align 8, !tbaa !5
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = icmp eq ptr %112, %113
  br i1 %114, label %115, label %123

115:                                              ; preds = %108
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = load ptr, ptr %116, align 8, !tbaa !5
  %118 = load ptr, ptr %4, align 8, !tbaa !5
  %119 = icmp eq ptr %117, %118
  br i1 %119, label %120, label %122

120:                                              ; preds = %115
  %121 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %121, align 8, !tbaa !5
  br label %122

122:                                              ; preds = %120, %115
  br label %144

123:                                              ; preds = %108
  %124 = load ptr, ptr %4, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %124, i32 0, i32 5
  %126 = load ptr, ptr %125, align 8, !tbaa !18
  store ptr %126, ptr %7, align 8, !tbaa !5
  %127 = load ptr, ptr %7, align 8, !tbaa !5
  %128 = load ptr, ptr %6, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %128, i32 0, i32 5
  store ptr %127, ptr %129, align 8, !tbaa !18
  %130 = load ptr, ptr %6, align 8, !tbaa !5
  %131 = load ptr, ptr %7, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %131, i32 0, i32 4
  store ptr %130, ptr %132, align 8, !tbaa !17
  %133 = load ptr, ptr %5, align 8, !tbaa !5
  %134 = load ptr, ptr %133, align 8, !tbaa !5
  %135 = load ptr, ptr %4, align 8, !tbaa !5
  %136 = icmp eq ptr %134, %135
  br i1 %136, label %137, label %143

137:                                              ; preds = %123
  %138 = load ptr, ptr %5, align 8, !tbaa !5
  %139 = load ptr, ptr %6, align 8, !tbaa !5
  %140 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %139, i32 0, i32 6
  store ptr %138, ptr %140, align 8, !tbaa !11
  %141 = load ptr, ptr %6, align 8, !tbaa !5
  %142 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %141, ptr %142, align 8, !tbaa !5
  br label %143

143:                                              ; preds = %137, %123
  br label %144

144:                                              ; preds = %143, %122
  %145 = load ptr, ptr %4, align 8, !tbaa !5
  %146 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %145, i32 0, i32 6
  store ptr null, ptr %146, align 8, !tbaa !11
  br label %147

147:                                              ; preds = %144, %1
  %148 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %148)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  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 i32 0
}

; 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, !6, i64 48}
!12 = !{!"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}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 0}
!16 = !{!12, !13, i64 8}
!17 = !{!12, !6, i64 32}
!18 = !{!12, !6, i64 40}


; 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_timer_list_start = external local_unnamed_addr global ptr, align 8
@_tx_timer_list_end = external local_unnamed_addr global ptr, align 8
@_tx_timer_current_ptr = external local_unnamed_addr global ptr, align 8
@_tx_timer_expired_timer_ptr = external local_unnamed_addr global ptr, align 8

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

6:                                                ; preds = %1
  %7 = load ptr, ptr @_tx_timer_list_start, align 8, !tbaa !11
  %.not50 = icmp uge ptr %5, %7
  %8 = load ptr, ptr @_tx_timer_list_end, align 8
  %9 = icmp ult ptr %5, %8
  %or.cond = select i1 %.not50, i1 %9, i1 false
  br i1 %or.cond, label %.critedge, label %33

.critedge:                                        ; preds = %6
  %10 = load ptr, ptr @_tx_timer_current_ptr, align 8, !tbaa !11
  %.not52 = icmp ult ptr %5, %10
  %11 = ptrtoint ptr %5 to i64
  br i1 %.not52, label %17, label %12

12:                                               ; preds = %.critedge
  %13 = ptrtoint ptr %10 to i64
  %14 = sub i64 %11, %13
  %15 = ashr exact i64 %14, 3
  %16 = add nsw i64 %15, 1
  br label %27

17:                                               ; preds = %.critedge
  %18 = ptrtoint ptr %7 to i64
  %19 = sub i64 %11, %18
  %20 = ashr exact i64 %19, 3
  %21 = ptrtoint ptr %8 to i64
  %22 = ptrtoint ptr %10 to i64
  %23 = sub i64 %21, %22
  %24 = ashr exact i64 %23, 3
  %25 = add nsw i64 %20, 1
  %26 = add nsw i64 %25, %24
  br label %27

27:                                               ; preds = %17, %12
  %.042 = phi i64 [ %16, %12 ], [ %26, %17 ]
  %28 = load i64, ptr %2, align 8, !tbaa !12
  %29 = icmp ugt i64 %28, 32
  br i1 %29, label %30, label %46

30:                                               ; preds = %27
  %31 = add nsw i64 %.042, -32
  %32 = add i64 %31, %28
  br label %46

33:                                               ; preds = %6
  %34 = load ptr, ptr @_tx_timer_expired_timer_ptr, align 8, !tbaa !11
  %.not51 = icmp eq ptr %34, %2
  br i1 %.not51, label %43, label %35

35:                                               ; preds = %33
  %36 = load i64, ptr %2, align 8, !tbaa !12
  %37 = icmp ugt i64 %36, 32
  br i1 %37, label %38, label %40

38:                                               ; preds = %35
  %39 = add i64 %36, -32
  br label %46

40:                                               ; preds = %35
  %41 = getelementptr inbounds i8, ptr %0, i64 24
  %42 = load i64, ptr %41, align 8, !tbaa !13
  br label %46

43:                                               ; preds = %33
  %44 = getelementptr inbounds i8, ptr %0, i64 24
  %45 = load i64, ptr %44, align 8, !tbaa !13
  br label %46

46:                                               ; preds = %27, %43, %40, %38, %30
  %.sink = phi i64 [ %45, %43 ], [ %42, %40 ], [ %39, %38 ], [ %32, %30 ], [ %.042, %27 ]
  store i64 %.sink, ptr %2, align 8, !tbaa !12
  %47 = getelementptr inbounds i8, ptr %0, i64 48
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = icmp eq ptr %2, %48
  br i1 %49, label %50, label %53

50:                                               ; preds = %46
  %51 = load ptr, ptr %5, align 8, !tbaa !11
  %52 = icmp eq ptr %51, %2
  br i1 %52, label %.sink.split, label %62

53:                                               ; preds = %46
  %54 = getelementptr inbounds i8, ptr %0, i64 56
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  %56 = getelementptr inbounds i8, ptr %48, i64 40
  store ptr %55, ptr %56, align 8, !tbaa !15
  %57 = getelementptr inbounds i8, ptr %55, i64 32
  store ptr %48, ptr %57, align 8, !tbaa !14
  %58 = load ptr, ptr %5, align 8, !tbaa !11
  %59 = icmp eq ptr %58, %2
  br i1 %59, label %60, label %62

60:                                               ; preds = %53
  %61 = getelementptr inbounds i8, ptr %48, i64 48
  store ptr %5, ptr %61, align 8, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %50, %60
  %.sink54 = phi ptr [ %48, %60 ], [ null, %50 ]
  store ptr %.sink54, ptr %5, align 8, !tbaa !11
  br label %62

62:                                               ; preds = %.sink.split, %53, %50
  store ptr null, ptr %4, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %62, %1
  tail call void @__restore_interrupt(i32 noundef %3)
  ret i32 0
}

; 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, !10, i64 48}
!6 = !{!"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}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !10, i64 32}
!15 = !{!6, !10, i64 40}


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