; LLVM IR from yinqiwen/ardb :: src/statistics.ll (ZN4ardb9CostTrack7AddCostEm)

; 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.ardb::CostTrack" = type { %"struct.ardb::Track.base", %"class.std::vector", %"class.std::vector.3" }
%"struct.ardb::Track.base" = type <{ ptr, %"class.std::__cxx11::basic_string", i32 }>
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<ardb::CostRange, std::allocator<ardb::CostRange>>::_Vector_impl" }
%"struct.std::_Vector_base<ardb::CostRange, std::allocator<ardb::CostRange>>::_Vector_impl" = type { %"struct.std::_Vector_base<ardb::CostRange, std::allocator<ardb::CostRange>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ardb::CostRange, std::allocator<ardb::CostRange>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.3" = type { %"struct.std::_Vector_base.4" }
%"struct.std::_Vector_base.4" = type { %"struct.std::_Vector_base<ardb::CostRecord, std::allocator<ardb::CostRecord>>::_Vector_impl" }
%"struct.std::_Vector_base<ardb::CostRecord, std::allocator<ardb::CostRecord>>::_Vector_impl" = type { %"struct.std::_Vector_base<ardb::CostRecord, std::allocator<ardb::CostRecord>>::_Vector_impl_data" }
%"struct.std::_Vector_base<ardb::CostRecord, std::allocator<ardb::CostRecord>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.ardb::CostRecord" = type { i64, i64 }
%"struct.ardb::CostRange" = type { i64, i64 }

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

; 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 @_ZN4ardb9CostTrack7AddCostEm(ptr noundef nonnull align 8 dereferenceable(96) %0, i64 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %"struct.ardb::CostTrack", ptr %7, i32 0, i32 2
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb10CostRecordESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %8, i64 noundef 0) #4
  %10 = getelementptr inbounds %"struct.ardb::CostRecord", ptr %9, i32 0, i32 0
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = call noundef i64 @_ZN4ardb17atomic_add_uint64EPVmm(ptr noundef %10, i64 noundef %11)
  %13 = getelementptr inbounds %"struct.ardb::CostTrack", ptr %7, i32 0, i32 2
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb10CostRecordESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %13, i64 noundef 0) #4
  %15 = getelementptr inbounds %"struct.ardb::CostRecord", ptr %14, i32 0, i32 1
  %16 = call noundef i64 @_ZN4ardb17atomic_add_uint64EPVmm(ptr noundef %15, i64 noundef 1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %54, %2
  %18 = load i64, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds %"struct.ardb::CostTrack", ptr %7, i32 0, i32 1
  %20 = call noundef i64 @_ZNKSt6vectorIN4ardb9CostRangeESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %19) #4
  %21 = icmp ult i64 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  store i32 2, ptr %6, align 4
  br label %57

23:                                               ; preds = %17
  %24 = load i64, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %"struct.ardb::CostTrack", ptr %7, i32 0, i32 1
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb9CostRangeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %25, i64 noundef %26) #4
  %28 = getelementptr inbounds %"struct.ardb::CostRange", ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = icmp uge i64 %24, %29
  br i1 %30, label %31, label %53

31:                                               ; preds = %23
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = getelementptr inbounds %"struct.ardb::CostTrack", ptr %7, i32 0, i32 1
  %34 = load i64, ptr %5, align 8, !tbaa !9
  %35 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb9CostRangeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %33, i64 noundef %34) #4
  %36 = getelementptr inbounds %"struct.ardb::CostRange", ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !13
  %38 = icmp ule i64 %32, %37
  br i1 %38, label %39, label %53

39:                                               ; preds = %31
  %40 = getelementptr inbounds %"struct.ardb::CostTrack", ptr %7, i32 0, i32 2
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = add i64 %41, 1
  %43 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb10CostRecordESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %40, i64 noundef %42) #4
  %44 = getelementptr inbounds %"struct.ardb::CostRecord", ptr %43, i32 0, i32 0
  %45 = load i64, ptr %4, align 8, !tbaa !9
  %46 = call noundef i64 @_ZN4ardb17atomic_add_uint64EPVmm(ptr noundef %44, i64 noundef %45)
  %47 = getelementptr inbounds %"struct.ardb::CostTrack", ptr %7, i32 0, i32 2
  %48 = load i64, ptr %5, align 8, !tbaa !9
  %49 = add i64 %48, 1
  %50 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb10CostRecordESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %47, i64 noundef %49) #4
  %51 = getelementptr inbounds %"struct.ardb::CostRecord", ptr %50, i32 0, i32 1
  %52 = call noundef i64 @_ZN4ardb17atomic_add_uint64EPVmm(ptr noundef %51, i64 noundef 1)
  store i32 1, ptr %6, align 4
  br label %57

53:                                               ; preds = %31, %23
  br label %54

54:                                               ; preds = %53
  %55 = load i64, ptr %5, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %5, align 8, !tbaa !9
  br label %17, !llvm.loop !14

57:                                               ; preds = %39, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %58 = load i32, ptr %6, align 4
  switch i32 %58, label %60 [
    i32 2, label %59
    i32 1, label %59
  ]

59:                                               ; preds = %57, %57
  ret void

60:                                               ; preds = %57
  unreachable
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4ardb17atomic_add_uint64EPVmm(ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb10CostRecordESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb9CostRangeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN4ardb9CostRangeE", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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 @_ZN4ardb9CostTrack7AddCostEm(ptr noundef nonnull align 8 dereferenceable(96) %0, i64 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 72
  %4 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb10CostRecordESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef 0) #2
  %5 = tail call noundef i64 @_ZN4ardb17atomic_add_uint64EPVmm(ptr noundef nonnull %4, i64 noundef %1)
  %6 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb10CostRecordESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef 0) #2
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = tail call noundef i64 @_ZN4ardb17atomic_add_uint64EPVmm(ptr noundef nonnull %7, i64 noundef 1)
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  %10 = tail call noundef i64 @_ZNKSt6vectorIN4ardb9CostRangeESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %9) #2
  %.not14 = icmp eq i64 %10, 0
  br i1 %.not14, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2, %24
  %.013 = phi i64 [ %25, %24 ], [ 0, %2 ]
  %11 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb9CostRangeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %9, i64 noundef %.013) #2
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %.not = icmp ugt i64 %12, %1
  br i1 %.not, label %24, label %13

13:                                               ; preds = %.lr.ph
  %14 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb9CostRangeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %9, i64 noundef %.013) #2
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !10
  %.not11 = icmp ult i64 %16, %1
  br i1 %.not11, label %24, label %17

17:                                               ; preds = %13
  %18 = add nuw i64 %.013, 1
  %19 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb10CostRecordESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %18) #2
  %20 = tail call noundef i64 @_ZN4ardb17atomic_add_uint64EPVmm(ptr noundef nonnull %19, i64 noundef %1)
  %21 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb10CostRecordESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %18) #2
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = tail call noundef i64 @_ZN4ardb17atomic_add_uint64EPVmm(ptr noundef nonnull %22, i64 noundef 1)
  br label %.loopexit

24:                                               ; preds = %.lr.ph, %13
  %25 = add nuw i64 %.013, 1
  %26 = tail call noundef i64 @_ZNKSt6vectorIN4ardb9CostRangeESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %9) #2
  %27 = icmp ult i64 %25, %26
  br i1 %27, label %.lr.ph, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %24, %2, %17
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4ardb17atomic_add_uint64EPVmm(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb10CostRecordESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN4ardb9CostRangeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) 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" }
attributes #1 = { inlinehint 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 = { 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, !7, i64 0}
!6 = !{!"_ZTSN4ardb9CostRangeE", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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