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

; 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_created_count = external global i64, align 8
@_tx_timer_created_ptr = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @_tx_timer_delete(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, 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
  %6 = call i32 @__disable_interrupts()
  store i32 %6, ptr %3, align 4, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.TX_TIMER_STRUCT, ptr %7, i32 0, i32 2
  %9 = getelementptr inbounds %struct.TX_TIMER_INTERNAL_STRUCT, ptr %8, i32 0, i32 6
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.TX_TIMER_STRUCT, ptr %13, i32 0, i32 2
  call void @_tx_timer_system_deactivate(ptr noundef %14)
  br label %15

15:                                               ; preds = %12, %1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.TX_TIMER_STRUCT, ptr %16, i32 0, i32 0
  store i64 0, ptr %17, align 8, !tbaa !15
  %18 = load i64, ptr @_tx_timer_created_count, align 8, !tbaa !16
  %19 = add i64 %18, -1
  store i64 %19, ptr @_tx_timer_created_count, align 8, !tbaa !16
  %20 = load i64, ptr @_tx_timer_created_count, align 8, !tbaa !16
  %21 = icmp eq i64 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %15
  store ptr null, ptr @_tx_timer_created_ptr, align 8, !tbaa !5
  br label %42

23:                                               ; preds = %15
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TX_TIMER_STRUCT, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  store ptr %26, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TX_TIMER_STRUCT, ptr %27, i32 0, i32 4
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  store ptr %29, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TX_TIMER_STRUCT, ptr %31, i32 0, i32 4
  store ptr %30, ptr %32, align 8, !tbaa !18
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.TX_TIMER_STRUCT, ptr %34, i32 0, i32 3
  store ptr %33, ptr %35, align 8, !tbaa !17
  %36 = load ptr, ptr @_tx_timer_created_ptr, align 8, !tbaa !5
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = icmp eq ptr %36, %37
  br i1 %38, label %39, label %41

39:                                               ; preds = %23
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %40, ptr @_tx_timer_created_ptr, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %39, %23
  br label %42

42:                                               ; preds = %41, %22
  %43 = load i32, ptr %3, align 4, !tbaa !9
  call void @__restore_interrupt(i32 noundef %43)
  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 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

declare void @_tx_timer_system_deactivate(ptr noundef) #3

; 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 = { "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 64}
!12 = !{!"TX_TIMER_STRUCT", !13, i64 0, !6, i64 8, !14, i64 16, !6, i64 72, !6, i64 80}
!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, !13, i64 0}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !6, i64 72}
!18 = !{!12, !6, i64 80}


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

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

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @_tx_timer_system_deactivate(ptr noundef nonnull %6) #3
  br label %7

7:                                                ; preds = %5, %1
  store i64 0, ptr %0, align 8, !tbaa !12
  %8 = load i64, ptr @_tx_timer_created_count, align 8, !tbaa !13
  %9 = add i64 %8, -1
  store i64 %9, ptr @_tx_timer_created_count, align 8, !tbaa !13
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %.sink.split, label %11

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %0, i64 72
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %0, i64 80
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %13, i64 80
  store ptr %15, ptr %16, align 8, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %15, i64 72
  store ptr %13, ptr %17, align 8, !tbaa !14
  %18 = load ptr, ptr @_tx_timer_created_ptr, align 8, !tbaa !16
  %19 = icmp eq ptr %18, %0
  br i1 %19, label %.sink.split, label %20

.sink.split:                                      ; preds = %11, %7
  %.sink = phi ptr [ null, %7 ], [ %13, %11 ]
  store ptr %.sink, ptr @_tx_timer_created_ptr, align 8, !tbaa !16
  br label %20

20:                                               ; preds = %.sink.split, %11
  tail call void @__restore_interrupt(i32 noundef %2)
  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

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, !10, i64 64}
!6 = !{!"TX_TIMER_STRUCT", !7, i64 0, !10, i64 8, !11, i64 16, !10, i64 72, !10, i64 80}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"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}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !10, i64 72}
!15 = !{!6, !10, i64 80}
!16 = !{!10, !10, i64 0}


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