; LLVM IR from nsccgz-storage/nvlsm :: util/histogram.ll (ZN7leveldb9Histogram5MergeERKS0_)

; 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.leveldb::Histogram" = type { double, double, double, double, double, [154 x double] }

; 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
define dso_local void @_ZN7leveldb9Histogram5MergeERKS0_(ptr noundef nonnull align 8 dereferenceable(1272) %0, ptr noundef nonnull align 8 dereferenceable(1272) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %"class.leveldb::Histogram", ptr %7, i32 0, i32 0
  %9 = load double, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 0
  %11 = load double, ptr %10, align 8, !tbaa !9
  %12 = fcmp olt double %9, %11
  br i1 %12, label %13, label %18

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %"class.leveldb::Histogram", ptr %14, i32 0, i32 0
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 0
  store double %16, ptr %17, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %13, %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %"class.leveldb::Histogram", ptr %19, i32 0, i32 1
  %21 = load double, ptr %20, align 8, !tbaa !12
  %22 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 1
  %23 = load double, ptr %22, align 8, !tbaa !12
  %24 = fcmp ogt double %21, %23
  br i1 %24, label %25, label %30

25:                                               ; preds = %18
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.leveldb::Histogram", ptr %26, i32 0, i32 1
  %28 = load double, ptr %27, align 8, !tbaa !12
  %29 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 1
  store double %28, ptr %29, align 8, !tbaa !12
  br label %30

30:                                               ; preds = %25, %18
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %"class.leveldb::Histogram", ptr %31, i32 0, i32 2
  %33 = load double, ptr %32, align 8, !tbaa !13
  %34 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 2
  %35 = load double, ptr %34, align 8, !tbaa !13
  %36 = fadd double %35, %33
  store double %36, ptr %34, align 8, !tbaa !13
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.leveldb::Histogram", ptr %37, i32 0, i32 3
  %39 = load double, ptr %38, align 8, !tbaa !14
  %40 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 3
  %41 = load double, ptr %40, align 8, !tbaa !14
  %42 = fadd double %41, %39
  store double %42, ptr %40, align 8, !tbaa !14
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.leveldb::Histogram", ptr %43, i32 0, i32 4
  %45 = load double, ptr %44, align 8, !tbaa !15
  %46 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 4
  %47 = load double, ptr %46, align 8, !tbaa !15
  %48 = fadd double %47, %45
  store double %48, ptr %46, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !16
  br label %49

49:                                               ; preds = %66, %30
  %50 = load i32, ptr %5, align 4, !tbaa !16
  %51 = icmp slt i32 %50, 154
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %69

53:                                               ; preds = %49
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %"class.leveldb::Histogram", ptr %54, i32 0, i32 5
  %56 = load i32, ptr %5, align 4, !tbaa !16
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [154 x double], ptr %55, i64 0, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !18
  %60 = getelementptr inbounds %"class.leveldb::Histogram", ptr %6, i32 0, i32 5
  %61 = load i32, ptr %5, align 4, !tbaa !16
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [154 x double], ptr %60, i64 0, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !18
  %65 = fadd double %64, %59
  store double %65, ptr %63, align 8, !tbaa !18
  br label %66

66:                                               ; preds = %53
  %67 = load i32, ptr %5, align 4, !tbaa !16
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %5, align 4, !tbaa !16
  br label %49, !llvm.loop !19

69:                                               ; preds = %52
  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, !11, i64 0}
!10 = !{!"_ZTSN7leveldb9HistogramE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !7, i64 40}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !11, i64 24}
!15 = !{!10, !11, i64 32}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!11, !11, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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 nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN7leveldb9Histogram5MergeERKS0_(ptr nocapture noundef nonnull align 8 dereferenceable(1272) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(1272) %1) local_unnamed_addr #0 align 2 {
  %3 = load double, ptr %1, align 8, !tbaa !5
  %4 = load double, ptr %0, align 8, !tbaa !5
  %5 = fcmp olt double %3, %4
  br i1 %5, label %6, label %7

6:                                                ; preds = %2
  store double %3, ptr %0, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %6, %2
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load double, ptr %8, align 8, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load double, ptr %10, align 8, !tbaa !10
  %12 = fcmp ogt double %9, %11
  br i1 %12, label %13, label %vector.memcheck

13:                                               ; preds = %7
  store double %9, ptr %10, align 8, !tbaa !10
  br label %vector.memcheck

vector.memcheck:                                  ; preds = %13, %7
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load <2 x double>, ptr %14, align 8, !tbaa !11
  %17 = load <2 x double>, ptr %15, align 8, !tbaa !11
  %18 = fadd <2 x double> %16, %17
  store <2 x double> %18, ptr %15, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %1, i64 32
  %20 = load double, ptr %19, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  %22 = load double, ptr %21, align 8, !tbaa !12
  %23 = fadd double %20, %22
  store double %23, ptr %21, align 8, !tbaa !12
  %24 = getelementptr inbounds i8, ptr %1, i64 40
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  %scevgep = getelementptr inbounds i8, ptr %0, i64 1272
  %scevgep16 = getelementptr inbounds i8, ptr %1, i64 1272
  %bound0 = icmp uge ptr %25, %scevgep16
  %bound1 = icmp uge ptr %24, %scevgep
  %found.conflict.not = or i1 %bound0, %bound1
  br i1 %found.conflict.not, label %vector.body, label %scalar.ph.prol.preheader

scalar.ph.prol.preheader:                         ; preds = %vector.memcheck, %vector.body
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 152, %vector.body ]
  br label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.prol, %scalar.ph.prol.preheader
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.prol.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.prol.preheader ]
  %26 = getelementptr inbounds [154 x double], ptr %24, i64 0, i64 %indvars.iv.prol
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds [154 x double], ptr %25, i64 0, i64 %indvars.iv.prol
  %29 = load double, ptr %28, align 8, !tbaa !11
  %30 = fadd double %27, %29
  store double %30, ptr %28, align 8, !tbaa !11
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, 2
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !13

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol
  br i1 %found.conflict.not, label %.loopexit, label %scalar.ph

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next.1, %vector.body ], [ 0, %vector.memcheck ]
  %31 = getelementptr inbounds [154 x double], ptr %24, i64 0, i64 %index
  %32 = getelementptr inbounds i8, ptr %31, i64 16
  %wide.load = load <2 x double>, ptr %31, align 8, !tbaa !11, !alias.scope !15
  %wide.load17 = load <2 x double>, ptr %32, align 8, !tbaa !11, !alias.scope !15
  %33 = getelementptr inbounds [154 x double], ptr %25, i64 0, i64 %index
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  %wide.load18 = load <2 x double>, ptr %33, align 8, !tbaa !11, !alias.scope !18, !noalias !15
  %wide.load19 = load <2 x double>, ptr %34, align 8, !tbaa !11, !alias.scope !18, !noalias !15
  %35 = fadd <2 x double> %wide.load, %wide.load18
  %36 = fadd <2 x double> %wide.load17, %wide.load19
  store <2 x double> %35, ptr %33, align 8, !tbaa !11, !alias.scope !18, !noalias !15
  store <2 x double> %36, ptr %34, align 8, !tbaa !11, !alias.scope !18, !noalias !15
  %index.next = or disjoint i64 %index, 4
  %37 = getelementptr inbounds [154 x double], ptr %24, i64 0, i64 %index.next
  %38 = getelementptr inbounds i8, ptr %37, i64 16
  %wide.load.1 = load <2 x double>, ptr %37, align 8, !tbaa !11, !alias.scope !15
  %wide.load17.1 = load <2 x double>, ptr %38, align 8, !tbaa !11, !alias.scope !15
  %39 = getelementptr inbounds [154 x double], ptr %25, i64 0, i64 %index.next
  %40 = getelementptr inbounds i8, ptr %39, i64 16
  %wide.load18.1 = load <2 x double>, ptr %39, align 8, !tbaa !11, !alias.scope !18, !noalias !15
  %wide.load19.1 = load <2 x double>, ptr %40, align 8, !tbaa !11, !alias.scope !18, !noalias !15
  %41 = fadd <2 x double> %wide.load.1, %wide.load18.1
  %42 = fadd <2 x double> %wide.load17.1, %wide.load19.1
  store <2 x double> %41, ptr %39, align 8, !tbaa !11, !alias.scope !18, !noalias !15
  store <2 x double> %42, ptr %40, align 8, !tbaa !11, !alias.scope !18, !noalias !15
  %index.next.1 = add nuw nsw i64 %index, 8
  %43 = icmp eq i64 %index.next.1, 152
  br i1 %43, label %scalar.ph.prol.preheader, label %vector.body, !llvm.loop !20

.loopexit:                                        ; preds = %scalar.ph, %scalar.ph.prol.loopexit
  ret void

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.next.prol, %scalar.ph.prol.loopexit ]
  %44 = getelementptr inbounds [154 x double], ptr %24, i64 0, i64 %indvars.iv
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = getelementptr inbounds [154 x double], ptr %25, i64 0, i64 %indvars.iv
  %47 = load double, ptr %46, align 8, !tbaa !11
  %48 = fadd double %45, %47
  store double %48, ptr %46, align 8, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %49 = getelementptr inbounds [154 x double], ptr %24, i64 0, i64 %indvars.iv.next
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds [154 x double], ptr %25, i64 0, i64 %indvars.iv.next
  %52 = load double, ptr %51, align 8, !tbaa !11
  %53 = fadd double %50, %52
  store double %53, ptr %51, align 8, !tbaa !11
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %54 = getelementptr inbounds [154 x double], ptr %24, i64 0, i64 %indvars.iv.next.1
  %55 = load double, ptr %54, align 8, !tbaa !11
  %56 = getelementptr inbounds [154 x double], ptr %25, i64 0, i64 %indvars.iv.next.1
  %57 = load double, ptr %56, align 8, !tbaa !11
  %58 = fadd double %55, %57
  store double %58, ptr %56, align 8, !tbaa !11
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %59 = getelementptr inbounds [154 x double], ptr %24, i64 0, i64 %indvars.iv.next.2
  %60 = load double, ptr %59, align 8, !tbaa !11
  %61 = getelementptr inbounds [154 x double], ptr %25, i64 0, i64 %indvars.iv.next.2
  %62 = load double, ptr %61, align 8, !tbaa !11
  %63 = fadd double %60, %62
  store double %63, ptr %61, align 8, !tbaa !11
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 154
  br i1 %exitcond.not.3, label %.loopexit, label %scalar.ph, !llvm.loop !24
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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 = !{!"_ZTSN7leveldb9HistogramE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !8, i64 40}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 32}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = !{!16}
!16 = distinct !{!16, !17}
!17 = distinct !{!17, !"LVerDomain"}
!18 = !{!19}
!19 = distinct !{!19, !17}
!20 = distinct !{!20, !21, !22, !23}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = distinct !{!24, !21, !22}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass