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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

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

8:                                                ; preds = %61, %2
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = shl i32 %9, 1
  store i32 %10, ptr %5, align 4, !tbaa !9
  %11 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 2
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp ule i32 %10, %12
  br i1 %13, label %14, label %17

14:                                               ; preds = %8
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp ugt i32 %15, 0
  br label %17

17:                                               ; preds = %14, %8
  %18 = phi i1 [ false, %8 ], [ %16, %14 ]
  br i1 %18, label %19, label %102

19:                                               ; preds = %17
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = icmp ult i32 %20, %22
  br i1 %23, label %24, label %44

24:                                               ; preds = %19
  %25 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds ptr, ptr %26, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %30)
  %32 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = add i32 %34, 1
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds ptr, ptr %33, i64 %36
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %38)
  %40 = icmp ugt i64 %31, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %24
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = add i32 %42, 1
  store i32 %43, ptr %5, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %41, %24, %19
  %45 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !13
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %46, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %50)
  %52 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds ptr, ptr %53, i64 %55
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  %58 = call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %57)
  %59 = icmp ule i64 %51, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %44
  br label %102

61:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %62 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !13
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds ptr, ptr %63, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  store ptr %67, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !13
  %70 = load i32, ptr %4, align 4, !tbaa !9
  %71 = zext i32 %70 to i64
  %72 = getelementptr inbounds ptr, ptr %69, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !13
  %76 = load i32, ptr %5, align 4, !tbaa !9
  %77 = zext i32 %76 to i64
  %78 = getelementptr inbounds ptr, ptr %75, i64 %77
  store ptr %73, ptr %78, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !13
  %82 = load i32, ptr %4, align 4, !tbaa !9
  %83 = zext i32 %82 to i64
  %84 = getelementptr inbounds ptr, ptr %81, i64 %83
  store ptr %79, ptr %84, align 8, !tbaa !5
  %85 = load i32, ptr %5, align 4, !tbaa !9
  %86 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !13
  %88 = load i32, ptr %5, align 4, !tbaa !9
  %89 = zext i32 %88 to i64
  %90 = getelementptr inbounds ptr, ptr %87, i64 %89
  %91 = load ptr, ptr %90, align 8, !tbaa !5
  %92 = getelementptr inbounds %"class.ardb::TimerTask", ptr %91, i32 0, i32 9
  store i32 %85, ptr %92, align 8, !tbaa !14
  %93 = load i32, ptr %4, align 4, !tbaa !9
  %94 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %7, i32 0, i32 0
  %95 = load ptr, ptr %94, align 8, !tbaa !13
  %96 = load i32, ptr %4, align 4, !tbaa !9
  %97 = zext i32 %96 to i64
  %98 = getelementptr inbounds ptr, ptr %95, i64 %97
  %99 = load ptr, ptr %98, align 8, !tbaa !5
  %100 = getelementptr inbounds %"class.ardb::TimerTask", ptr %99, i32 0, i32 9
  store i32 %93, ptr %100, align 8, !tbaa !14
  %101 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %101, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %8, !llvm.loop !19

102:                                              ; preds = %60, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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, !10, i64 12}
!12 = !{!"_ZTSN4ardb14TimerTaskQueueE", !6, i64 0, !10, i64 8, !10, i64 12}
!13 = !{!12, !6, i64 0}
!14 = !{!15, !10, i64 56}
!15 = !{!"_ZTSN4ardb9TimerTaskE", !10, i64 0, !16, i64 4, !17, i64 8, !17, i64 16, !18, i64 24, !17, i64 32, !6, i64 40, !6, i64 48, !10, i64 56}
!16 = !{!"_ZTSN4ardb14TimerTaskStateE", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTSN4ardb8TimeUnitE", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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
declare dso_local noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4ardb14TimerTaskQueue7FixDownEj(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 12
  %4 = shl i32 %1, 1
  %5 = load i32, ptr %3, align 4, !tbaa !5
  %6 = add i32 %4, -1
  %7 = icmp ult i32 %6, %5
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

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

.lr.ph:                                           ; preds = %.lr.ph.preheader, %34
  %.pre23 = phi ptr [ %42, %34 ], [ %.pre23.pre, %.lr.ph.preheader ]
  %8 = phi i32 [ %50, %34 ], [ %5, %.lr.ph.preheader ]
  %9 = phi i32 [ %49, %34 ], [ %4, %.lr.ph.preheader ]
  %.021 = phi i32 [ %.018, %34 ], [ %1, %.lr.ph.preheader ]
  %10 = icmp ult i32 %9, %8
  br i1 %10, label %11, label %23

11:                                               ; preds = %.lr.ph
  %12 = zext i32 %9 to i64
  %13 = getelementptr inbounds ptr, ptr %.pre23, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = tail call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %14)
  %16 = load ptr, ptr %0, align 8, !tbaa !11
  %17 = or disjoint i32 %9, 1
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds ptr, ptr %16, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = tail call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %20)
  %22 = icmp ugt i64 %15, %21
  %spec.select = select i1 %22, i32 %17, i32 %9
  %.pre = load ptr, ptr %0, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %11, %.lr.ph
  %24 = phi ptr [ %.pre23, %.lr.ph ], [ %.pre, %11 ]
  %.018 = phi i32 [ %9, %.lr.ph ], [ %spec.select, %11 ]
  %25 = zext i32 %.021 to i64
  %26 = getelementptr inbounds ptr, ptr %24, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = tail call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %27)
  %29 = load ptr, ptr %0, align 8, !tbaa !11
  %30 = zext i32 %.018 to i64
  %31 = getelementptr inbounds ptr, ptr %29, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = tail call noundef i64 @_ZN4ardb9TimerTask18GetNextTriggerTimeEv(ptr noundef nonnull align 8 dereferenceable(60) %32)
  %.not = icmp ugt i64 %28, %33
  br i1 %.not, label %34, label %._crit_edge

34:                                               ; preds = %23
  %35 = load ptr, ptr %0, align 8, !tbaa !11
  %36 = getelementptr inbounds ptr, ptr %35, i64 %30
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %38 = getelementptr inbounds ptr, ptr %35, i64 %25
  %39 = load ptr, ptr %38, align 8, !tbaa !12
  store ptr %39, ptr %36, align 8, !tbaa !12
  %40 = load ptr, ptr %0, align 8, !tbaa !11
  %41 = getelementptr inbounds ptr, ptr %40, i64 %25
  store ptr %37, ptr %41, align 8, !tbaa !12
  %42 = load ptr, ptr %0, align 8, !tbaa !11
  %43 = getelementptr inbounds ptr, ptr %42, i64 %30
  %44 = load ptr, ptr %43, align 8, !tbaa !12
  %45 = getelementptr inbounds i8, ptr %44, i64 56
  store i32 %.018, ptr %45, align 8, !tbaa !13
  %46 = getelementptr inbounds ptr, ptr %42, i64 %25
  %47 = load ptr, ptr %46, align 8, !tbaa !12
  %48 = getelementptr inbounds i8, ptr %47, i64 56
  store i32 %.021, ptr %48, align 8, !tbaa !13
  %49 = shl i32 %.018, 1
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add i32 %49, -1
  %52 = icmp ult i32 %51, %50
  br i1 %52, label %.lr.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %34, %23, %2
  ret void
}

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, !10, i64 12}
!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 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}
!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, !7, i64 40, !7, i64 48, !10, i64 56}
!15 = !{!"_ZTSN4ardb14TimerTaskStateE", !8, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{!"_ZTSN4ardb8TimeUnitE", !8, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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