; LLVM IR from bohanwang/libpgo :: src/core/basicAlgorithms (averagingBuffer)

; 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.pgo::BasicAlgorithms::AveragingBuffer" = type <{ ptr, i32, i32, %"class.std::vector", double, i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3pgo15BasicAlgorithms15AveragingBuffer8addValueEd(ptr noundef nonnull align 8 dereferenceable(52) %0, double noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 5
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 1
  %9 = load i32, ptr %8, align 8, !tbaa !18
  %10 = icmp slt i32 %7, %9
  br i1 %10, label %11, label %28

11:                                               ; preds = %2
  %12 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 4
  %13 = load double, ptr %12, align 8, !tbaa !19
  %14 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 5
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = sitofp i32 %15 to double
  %17 = load double, ptr %4, align 8, !tbaa !9
  %18 = call double @llvm.fmuladd.f64(double %13, double %16, double %17)
  %19 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 5
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = add nsw i32 %20, 1
  %22 = sitofp i32 %21 to double
  %23 = fdiv double %18, %22
  %24 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 4
  store double %23, ptr %24, align 8, !tbaa !19
  %25 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 5
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %25, align 8, !tbaa !11
  br label %50

28:                                               ; preds = %2
  %29 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 3
  %30 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 2
  %31 = load i32, ptr %30, align 4, !tbaa !20
  %32 = sext i32 %31 to i64
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %29, i64 noundef %32) #2
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !18
  %37 = sitofp i32 %36 to double
  %38 = fdiv double %34, %37
  %39 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 4
  %40 = load double, ptr %39, align 8, !tbaa !19
  %41 = fsub double %40, %38
  store double %41, ptr %39, align 8, !tbaa !19
  %42 = load double, ptr %4, align 8, !tbaa !9
  %43 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !18
  %45 = sitofp i32 %44 to double
  %46 = fdiv double %42, %45
  %47 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 4
  %48 = load double, ptr %47, align 8, !tbaa !19
  %49 = fadd double %48, %46
  store double %49, ptr %47, align 8, !tbaa !19
  br label %50

50:                                               ; preds = %28, %11
  %51 = load double, ptr %4, align 8, !tbaa !9
  %52 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 3
  %53 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 2
  %54 = load i32, ptr %53, align 4, !tbaa !20
  %55 = sext i32 %54 to i64
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %52, i64 noundef %55) #2
  store double %51, ptr %56, align 8, !tbaa !9
  %57 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 2
  %58 = load i32, ptr %57, align 4, !tbaa !20
  %59 = add nsw i32 %58, 1
  %60 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 1
  %61 = load i32, ptr %60, align 8, !tbaa !18
  %62 = srem i32 %59, %61
  %63 = getelementptr inbounds %"class.pgo::BasicAlgorithms::AveragingBuffer", ptr %5, i32 0, i32 2
  store i32 %62, ptr %63, align 4, !tbaa !20
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !13, i64 48}
!12 = !{!"_ZTSN3pgo15BasicAlgorithms15AveragingBufferE", !13, i64 8, !13, i64 12, !14, i64 16, !10, i64 40, !13, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSSt6vectorIdSaIdEE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!12, !13, i64 8}
!19 = !{!12, !10, i64 40}
!20 = !{!12, !13, i64 12}


; 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 @_ZN3pgo15BasicAlgorithms15AveragingBuffer8addValueEd(ptr noundef nonnull align 8 dereferenceable(52) %0, double noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !16
  %7 = icmp slt i32 %4, %6
  br i1 %7, label %8, label %16

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = load double, ptr %9, align 8, !tbaa !17
  %11 = sitofp i32 %4 to double
  %12 = tail call double @llvm.fmuladd.f64(double %10, double %11, double %1)
  %13 = add nsw i32 %4, 1
  %14 = sitofp i32 %13 to double
  %15 = fdiv double %12, %14
  store double %15, ptr %9, align 8, !tbaa !17
  store i32 %13, ptr %3, align 8, !tbaa !5
  br label %36

16:                                               ; preds = %2
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = getelementptr inbounds i8, ptr %0, i64 12
  %19 = load i32, ptr %18, align 4, !tbaa !18
  %20 = sext i32 %19 to i64
  %21 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %17, i64 noundef %20) #2
  %22 = load double, ptr %21, align 8, !tbaa !19
  %23 = load i32, ptr %5, align 8, !tbaa !16
  %24 = sitofp i32 %23 to double
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %26 = load double, ptr %25, align 8, !tbaa !17
  %27 = insertelement <2 x double> poison, double %1, i64 0
  %28 = insertelement <2 x double> %27, double %22, i64 1
  %29 = insertelement <2 x double> poison, double %24, i64 0
  %30 = shufflevector <2 x double> %29, <2 x double> poison, <2 x i32> zeroinitializer
  %31 = fdiv <2 x double> %28, %30
  %32 = extractelement <2 x double> %31, i64 1
  %33 = fsub double %26, %32
  %34 = extractelement <2 x double> %31, i64 0
  %35 = fadd double %34, %33
  store double %35, ptr %25, align 8, !tbaa !17
  br label %36

36:                                               ; preds = %16, %8
  %37 = getelementptr inbounds i8, ptr %0, i64 16
  %38 = getelementptr inbounds i8, ptr %0, i64 12
  %39 = load i32, ptr %38, align 4, !tbaa !18
  %40 = sext i32 %39 to i64
  %41 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %37, i64 noundef %40) #2
  store double %1, ptr %41, align 8, !tbaa !19
  %42 = load i32, ptr %38, align 4, !tbaa !18
  %43 = add nsw i32 %42, 1
  %44 = load i32, ptr %5, align 8, !tbaa !16
  %45 = srem i32 %43, %44
  store i32 %45, ptr %38, align 4, !tbaa !18
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 48}
!6 = !{!"_ZTSN3pgo15BasicAlgorithms15AveragingBufferE", !7, i64 8, !7, i64 12, !10, i64 16, !15, i64 40, !7, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIdSaIdEE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = !{!6, !7, i64 8}
!17 = !{!6, !15, i64 40}
!18 = !{!6, !7, i64 12}
!19 = !{!15, !15, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass