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

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

18:                                               ; preds = %29, %2
  %19 = load i32, ptr %8, align 4, !tbaa !13
  %20 = load i32, ptr %7, align 4, !tbaa !13
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %18
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %24, i32 1
  store ptr %25, ptr %5, align 8, !tbaa !5
  %26 = load double, ptr %24, align 8, !tbaa !14
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds double, ptr %27, i32 1
  store ptr %28, ptr %6, align 8, !tbaa !5
  store double %26, ptr %27, align 8, !tbaa !14
  br label %29

29:                                               ; preds = %23
  %30 = load i32, ptr %8, align 4, !tbaa !13
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %8, align 4, !tbaa !13
  br label %18, !llvm.loop !16

32:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  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, !6, i64 8}
!10 = !{!"_ZTS7RVector", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, 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 nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z4copyRK7RVectorS1_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = zext nneg i32 %3 to i64
  %min.iters.check = icmp ult i32 %3, 6
  %10 = ptrtoint ptr %8 to i64
  %11 = ptrtoint ptr %6 to i64
  %12 = sub i64 %11, %10
  %diff.check = icmp ult i64 %12, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %.lr.ph.preheader23, label %vector.ph

.lr.ph.preheader23:                               ; preds = %middle.block, %.lr.ph.preheader
  %.011.ph = phi i32 [ 0, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.0710.ph = phi ptr [ %8, %.lr.ph.preheader ], [ %ind.end12, %middle.block ]
  %.089.ph = phi ptr [ %6, %.lr.ph.preheader ], [ %ind.end14, %middle.block ]
  %13 = sub i32 %3, %.011.ph
  %xtraiter = and i32 %13, 7
  %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.preheader23, %.lr.ph.prol
  %.011.prol = phi i32 [ %17, %.lr.ph.prol ], [ %.011.ph, %.lr.ph.preheader23 ]
  %.0710.prol = phi ptr [ %14, %.lr.ph.prol ], [ %.0710.ph, %.lr.ph.preheader23 ]
  %.089.prol = phi ptr [ %16, %.lr.ph.prol ], [ %.089.ph, %.lr.ph.preheader23 ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader23 ]
  %14 = getelementptr inbounds i8, ptr %.0710.prol, i64 8
  %15 = load double, ptr %.0710.prol, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %.089.prol, i64 8
  store double %15, ptr %.089.prol, align 8, !tbaa !12
  %17 = add nuw nsw i32 %.011.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.preheader23
  %.011.unr = phi i32 [ %.011.ph, %.lr.ph.preheader23 ], [ %17, %.lr.ph.prol ]
  %.0710.unr = phi ptr [ %.0710.ph, %.lr.ph.preheader23 ], [ %14, %.lr.ph.prol ]
  %.089.unr = phi ptr [ %.089.ph, %.lr.ph.preheader23 ], [ %16, %.lr.ph.prol ]
  %18 = sub i32 %.011.ph, %3
  %19 = icmp ugt i32 %18, -8
  br i1 %19, label %._crit_edge, label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %9, 2147483644
  %ind.end = trunc nuw nsw i64 %n.vec to i32
  %20 = shl nuw nsw i64 %n.vec, 3
  %ind.end12 = getelementptr i8, ptr %8, i64 %20
  %21 = shl nuw nsw i64 %n.vec, 3
  %ind.end14 = getelementptr i8, ptr %6, i64 %21
  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 %8, i64 %offset.idx
  %offset.idx17 = shl i64 %index, 3
  %next.gep18 = getelementptr i8, ptr %6, i64 %offset.idx17
  %22 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <2 x double>, ptr %next.gep, align 8, !tbaa !12
  %wide.load20 = load <2 x double>, ptr %22, align 8, !tbaa !12
  %23 = getelementptr i8, ptr %next.gep18, i64 16
  store <2 x double> %wide.load, ptr %next.gep18, align 8, !tbaa !12
  store <2 x double> %wide.load20, ptr %23, align 8, !tbaa !12
  %index.next = add nuw i64 %index, 4
  %24 = icmp eq i64 %index.next, %n.vec
  br i1 %24, label %middle.block, label %vector.body, !llvm.loop !16

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

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

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.011 = phi i32 [ %49, %.lr.ph ], [ %.011.unr, %.lr.ph.prol.loopexit ]
  %.0710 = phi ptr [ %46, %.lr.ph ], [ %.0710.unr, %.lr.ph.prol.loopexit ]
  %.089 = phi ptr [ %48, %.lr.ph ], [ %.089.unr, %.lr.ph.prol.loopexit ]
  %25 = getelementptr inbounds i8, ptr %.0710, i64 8
  %26 = load double, ptr %.0710, align 8, !tbaa !12
  %27 = getelementptr inbounds i8, ptr %.089, i64 8
  store double %26, ptr %.089, align 8, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %.0710, i64 16
  %29 = load double, ptr %25, align 8, !tbaa !12
  %30 = getelementptr inbounds i8, ptr %.089, i64 16
  store double %29, ptr %27, align 8, !tbaa !12
  %31 = getelementptr inbounds i8, ptr %.0710, i64 24
  %32 = load double, ptr %28, align 8, !tbaa !12
  %33 = getelementptr inbounds i8, ptr %.089, i64 24
  store double %32, ptr %30, align 8, !tbaa !12
  %34 = getelementptr inbounds i8, ptr %.0710, i64 32
  %35 = load double, ptr %31, align 8, !tbaa !12
  %36 = getelementptr inbounds i8, ptr %.089, i64 32
  store double %35, ptr %33, align 8, !tbaa !12
  %37 = getelementptr inbounds i8, ptr %.0710, i64 40
  %38 = load double, ptr %34, align 8, !tbaa !12
  %39 = getelementptr inbounds i8, ptr %.089, i64 40
  store double %38, ptr %36, align 8, !tbaa !12
  %40 = getelementptr inbounds i8, ptr %.0710, i64 48
  %41 = load double, ptr %37, align 8, !tbaa !12
  %42 = getelementptr inbounds i8, ptr %.089, i64 48
  store double %41, ptr %39, align 8, !tbaa !12
  %43 = getelementptr inbounds i8, ptr %.0710, i64 56
  %44 = load double, ptr %40, align 8, !tbaa !12
  %45 = getelementptr inbounds i8, ptr %.089, i64 56
  store double %44, ptr %42, align 8, !tbaa !12
  %46 = getelementptr inbounds i8, ptr %.0710, i64 64
  %47 = load double, ptr %43, align 8, !tbaa !12
  %48 = getelementptr inbounds i8, ptr %.089, i64 64
  store double %47, ptr %45, align 8, !tbaa !12
  %49 = add nuw nsw i32 %.011, 8
  %exitcond.not.7 = icmp eq i32 %49, %3
  br i1 %exitcond.not.7, label %._crit_edge, label %.lr.ph, !llvm.loop !20
}

attributes #0 = { 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" }

!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 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !17, !18}


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