; LLVM IR from eclipse-threadx/threadx :: ports/risc-v64/gnu/src/tx_timer_interrupt.ll (tx_timer_interrupt)

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

@_tx_timer_system_clock = external global i64, align 8
@_tx_timer_time_slice = external global i64, align 8
@_tx_timer_expired_time_slice = external global i32, align 4
@_tx_timer_current_ptr = external global ptr, align 8
@_tx_timer_expired = external global i32, align 4
@_tx_timer_list_end = external global ptr, align 8
@_tx_timer_list_start = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @_tx_timer_interrupt() #0 {
  %1 = load i64, ptr @_tx_timer_system_clock, align 8, !tbaa !5
  %2 = add i64 %1, 1
  store i64 %2, ptr @_tx_timer_system_clock, align 8, !tbaa !5
  %3 = load i64, ptr @_tx_timer_time_slice, align 8, !tbaa !5
  %4 = icmp ne i64 %3, 0
  br i1 %4, label %5, label %12

5:                                                ; preds = %0
  %6 = load i64, ptr @_tx_timer_time_slice, align 8, !tbaa !5
  %7 = add i64 %6, -1
  store i64 %7, ptr @_tx_timer_time_slice, align 8, !tbaa !5
  %8 = load i64, ptr @_tx_timer_time_slice, align 8, !tbaa !5
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %5
  store i32 1, ptr @_tx_timer_expired_time_slice, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %10, %5
  br label %12

12:                                               ; preds = %11, %0
  %13 = load ptr, ptr @_tx_timer_current_ptr, align 8, !tbaa !11
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %12
  store i32 1, ptr @_tx_timer_expired, align 4, !tbaa !9
  br label %26

17:                                               ; preds = %12
  %18 = load ptr, ptr @_tx_timer_current_ptr, align 8, !tbaa !11
  %19 = getelementptr inbounds ptr, ptr %18, i32 1
  store ptr %19, ptr @_tx_timer_current_ptr, align 8, !tbaa !11
  %20 = load ptr, ptr @_tx_timer_current_ptr, align 8, !tbaa !11
  %21 = load ptr, ptr @_tx_timer_list_end, align 8, !tbaa !11
  %22 = icmp eq ptr %20, %21
  br i1 %22, label %23, label %25

23:                                               ; preds = %17
  %24 = load ptr, ptr @_tx_timer_list_start, align 8, !tbaa !11
  store ptr %24, ptr @_tx_timer_current_ptr, align 8, !tbaa !11
  br label %25

25:                                               ; preds = %23, %17
  br label %26

26:                                               ; preds = %25, %16
  %27 = load i32, ptr @_tx_timer_expired_time_slice, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %32, label %29

29:                                               ; preds = %26
  %30 = load i32, ptr @_tx_timer_expired, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %41

32:                                               ; preds = %29, %26
  %33 = load i32, ptr @_tx_timer_expired, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  call void @_tx_timer_expiration_process()
  br label %36

36:                                               ; preds = %35, %32
  %37 = load i32, ptr @_tx_timer_expired_time_slice, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  call void @_tx_thread_time_slice()
  br label %40

40:                                               ; preds = %39, %36
  br label %41

41:                                               ; preds = %40, %29
  ret void
}

declare void @_tx_timer_expiration_process() #1

declare void @_tx_thread_time_slice() #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 = { "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, !6, i64 0}
!6 = !{!"long", !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, !12, i64 0}
!12 = !{!"any pointer", !7, 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_timer_system_clock = external local_unnamed_addr global i64, align 8
@_tx_timer_time_slice = external local_unnamed_addr global i64, align 8
@_tx_timer_expired_time_slice = external local_unnamed_addr global i32, align 4
@_tx_timer_current_ptr = external local_unnamed_addr global ptr, align 8
@_tx_timer_expired = external local_unnamed_addr global i32, align 4
@_tx_timer_list_end = external local_unnamed_addr global ptr, align 8
@_tx_timer_list_start = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @_tx_timer_interrupt() local_unnamed_addr #0 {
  %1 = load i64, ptr @_tx_timer_system_clock, align 8, !tbaa !5
  %2 = add i64 %1, 1
  store i64 %2, ptr @_tx_timer_system_clock, align 8, !tbaa !5
  %3 = load i64, ptr @_tx_timer_time_slice, align 8, !tbaa !5
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %8, label %4

4:                                                ; preds = %0
  %5 = add i64 %3, -1
  store i64 %5, ptr @_tx_timer_time_slice, align 8, !tbaa !5
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %4
  store i32 1, ptr @_tx_timer_expired_time_slice, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %4, %7, %0
  %9 = load ptr, ptr @_tx_timer_current_ptr, align 8, !tbaa !11
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %.not2 = icmp eq ptr %10, null
  br i1 %.not2, label %11, label %.thread6

.thread6:                                         ; preds = %8
  store i32 1, ptr @_tx_timer_expired, align 4, !tbaa !9
  br label %22

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %12, ptr @_tx_timer_current_ptr, align 8, !tbaa !11
  %13 = load ptr, ptr @_tx_timer_list_end, align 8, !tbaa !11
  %14 = icmp eq ptr %12, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %11
  %16 = load ptr, ptr @_tx_timer_list_start, align 8, !tbaa !11
  store ptr %16, ptr @_tx_timer_current_ptr, align 8, !tbaa !11
  br label %17

17:                                               ; preds = %11, %15
  %.pr = load i32, ptr @_tx_timer_expired, align 4
  %18 = load i32, ptr @_tx_timer_expired_time_slice, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 0
  %20 = icmp ne i32 %.pr, 0
  %or.cond = select i1 %19, i1 true, i1 %20
  br i1 %or.cond, label %21, label %26

21:                                               ; preds = %17
  br i1 %20, label %22, label %23

22:                                               ; preds = %.thread6, %21
  tail call void @_tx_timer_expiration_process() #2
  %.pr4 = load i32, ptr @_tx_timer_expired_time_slice, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %22, %21
  %24 = phi i32 [ %.pr4, %22 ], [ %18, %21 ]
  %.not3 = icmp eq i32 %24, 0
  br i1 %.not3, label %26, label %25

25:                                               ; preds = %23
  tail call void @_tx_thread_time_slice() #2
  br label %26

26:                                               ; preds = %23, %25, %17
  ret void
}

declare void @_tx_timer_expiration_process() local_unnamed_addr #1

declare void @_tx_thread_time_slice() 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 = { "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 = { 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 = !{!"long", !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, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,SimplifyCFGPass,TailCallElimPass