; LLVM IR from aspuru-guzik-group/qtorch :: nlopt-2.4.2/stogo/linalg.ll (Z4axpydRK7RVectorS1_)

; 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.RVector = type { i32, ptr }

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

20:                                               ; preds = %37, %3
  %21 = load i32, ptr %10, align 4, !tbaa !15
  %22 = load i32, ptr %9, align 4, !tbaa !15
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %40

25:                                               ; preds = %20
  %26 = load double, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !9
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !9
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = call double @llvm.fmuladd.f64(double %26, double %28, double %30)
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  store double %31, ptr %32, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !9
  %34 = getelementptr inbounds double, ptr %33, i32 1
  store ptr %34, ptr %7, align 8, !tbaa !9
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = getelementptr inbounds double, ptr %35, i32 1
  store ptr %36, ptr %8, align 8, !tbaa !9
  br label %37

37:                                               ; preds = %25
  %38 = load i32, ptr %10, align 4, !tbaa !15
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %10, align 4, !tbaa !15
  br label %20, !llvm.loop !16

40:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS7RVector", !13, i64 0, !10, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 0}
!15 = !{!13, !13, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z4axpydRK7RVectorS1_(double noundef %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %1, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %2) local_unnamed_addr #1 {
  %4 = load i32, ptr %1, align 8, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = zext nneg i32 %4 to i64
  %min.iters.check = icmp ult i32 %4, 8
  br i1 %min.iters.check, label %.lr.ph.preheader28, label %vector.memcheck

.lr.ph.preheader28:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %.015.ph = phi i32 [ 0, %vector.memcheck ], [ 0, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.01114.ph = phi ptr [ %9, %vector.memcheck ], [ %9, %.lr.ph.preheader ], [ %ind.end17, %middle.block ]
  %.01213.ph = phi ptr [ %7, %vector.memcheck ], [ %7, %.lr.ph.preheader ], [ %ind.end19, %middle.block ]
  %11 = sub i32 %4, %.015.ph
  %xtraiter = and i32 %11, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader28, %.lr.ph.prol
  %.015.prol = phi i32 [ %17, %.lr.ph.prol ], [ %.015.ph, %.lr.ph.preheader28 ]
  %.01114.prol = phi ptr [ %15, %.lr.ph.prol ], [ %.01114.ph, %.lr.ph.preheader28 ]
  %.01213.prol = phi ptr [ %16, %.lr.ph.prol ], [ %.01213.ph, %.lr.ph.preheader28 ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader28 ]
  %12 = load double, ptr %.01114.prol, align 8, !tbaa !12
  %13 = load double, ptr %.01213.prol, align 8, !tbaa !12
  %14 = tail call double @llvm.fmuladd.f64(double %0, double %12, double %13)
  store double %14, ptr %.01213.prol, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %.01114.prol, i64 8
  %16 = getelementptr inbounds i8, ptr %.01213.prol, i64 8
  %17 = add nuw nsw i32 %.015.prol, 1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !14

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader28
  %.015.unr = phi i32 [ %.015.ph, %.lr.ph.preheader28 ], [ %17, %.lr.ph.prol ]
  %.01114.unr = phi ptr [ %.01114.ph, %.lr.ph.preheader28 ], [ %15, %.lr.ph.prol ]
  %.01213.unr = phi ptr [ %.01213.ph, %.lr.ph.preheader28 ], [ %16, %.lr.ph.prol ]
  %18 = sub i32 %.015.ph, %4
  %19 = icmp ugt i32 %18, -4
  br i1 %19, label %._crit_edge, label %.lr.ph

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %20 = add nsw i32 %4, -1
  %21 = zext i32 %20 to i64
  %22 = shl nuw nsw i64 %21, 3
  %23 = add nuw nsw i64 %22, 8
  %scevgep = getelementptr i8, ptr %7, i64 %23
  %scevgep16 = getelementptr i8, ptr %9, i64 %23
  %bound0 = icmp ult ptr %7, %scevgep16
  %bound1 = icmp ult ptr %9, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.preheader28, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %10, 2147483644
  %ind.end = trunc nuw nsw i64 %n.vec to i32
  %24 = shl nuw nsw i64 %n.vec, 3
  %ind.end17 = getelementptr i8, ptr %9, i64 %24
  %25 = shl nuw nsw i64 %n.vec, 3
  %ind.end19 = getelementptr i8, ptr %7, i64 %25
  %broadcast.splatinsert = insertelement <2 x double> poison, double %0, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 3
  %next.gep = getelementptr i8, ptr %9, i64 %offset.idx
  %offset.idx22 = shl i64 %index, 3
  %next.gep23 = getelementptr i8, ptr %7, i64 %offset.idx22
  %26 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <2 x double>, ptr %next.gep, align 8, !tbaa !12, !alias.scope !16
  %wide.load25 = load <2 x double>, ptr %26, align 8, !tbaa !12, !alias.scope !16
  %27 = getelementptr i8, ptr %next.gep23, i64 16
  %wide.load26 = load <2 x double>, ptr %next.gep23, align 8, !tbaa !12, !alias.scope !19, !noalias !16
  %wide.load27 = load <2 x double>, ptr %27, align 8, !tbaa !12, !alias.scope !19, !noalias !16
  %28 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat, <2 x double> %wide.load, <2 x double> %wide.load26)
  %29 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat, <2 x double> %wide.load25, <2 x double> %wide.load27)
  store <2 x double> %28, ptr %next.gep23, align 8, !tbaa !12, !alias.scope !19, !noalias !16
  store <2 x double> %29, ptr %27, align 8, !tbaa !12, !alias.scope !19, !noalias !16
  %index.next = add nuw i64 %index, 4
  %30 = icmp eq i64 %index.next, %n.vec
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !21

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %10
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader28

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %3
  ret void

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.015 = phi i32 [ %51, %.lr.ph ], [ %.015.unr, %.lr.ph.prol.loopexit ]
  %.01114 = phi ptr [ %49, %.lr.ph ], [ %.01114.unr, %.lr.ph.prol.loopexit ]
  %.01213 = phi ptr [ %50, %.lr.ph ], [ %.01213.unr, %.lr.ph.prol.loopexit ]
  %31 = load double, ptr %.01114, align 8, !tbaa !12
  %32 = load double, ptr %.01213, align 8, !tbaa !12
  %33 = tail call double @llvm.fmuladd.f64(double %0, double %31, double %32)
  store double %33, ptr %.01213, align 8, !tbaa !12
  %34 = getelementptr inbounds i8, ptr %.01114, i64 8
  %35 = getelementptr inbounds i8, ptr %.01213, i64 8
  %36 = load double, ptr %34, align 8, !tbaa !12
  %37 = load double, ptr %35, align 8, !tbaa !12
  %38 = tail call double @llvm.fmuladd.f64(double %0, double %36, double %37)
  store double %38, ptr %35, align 8, !tbaa !12
  %39 = getelementptr inbounds i8, ptr %.01114, i64 16
  %40 = getelementptr inbounds i8, ptr %.01213, i64 16
  %41 = load double, ptr %39, align 8, !tbaa !12
  %42 = load double, ptr %40, align 8, !tbaa !12
  %43 = tail call double @llvm.fmuladd.f64(double %0, double %41, double %42)
  store double %43, ptr %40, align 8, !tbaa !12
  %44 = getelementptr inbounds i8, ptr %.01114, i64 24
  %45 = getelementptr inbounds i8, ptr %.01213, i64 24
  %46 = load double, ptr %44, align 8, !tbaa !12
  %47 = load double, ptr %45, align 8, !tbaa !12
  %48 = tail call double @llvm.fmuladd.f64(double %0, double %46, double %47)
  store double %48, ptr %45, align 8, !tbaa !12
  %49 = getelementptr inbounds i8, ptr %.01114, i64 32
  %50 = getelementptr inbounds i8, ptr %.01213, i64 32
  %51 = add nuw nsw i32 %.015, 4
  %exitcond.not.3 = icmp eq i32 %51, %4
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !25
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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