; LLVM IR from junhyeokahn/PyPnC :: pnc/planner/locomotion/towr_plus/src (atlas_crbi_helper)

; 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: nounwind uwtable
define dso_local void @atlas_crbi_helper_copy(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %41

10:                                               ; preds = %3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %28

13:                                               ; preds = %10
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %24, %13
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = icmp slt i64 %15, %16
  br i1 %17, label %18, label %27

18:                                               ; preds = %14
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %19, i32 1
  store ptr %20, ptr %4, align 8, !tbaa !5
  %21 = load double, ptr %19, align 8, !tbaa !11
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds double, ptr %22, i32 1
  store ptr %23, ptr %6, align 8, !tbaa !5
  store double %21, ptr %22, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %18
  %25 = load i64, ptr %7, align 8, !tbaa !9
  %26 = add nsw i64 %25, 1
  store i64 %26, ptr %7, align 8, !tbaa !9
  br label %14, !llvm.loop !13

27:                                               ; preds = %14
  br label %40

28:                                               ; preds = %10
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %36, %28
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = load i64, ptr %5, align 8, !tbaa !9
  %32 = icmp slt i64 %30, %31
  br i1 %32, label %33, label %39

33:                                               ; preds = %29
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds double, ptr %34, i32 1
  store ptr %35, ptr %6, align 8, !tbaa !5
  store double 0.000000e+00, ptr %34, align 8, !tbaa !11
  br label %36

36:                                               ; preds = %33
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = add nsw i64 %37, 1
  store i64 %38, ptr %7, align 8, !tbaa !9
  br label %29, !llvm.loop !15

39:                                               ; preds = %29
  br label %40

40:                                               ; preds = %39, %27
  br label %41

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

; 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

attributes #0 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @atlas_crbi_helper_copy(ptr noundef readonly %0, i64 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = ptrtoint ptr %0 to i64
  %5 = ptrtoint ptr %2 to i64
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %.loopexit, label %6

6:                                                ; preds = %3
  %.not15 = icmp eq ptr %0, null
  %7 = icmp sgt i64 %1, 0
  br i1 %.not15, label %.preheader, label %.preheader16

.preheader16:                                     ; preds = %6
  br i1 %7, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader16
  %min.iters.check = icmp ult i64 %1, 6
  %8 = sub i64 %5, %4
  %diff.check = icmp ult i64 %8, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader33, label %vector.ph

.lr.ph.preheader33:                               ; preds = %middle.block, %.lr.ph.preheader
  %.020.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %.01019.ph = phi ptr [ %2, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.01218.ph = phi ptr [ %0, %.lr.ph.preheader ], [ %ind.end26, %middle.block ]
  %9 = sub nsw i64 %1, %.020.ph
  %xtraiter = and i64 %9, 7
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader33, %.lr.ph.prol
  %.020.prol = phi i64 [ %13, %.lr.ph.prol ], [ %.020.ph, %.lr.ph.preheader33 ]
  %.01019.prol = phi ptr [ %12, %.lr.ph.prol ], [ %.01019.ph, %.lr.ph.preheader33 ]
  %.01218.prol = phi ptr [ %10, %.lr.ph.prol ], [ %.01218.ph, %.lr.ph.preheader33 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader33 ]
  %10 = getelementptr inbounds i8, ptr %.01218.prol, i64 8
  %11 = load double, ptr %.01218.prol, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.01019.prol, i64 8
  store double %11, ptr %.01019.prol, align 8, !tbaa !5
  %13 = add nuw nsw i64 %.020.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !9

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader33
  %.020.unr = phi i64 [ %.020.ph, %.lr.ph.preheader33 ], [ %13, %.lr.ph.prol ]
  %.01019.unr = phi ptr [ %.01019.ph, %.lr.ph.preheader33 ], [ %12, %.lr.ph.prol ]
  %.01218.unr = phi ptr [ %.01218.ph, %.lr.ph.preheader33 ], [ %10, %.lr.ph.prol ]
  %14 = sub nsw i64 %.020.ph, %1
  %15 = icmp ugt i64 %14, -8
  br i1 %15, label %.loopexit, label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %1, 9223372036854775804
  %16 = shl i64 %n.vec, 3
  %ind.end = getelementptr i8, ptr %2, i64 %16
  %17 = shl i64 %n.vec, 3
  %ind.end26 = getelementptr i8, ptr %0, i64 %17
  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 %2, i64 %offset.idx
  %offset.idx29 = shl i64 %index, 3
  %next.gep30 = getelementptr i8, ptr %0, i64 %offset.idx29
  %18 = getelementptr i8, ptr %next.gep30, i64 16
  %wide.load = load <2 x double>, ptr %next.gep30, align 8, !tbaa !5
  %wide.load32 = load <2 x double>, ptr %18, align 8, !tbaa !5
  %19 = getelementptr i8, ptr %next.gep, i64 16
  store <2 x double> %wide.load, ptr %next.gep, align 8, !tbaa !5
  store <2 x double> %wide.load32, ptr %19, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %20 = icmp eq i64 %index.next, %n.vec
  br i1 %20, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %1
  br i1 %cmp.n, label %.loopexit, label %.lr.ph.preheader33

.preheader:                                       ; preds = %6
  br i1 %7, label %.lr.ph23.preheader, label %.loopexit

.lr.ph23.preheader:                               ; preds = %.preheader
  %21 = shl nuw i64 %1, 3
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %2, i8 0, i64 %21, i1 false), !tbaa !5
  br label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.020 = phi i64 [ %46, %.lr.ph ], [ %.020.unr, %.lr.ph.prol.loopexit ]
  %.01019 = phi ptr [ %45, %.lr.ph ], [ %.01019.unr, %.lr.ph.prol.loopexit ]
  %.01218 = phi ptr [ %43, %.lr.ph ], [ %.01218.unr, %.lr.ph.prol.loopexit ]
  %22 = getelementptr inbounds i8, ptr %.01218, i64 8
  %23 = load double, ptr %.01218, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.01019, i64 8
  store double %23, ptr %.01019, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %.01218, i64 16
  %26 = load double, ptr %22, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %.01019, i64 16
  store double %26, ptr %24, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.01218, i64 24
  %29 = load double, ptr %25, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %.01019, i64 24
  store double %29, ptr %27, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %.01218, i64 32
  %32 = load double, ptr %28, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %.01019, i64 32
  store double %32, ptr %30, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %.01218, i64 40
  %35 = load double, ptr %31, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %.01019, i64 40
  store double %35, ptr %33, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %.01218, i64 48
  %38 = load double, ptr %34, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %.01019, i64 48
  store double %38, ptr %36, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %.01218, i64 56
  %41 = load double, ptr %37, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %.01019, i64 56
  store double %41, ptr %39, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %.01218, i64 64
  %44 = load double, ptr %40, align 8, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %.01019, i64 64
  store double %44, ptr %42, align 8, !tbaa !5
  %46 = add nuw nsw i64 %.020, 8
  %exitcond.not.7 = icmp eq i64 %46, %1
  br i1 %exitcond.not.7, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %.lr.ph23.preheader, %.preheader16, %.preheader, %3
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { 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 #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12, !13}


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