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

; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4ardb14TimerTaskQueue5FixUpEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #2 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb14TimerTaskQueue3AddEPNS_9TimerTaskE(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 2
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = add i32 %10, 1
  %12 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !12
  %14 = icmp eq i32 %11, %13
  br i1 %14, label %15, label %62

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  store ptr null, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !12
  %18 = mul i32 2, %17
  %19 = zext i32 %18 to i64
  %20 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %19, i64 8)
  %21 = extractvalue { i64, i1 } %20, 1
  %22 = extractvalue { i64, i1 } %20, 0
  %23 = select i1 %21, i64 -1, i64 %22
  %24 = call noalias noundef nonnull ptr @_Znam(i64 noundef %23) #8
  store ptr %24, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 1
  %27 = load i32, ptr %26, align 8, !tbaa !12
  %28 = zext i32 %27 to i64
  %29 = mul i64 16, %28
  call void @llvm.memset.p0.i64(ptr align 8 %25, i8 0, i64 %29, i1 false)
  br label %30

30:                                               ; preds = %15
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = icmp eq ptr null, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  store i32 1, ptr %6, align 4
  br label %59

34:                                               ; preds = %30
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !12
  %42 = zext i32 %41 to i64
  %43 = mul i64 %42, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %37, ptr align 8 %39, i64 %43, i1 false)
  br label %44

44:                                               ; preds = %36
  %45 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !13
  %47 = icmp eq ptr %46, null
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  call void @_ZdaPv(ptr noundef %46) #9
  br label %49

49:                                               ; preds = %48, %44
  %50 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  store ptr null, ptr %50, align 8, !tbaa !13
  br label %51

51:                                               ; preds = %49
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  store ptr %53, ptr %54, align 8, !tbaa !13
  %55 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 1
  %56 = load i32, ptr %55, align 8, !tbaa !12
  %57 = mul i32 2, %56
  %58 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 1
  store i32 %57, ptr %58, align 8, !tbaa !12
  store i32 0, ptr %6, align 4
  br label %59

59:                                               ; preds = %52, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  %60 = load i32, ptr %6, align 4
  switch i32 %60, label %78 [
    i32 0, label %61
    i32 1, label %77
  ]

61:                                               ; preds = %59
  br label %62

62:                                               ; preds = %61, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %63 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 2
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = add i32 %64, 1
  store i32 %65, ptr %63, align 4, !tbaa !9
  store i32 %65, ptr %7, align 4, !tbaa !14
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !13
  %69 = load i32, ptr %7, align 4, !tbaa !14
  %70 = zext i32 %69 to i64
  %71 = getelementptr inbounds ptr, ptr %68, i64 %70
  store ptr %66, ptr %71, align 8, !tbaa !5
  %72 = load i32, ptr %7, align 4, !tbaa !14
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %"class.ardb::TimerTask", ptr %73, i32 0, i32 9
  store i32 %72, ptr %74, align 8, !tbaa !15
  %75 = getelementptr inbounds %"class.ardb::TimerTaskQueue", ptr %8, i32 0, i32 2
  %76 = load i32, ptr %75, align 4, !tbaa !9
  call void @_ZN4ardb14TimerTaskQueue5FixUpEj(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef %76)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %77

77:                                               ; preds = %62, %59
  ret void

78:                                               ; preds = %59
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #6

attributes #0 = { nobuiltin allocsize(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 nounwind willreturn memory(argmem: write) }
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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nobuiltin nounwind "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 #7 = { nounwind }
attributes #8 = { builtin allocsize(0) }
attributes #9 = { builtin 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, !11, i64 12}
!10 = !{!"_ZTSN4ardb14TimerTaskQueueE", !6, i64 0, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !6, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !11, i64 56}
!16 = !{!"_ZTSN4ardb9TimerTaskE", !11, i64 0, !17, i64 4, !18, i64 8, !18, i64 16, !19, i64 24, !18, i64 32, !6, i64 40, !6, i64 48, !11, i64 56}
!17 = !{!"_ZTSN4ardb14TimerTaskStateE", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!"_ZTSN4ardb8TimeUnitE", !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"

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4ardb14TimerTaskQueue5FixUpEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4ardb14TimerTaskQueue3AddEPNS_9TimerTaskE(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 12
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = add i32 %4, 1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i32 %5, %7
  br i1 %8, label %9, label %._crit_edge

._crit_edge:                                      ; preds = %2
  %.pre12 = load ptr, ptr %0, align 8, !tbaa !12
  br label %21

9:                                                ; preds = %2
  %10 = shl i32 %5, 1
  %11 = zext i32 %10 to i64
  %12 = shl nuw nsw i64 %11, 3
  %13 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %12) #5
  %14 = zext i32 %5 to i64
  %15 = shl nuw nsw i64 %14, 4
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %13, i8 0, i64 %15, i1 false)
  %16 = load ptr, ptr %0, align 8, !tbaa !12
  %17 = shl nuw nsw i64 %14, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %13, ptr align 8 %16, i64 %17, i1 false)
  %18 = icmp eq ptr %16, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %9
  tail call void @_ZdaPv(ptr noundef nonnull %16) #6
  %.pre = load i32, ptr %6, align 8, !tbaa !11
  %.pre11.pre = load i32, ptr %3, align 4, !tbaa !5
  %.pre14 = shl i32 %.pre, 1
  %.pre17 = add i32 %.pre11.pre, 1
  br label %20

20:                                               ; preds = %19, %9
  %.pre15.pre-phi = phi i32 [ %.pre17, %19 ], [ %5, %9 ]
  %.pre-phi = phi i32 [ %.pre14, %19 ], [ %10, %9 ]
  store ptr %13, ptr %0, align 8, !tbaa !12
  store i32 %.pre-phi, ptr %6, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %._crit_edge, %20
  %.pre-phi16 = phi i32 [ %5, %._crit_edge ], [ %.pre15.pre-phi, %20 ]
  %22 = phi ptr [ %.pre12, %._crit_edge ], [ %13, %20 ]
  store i32 %.pre-phi16, ptr %3, align 4, !tbaa !5
  %23 = zext i32 %.pre-phi16 to i64
  %24 = getelementptr inbounds ptr, ptr %22, i64 %23
  store ptr %1, ptr %24, align 8, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %1, i64 56
  store i32 %.pre-phi16, ptr %25, align 8, !tbaa !14
  tail call void @_ZN4ardb14TimerTaskQueue5FixUpEj(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %.pre-phi16)
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #4

attributes #0 = { nobuiltin allocsize(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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nobuiltin nounwind "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 #5 = { builtin allocsize(0) }
attributes #6 = { builtin 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 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, !10, i64 8}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, 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, !7, i64 40, !7, i64 48, !10, i64 56}
!16 = !{!"_ZTSN4ardb14TimerTaskStateE", !8, i64 0}
!17 = !{!"long", !8, i64 0}
!18 = !{!"_ZTSN4ardb8TimeUnitE", !8, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass