; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/perf (perf)

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

; 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 nounwind uwtable
declare dso_local noundef double @_ZN4Perf8internal17StandardDeviationEdRKSt6vectorIdSaIdEE(double noundef, ptr noundef nonnull align 8 dereferenceable(24)) #1

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Perf8internal10StatisticsERKSt6vectorIdSaIdEERdS6_S6_S6_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %12, i64 noundef 0) #2
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  store double %14, ptr %15, align 8, !tbaa !9
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  store double %14, ptr %16, align 8, !tbaa !9
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  store double %14, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 1, ptr %11, align 8, !tbaa !11
  br label %18

18:                                               ; preds = %61, %5
  %19 = load i64, ptr %11, align 8, !tbaa !11
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %20) #2
  %22 = icmp ult i64 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %64

24:                                               ; preds = %18
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i64, ptr %11, align 8, !tbaa !11
  %27 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %25, i64 noundef %26) #2
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load double, ptr %29, align 8, !tbaa !9
  %31 = fadd double %30, %28
  store double %31, ptr %29, align 8, !tbaa !9
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = load double, ptr %32, align 8, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i64, ptr %11, align 8, !tbaa !11
  %36 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %34, i64 noundef %35) #2
  %37 = load double, ptr %36, align 8, !tbaa !9
  %38 = fcmp ogt double %33, %37
  br i1 %38, label %39, label %45

39:                                               ; preds = %24
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i64, ptr %11, align 8, !tbaa !11
  %42 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %40, i64 noundef %41) #2
  %43 = load double, ptr %42, align 8, !tbaa !9
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  store double %43, ptr %44, align 8, !tbaa !9
  br label %60

45:                                               ; preds = %24
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = load double, ptr %46, align 8, !tbaa !9
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i64, ptr %11, align 8, !tbaa !11
  %50 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %48, i64 noundef %49) #2
  %51 = load double, ptr %50, align 8, !tbaa !9
  %52 = fcmp olt double %47, %51
  br i1 %52, label %53, label %59

53:                                               ; preds = %45
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i64, ptr %11, align 8, !tbaa !11
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %54, i64 noundef %55) #2
  %57 = load double, ptr %56, align 8, !tbaa !9
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  store double %57, ptr %58, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %53, %45
  br label %60

60:                                               ; preds = %59, %39
  br label %61

61:                                               ; preds = %60
  %62 = load i64, ptr %11, align 8, !tbaa !11
  %63 = add i64 %62, 1
  store i64 %63, ptr %11, align 8, !tbaa !11
  br label %18, !llvm.loop !13

64:                                               ; preds = %23
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load double, ptr %65, align 8, !tbaa !9
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %67) #2
  %69 = uitofp i64 %68 to double
  %70 = fdiv double %66, %69
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  store double %70, ptr %71, align 8, !tbaa !9
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load double, ptr %72, align 8, !tbaa !9
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = call noundef double @_ZN4Perf8internal17StandardDeviationEdRKSt6vectorIdSaIdEE(double noundef %73, ptr noundef nonnull align 8 dereferenceable(24) %74)
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  store double %75, ptr %76, align 8, !tbaa !9
  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 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 double @_ZN4Perf8internal17StandardDeviationEdRKSt6vectorIdSaIdEE(double noundef, ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(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(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Perf8internal10StatisticsERKSt6vectorIdSaIdEERdS6_S6_S6_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr nocapture noundef nonnull align 8 dereferenceable(8) %1, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %2, ptr nocapture noundef nonnull align 8 dereferenceable(8) %3, ptr nocapture noundef nonnull align 8 dereferenceable(8) %4) local_unnamed_addr #0 {
  %6 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #1
  %7 = load double, ptr %6, align 8, !tbaa !5
  store double %7, ptr %1, align 8, !tbaa !5
  store double %7, ptr %4, align 8, !tbaa !5
  store double %7, ptr %3, align 8, !tbaa !5
  %8 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %9 = icmp ugt i64 %8, 1
  br i1 %9, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %30, %5
  %10 = load double, ptr %1, align 8, !tbaa !5
  %11 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %12 = uitofp i64 %11 to double
  %13 = fdiv double %10, %12
  store double %13, ptr %1, align 8, !tbaa !5
  %14 = tail call noundef double @_ZN4Perf8internal17StandardDeviationEdRKSt6vectorIdSaIdEE(double noundef %13, ptr noundef nonnull align 8 dereferenceable(24) %0)
  store double %14, ptr %2, align 8, !tbaa !5
  ret void

.lr.ph:                                           ; preds = %5, %30
  %.027 = phi i64 [ %31, %30 ], [ 1, %5 ]
  %15 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.027) #1
  %16 = load double, ptr %15, align 8, !tbaa !5
  %17 = load double, ptr %1, align 8, !tbaa !5
  %18 = fadd double %16, %17
  store double %18, ptr %1, align 8, !tbaa !5
  %19 = load double, ptr %3, align 8, !tbaa !5
  %20 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.027) #1
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = fcmp ogt double %19, %21
  br i1 %22, label %.sink.split, label %23

23:                                               ; preds = %.lr.ph
  %24 = load double, ptr %4, align 8, !tbaa !5
  %25 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.027) #1
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = fcmp olt double %24, %26
  br i1 %27, label %.sink.split, label %30

.sink.split:                                      ; preds = %23, %.lr.ph
  %.sink28 = phi ptr [ %3, %.lr.ph ], [ %4, %23 ]
  %28 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNKSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.027) #1
  %29 = load double, ptr %28, align 8, !tbaa !5
  store double %29, ptr %.sink28, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %.sink.split, %23
  %31 = add nuw i64 %.027, 1
  %32 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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