; LLVM IR from sfu-dis/mosaicdb :: benchmarks/egen/bucketsimulator.ll (ZN4TPCE15BucketSimulator11calc_stddevEv)

; 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.TPCE::BucketSimulator" = type { %"class.TPCE::CRandom", ptr, i64, i32, i32, i64, i64, i32, ptr }
%"class.TPCE::CRandom" = type { i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN4TPCE15BucketSimulator11calc_stddevEv(ptr noundef nonnull align 8 dereferenceable(64) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store double 0.000000e+00, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %26, %1
  %11 = load i32, ptr %4, align 4, !tbaa !11
  %12 = getelementptr inbounds %"class.TPCE::BucketSimulator", ptr %9, i32 0, i32 7
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp slt i32 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %29

16:                                               ; preds = %10
  %17 = getelementptr inbounds %"class.TPCE::BucketSimulator", ptr %9, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = load i32, ptr %4, align 4, !tbaa !11
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i64, ptr %18, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !18
  %23 = sitofp i64 %22 to double
  %24 = load double, ptr %3, align 8, !tbaa !9
  %25 = fadd double %24, %23
  store double %25, ptr %3, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %16
  %27 = load i32, ptr %4, align 4, !tbaa !11
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %4, align 4, !tbaa !11
  br label %10, !llvm.loop !19

29:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %30 = load double, ptr %3, align 8, !tbaa !9
  %31 = getelementptr inbounds %"class.TPCE::BucketSimulator", ptr %9, i32 0, i32 7
  %32 = load i32, ptr %31, align 8, !tbaa !13
  %33 = sitofp i32 %32 to double
  %34 = fdiv double %30, %33
  store double %34, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %62, %29
  %36 = load i32, ptr %7, align 4, !tbaa !11
  %37 = getelementptr inbounds %"class.TPCE::BucketSimulator", ptr %9, i32 0, i32 7
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = icmp slt i32 %36, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %65

41:                                               ; preds = %35
  %42 = getelementptr inbounds %"class.TPCE::BucketSimulator", ptr %9, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  %44 = load i32, ptr %7, align 4, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i64, ptr %43, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !18
  %48 = sitofp i64 %47 to double
  %49 = load double, ptr %5, align 8, !tbaa !9
  %50 = fsub double %48, %49
  %51 = getelementptr inbounds %"class.TPCE::BucketSimulator", ptr %9, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = load i32, ptr %7, align 4, !tbaa !11
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i64, ptr %52, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !18
  %57 = sitofp i64 %56 to double
  %58 = load double, ptr %5, align 8, !tbaa !9
  %59 = fsub double %57, %58
  %60 = load double, ptr %6, align 8, !tbaa !9
  %61 = call double @llvm.fmuladd.f64(double %50, double %59, double %60)
  store double %61, ptr %6, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %41
  %63 = load i32, ptr %7, align 4, !tbaa !11
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %7, align 4, !tbaa !11
  br label %35, !llvm.loop !21

65:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %66 = load double, ptr %6, align 8, !tbaa !9
  %67 = getelementptr inbounds %"class.TPCE::BucketSimulator", ptr %9, i32 0, i32 7
  %68 = load i32, ptr %67, align 8, !tbaa !13
  %69 = sub nsw i32 %68, 1
  %70 = sitofp i32 %69 to double
  %71 = fdiv double %66, %70
  %72 = call double @sqrt(double noundef %71) #4
  store double %72, ptr %8, align 8, !tbaa !9
  %73 = load double, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret double %73
}

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

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

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

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 willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 48}
!14 = !{!"_ZTSN4TPCE15BucketSimulatorE", !15, i64 0, !6, i64 8, !16, i64 16, !12, i64 24, !12, i64 28, !16, i64 32, !16, i64 40, !12, i64 48, !6, i64 56}
!15 = !{!"_ZTSN4TPCE7CRandomE", !16, i64 0}
!16 = !{!"long long", !7, i64 0}
!17 = !{!14, !6, i64 8}
!18 = !{!16, !16, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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 nofree nounwind memory(readwrite, inaccessiblemem: write) uwtable
define dso_local noundef double @_ZN4TPCE15BucketSimulator11calc_stddevEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(64) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 48
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge26

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !13
  %wide.trip.count = zext nneg i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %7 = icmp ult i32 %3, 4
  br i1 %7, label %._crit_edge.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %17

._crit_edge.unr-lcssa:                            ; preds = %17, %.lr.ph
  %.lcssa38.ph = phi double [ poison, %.lr.ph ], [ %33, %17 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.3, %17 ]
  %.020.unr = phi double [ 0.000000e+00, %.lr.ph ], [ %33, %17 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.unr-lcssa ]
  %.020.epil = phi double [ %11, %.epil.preheader ], [ %.020.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.unr-lcssa ]
  %8 = getelementptr inbounds i64, ptr %6, i64 %indvars.iv.epil
  %9 = load i64, ptr %8, align 8, !tbaa !14
  %10 = sitofp i64 %9 to double
  %11 = fadd double %.020.epil, %10
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !15

._crit_edge:                                      ; preds = %.epil.preheader, %._crit_edge.unr-lcssa
  %.lcssa38 = phi double [ %.lcssa38.ph, %._crit_edge.unr-lcssa ], [ %11, %.epil.preheader ]
  %12 = sitofp i32 %3 to double
  %13 = fdiv double %.lcssa38, %12
  br i1 %4, label %.lr.ph25, label %._crit_edge26

.lr.ph25:                                         ; preds = %._crit_edge
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %xtraiter41 = and i64 %wide.trip.count, 3
  %16 = icmp ult i32 %3, 4
  br i1 %16, label %._crit_edge26.loopexit.unr-lcssa, label %.lr.ph25.new

.lr.ph25.new:                                     ; preds = %.lr.ph25
  %unroll_iter45 = and i64 %wide.trip.count, 2147483644
  br label %43

17:                                               ; preds = %17, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %17 ]
  %.020 = phi double [ 0.000000e+00, %.lr.ph.new ], [ %33, %17 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %17 ]
  %18 = getelementptr inbounds i64, ptr %6, i64 %indvars.iv
  %19 = load i64, ptr %18, align 8, !tbaa !14
  %20 = sitofp i64 %19 to double
  %21 = fadd double %.020, %20
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %22 = getelementptr inbounds i64, ptr %6, i64 %indvars.iv.next
  %23 = load i64, ptr %22, align 8, !tbaa !14
  %24 = sitofp i64 %23 to double
  %25 = fadd double %21, %24
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %26 = getelementptr inbounds i64, ptr %6, i64 %indvars.iv.next.1
  %27 = load i64, ptr %26, align 8, !tbaa !14
  %28 = sitofp i64 %27 to double
  %29 = fadd double %25, %28
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %30 = getelementptr inbounds i64, ptr %6, i64 %indvars.iv.next.2
  %31 = load i64, ptr %30, align 8, !tbaa !14
  %32 = sitofp i64 %31 to double
  %33 = fadd double %29, %32
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.unr-lcssa, label %17, !llvm.loop !17

._crit_edge26.loopexit.unr-lcssa:                 ; preds = %43, %.lr.ph25
  %.lcssa.ph = phi double [ poison, %.lr.ph25 ], [ %63, %43 ]
  %indvars.iv30.unr = phi i64 [ 0, %.lr.ph25 ], [ %indvars.iv.next31.3, %43 ]
  %.01522.unr = phi double [ 0.000000e+00, %.lr.ph25 ], [ %63, %43 ]
  %lcmp.mod43.not = icmp eq i64 %xtraiter41, 0
  br i1 %lcmp.mod43.not, label %._crit_edge26, label %.epil.preheader40

.epil.preheader40:                                ; preds = %._crit_edge26.loopexit.unr-lcssa, %.epil.preheader40
  %indvars.iv30.epil = phi i64 [ %indvars.iv.next31.epil, %.epil.preheader40 ], [ %indvars.iv30.unr, %._crit_edge26.loopexit.unr-lcssa ]
  %.01522.epil = phi double [ %38, %.epil.preheader40 ], [ %.01522.unr, %._crit_edge26.loopexit.unr-lcssa ]
  %epil.iter42 = phi i64 [ %epil.iter42.next, %.epil.preheader40 ], [ 0, %._crit_edge26.loopexit.unr-lcssa ]
  %34 = getelementptr inbounds i64, ptr %15, i64 %indvars.iv30.epil
  %35 = load i64, ptr %34, align 8, !tbaa !14
  %36 = sitofp i64 %35 to double
  %37 = fsub double %36, %13
  %38 = tail call double @llvm.fmuladd.f64(double %37, double %37, double %.01522.epil)
  %indvars.iv.next31.epil = add nuw nsw i64 %indvars.iv30.epil, 1
  %epil.iter42.next = add i64 %epil.iter42, 1
  %epil.iter42.cmp.not = icmp eq i64 %epil.iter42.next, %xtraiter41
  br i1 %epil.iter42.cmp.not, label %._crit_edge26, label %.epil.preheader40, !llvm.loop !19

._crit_edge26:                                    ; preds = %._crit_edge26.loopexit.unr-lcssa, %.epil.preheader40, %1, %._crit_edge
  %.015.lcssa = phi double [ 0.000000e+00, %._crit_edge ], [ 0.000000e+00, %1 ], [ %.lcssa.ph, %._crit_edge26.loopexit.unr-lcssa ], [ %38, %.epil.preheader40 ]
  %39 = add nsw i32 %3, -1
  %40 = sitofp i32 %39 to double
  %41 = fdiv double %.015.lcssa, %40
  %42 = tail call double @sqrt(double noundef %41) #3
  ret double %42

43:                                               ; preds = %43, %.lr.ph25.new
  %indvars.iv30 = phi i64 [ 0, %.lr.ph25.new ], [ %indvars.iv.next31.3, %43 ]
  %.01522 = phi double [ 0.000000e+00, %.lr.ph25.new ], [ %63, %43 ]
  %niter46 = phi i64 [ 0, %.lr.ph25.new ], [ %niter46.next.3, %43 ]
  %44 = getelementptr inbounds i64, ptr %15, i64 %indvars.iv30
  %45 = load i64, ptr %44, align 8, !tbaa !14
  %46 = sitofp i64 %45 to double
  %47 = fsub double %46, %13
  %48 = tail call double @llvm.fmuladd.f64(double %47, double %47, double %.01522)
  %indvars.iv.next31 = or disjoint i64 %indvars.iv30, 1
  %49 = getelementptr inbounds i64, ptr %15, i64 %indvars.iv.next31
  %50 = load i64, ptr %49, align 8, !tbaa !14
  %51 = sitofp i64 %50 to double
  %52 = fsub double %51, %13
  %53 = tail call double @llvm.fmuladd.f64(double %52, double %52, double %48)
  %indvars.iv.next31.1 = or disjoint i64 %indvars.iv30, 2
  %54 = getelementptr inbounds i64, ptr %15, i64 %indvars.iv.next31.1
  %55 = load i64, ptr %54, align 8, !tbaa !14
  %56 = sitofp i64 %55 to double
  %57 = fsub double %56, %13
  %58 = tail call double @llvm.fmuladd.f64(double %57, double %57, double %53)
  %indvars.iv.next31.2 = or disjoint i64 %indvars.iv30, 3
  %59 = getelementptr inbounds i64, ptr %15, i64 %indvars.iv.next31.2
  %60 = load i64, ptr %59, align 8, !tbaa !14
  %61 = sitofp i64 %60 to double
  %62 = fsub double %61, %13
  %63 = tail call double @llvm.fmuladd.f64(double %62, double %62, double %58)
  %indvars.iv.next31.3 = add nuw nsw i64 %indvars.iv30, 4
  %niter46.next.3 = add i64 %niter46, 4
  %niter46.ncmp.3 = icmp eq i64 %niter46.next.3, %unroll_iter45
  br i1 %niter46.ncmp.3, label %._crit_edge26.loopexit.unr-lcssa, label %43, !llvm.loop !20
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nofree nounwind memory(readwrite, inaccessiblemem: write) 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 = { mustprogress nofree nounwind willreturn memory(write) "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, !12, i64 48}
!6 = !{!"_ZTSN4TPCE15BucketSimulatorE", !7, i64 0, !11, i64 8, !8, i64 16, !12, i64 24, !12, i64 28, !8, i64 32, !8, i64 40, !12, i64 48, !11, i64 56}
!7 = !{!"_ZTSN4TPCE7CRandomE", !8, i64 0}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!6, !11, i64 8}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !16}
!20 = distinct !{!20, !18}


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