; LLVM IR from yinqiwen/ardb :: src/common/channel/timer/timer_task_queue.ll (ZN4ardb14TimerTaskQueue5FixUpEj)

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

%"class.ardb::TimerTaskQueue" = type { ptr, i32, i32 }
%"class.ardb::TimerTask" = type <{ i32, i32, i64, i64, i32, [4 x i8], i64, ptr, ptr, i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb14TimerTaskQueue5FixUpEj(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  br label %9

9:                                                ; preds = %74, %2
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = icmp ugt i32 %10, 1
  br i1 %11, label %12, label %75

12:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = lshr i32 %13, 1
  store i32 %14, ptr %5, align 4, !tbaa !9
  %15 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds ptr, ptr %16, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %20)
  %22 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds ptr, ptr %23, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %27)
  %29 = icmp ule i64 %21, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %12
  store i32 3, ptr %6, align 4
  br label %72

31:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %32 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %33, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  store ptr %37, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds ptr, ptr %39, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds ptr, ptr %45, i64 %47
  store ptr %43, ptr %48, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = load i32, ptr %4, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds ptr, ptr %51, i64 %53
  store ptr %49, ptr %54, align 8, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds ptr, ptr %57, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = getelementptr inbounds %"class.ardb::TimerTask", ptr %61, i32 0, i32 9
  store i32 %55, ptr %62, align 8, !tbaa !13
  %63 = load i32, ptr %4, align 4, !tbaa !9
  %64 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !11
  %66 = load i32, ptr %4, align 4, !tbaa !9
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds ptr, ptr %65, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds %"class.ardb::TimerTask", ptr %69, i32 0, i32 9
  store i32 %63, ptr %70, align 8, !tbaa !13
  %71 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %71, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  store i32 0, ptr %6, align 4
  br label %72

72:                                               ; preds = %31, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %73 = load i32, ptr %6, align 4
  switch i32 %73, label %76 [
    i32 0, label %74
    i32 3, label %75
  ]

74:                                               ; preds = %72
  br label %9, !llvm.loop !18

75:                                               ; preds = %72, %9
  ret void

76:                                               ; preds = %72
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60)) #2 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN4ardb14TimerTaskQueueE", !6, i64 0, !10, i64 8, !10, i64 12}
!13 = !{!14, !10, i64 56}
!14 = !{!"_ZTSN4ardb9TimerTaskE", !10, i64 0, !15, i64 4, !16, i64 8, !16, i64 16, !17, i64 24, !16, i64 32, !6, i64 40, !6, i64 48, !10, i64 56}
!15 = !{!"_ZTSN4ardb14TimerTaskStateE", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTSN4ardb8TimeUnitE", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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: mustprogress nounwind uwtable
define dso_local void @_ZN4ardb14TimerTaskQueue5FixUpEj(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = icmp ugt i32 %1, 1
  br i1 %3, label %.lr.ph.preheader, label %.thread

.lr.ph.preheader:                                 ; preds = %2
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %15
  %4 = phi ptr [ %23, %15 ], [ %.pre, %.lr.ph.preheader ]
  %.019 = phi i32 [ %5, %15 ], [ %1, %.lr.ph.preheader ]
  %5 = lshr i32 %.019, 1
  %6 = zext nneg i32 %5 to i64
  %7 = getelementptr inbounds ptr, ptr %4, i64 %6
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = tail call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %8)
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = zext i32 %.019 to i64
  %12 = getelementptr inbounds ptr, ptr %10, i64 %11
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = tail call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %13)
  %.not = icmp ugt i64 %9, %14
  br i1 %.not, label %15, label %.thread

15:                                               ; preds = %.lr.ph
  %16 = load ptr, ptr %0, align 8, !tbaa !5
  %17 = getelementptr inbounds ptr, ptr %16, i64 %6
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds ptr, ptr %16, i64 %11
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  store ptr %20, ptr %17, align 8, !tbaa !11
  %21 = load ptr, ptr %0, align 8, !tbaa !5
  %22 = getelementptr inbounds ptr, ptr %21, i64 %11
  store ptr %18, ptr %22, align 8, !tbaa !11
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = getelementptr inbounds ptr, ptr %23, i64 %6
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds i8, ptr %25, i64 56
  store i32 %5, ptr %26, align 8, !tbaa !12
  %27 = getelementptr inbounds ptr, ptr %23, i64 %11
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %28, i64 56
  store i32 %.019, ptr %29, align 8, !tbaa !12
  %30 = icmp ugt i32 %.019, 3
  br i1 %30, label %.lr.ph, label %.thread

.thread:                                          ; preds = %15, %.lr.ph, %2
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60)) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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 = !{!"_ZTSN4ardb14TimerTaskQueueE", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 56}
!13 = !{!"_ZTSN4ardb9TimerTaskE", !10, i64 0, !14, i64 4, !15, i64 8, !15, i64 16, !16, i64 24, !15, i64 32, !7, i64 40, !7, i64 48, !10, i64 56}
!14 = !{!"_ZTSN4ardb14TimerTaskStateE", !8, i64 0}
!15 = !{!"long", !8, i64 0}
!16 = !{!"_ZTSN4ardb8TimeUnitE", !8, i64 0}


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