; LLVM IR from AdaptiveCpp/AdaptiveCpp :: src/runtime/hw_model (memcpy)

; 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.hipsycl::rt::static_array" = type { %"struct.std::array" }
%"struct.std::array" = type { [3 x i64] }
%"class.hipsycl::rt::memory_location" = type { %"class.hipsycl::rt::device_id", %"class.hipsycl::rt::static_array", %"class.hipsycl::rt::static_array", i64, i8, ptr, %"class.std::shared_ptr" }
%"class.hipsycl::rt::device_id" = type { %"struct.hipsycl::rt::backend_descriptor", i32 }
%"struct.hipsycl::rt::backend_descriptor" = type { i32, i32, i32 }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZNK7hipsycl2rt12memcpy_model21estimate_runtime_costERKNS0_15memory_locationES4_NS0_12static_arrayILi3EEE(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(104), ptr noundef byval(%"class.hipsycl::rt::static_array") align 8) #0 align 2

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK7hipsycl2rt12memcpy_model13choose_sourceERKSt6vectorINS0_15memory_locationESaIS3_EERKS3_NS0_12static_arrayILi3EEE(ptr dead_on_unwind noalias writable sret(%"class.hipsycl::rt::memory_location") align 8 %0, ptr noundef nonnull align 1 dereferenceable(1) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(104) %3, ptr noundef byval(%"class.hipsycl::rt::static_array") align 8 %4) #0 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca double, align 8
  %12 = alloca i64, align 8
  %13 = alloca double, align 8
  %14 = alloca %"class.hipsycl::rt::static_array", align 8
  store ptr %0, ptr %6, align 8
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store i64 0, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %16 = call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #5
  store double %16, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %36, %5
  %18 = load i64, ptr %12, align 8, !tbaa !9
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = call noundef i64 @_ZNKSt6vectorIN7hipsycl2rt15memory_locationESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %19) #5
  %21 = icmp ult i64 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %39

23:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = load i64, ptr %12, align 8, !tbaa !9
  %26 = call noundef nonnull align 8 dereferenceable(104) ptr @_ZNKSt6vectorIN7hipsycl2rt15memory_locationESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %24, i64 noundef %25) #5
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %14, ptr align 8 %4, i64 24, i1 false), !tbaa.struct !13
  %28 = call noundef double @_ZNK7hipsycl2rt12memcpy_model21estimate_runtime_costERKNS0_15memory_locationES4_NS0_12static_arrayILi3EEE(ptr noundef nonnull align 1 dereferenceable(1) %15, ptr noundef nonnull align 8 dereferenceable(104) %26, ptr noundef nonnull align 8 dereferenceable(104) %27, ptr noundef byval(%"class.hipsycl::rt::static_array") align 8 %14)
  store double %28, ptr %13, align 8, !tbaa !11
  %29 = load double, ptr %13, align 8, !tbaa !11
  %30 = load double, ptr %11, align 8, !tbaa !11
  %31 = fcmp olt double %29, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %23
  %33 = load double, ptr %13, align 8, !tbaa !11
  store double %33, ptr %11, align 8, !tbaa !11
  %34 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %34, ptr %10, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %32, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  br label %36

36:                                               ; preds = %35
  %37 = load i64, ptr %12, align 8, !tbaa !9
  %38 = add i64 %37, 1
  store i64 %38, ptr %12, align 8, !tbaa !9
  br label %17, !llvm.loop !15

39:                                               ; preds = %22
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i64, ptr %10, align 8, !tbaa !9
  %42 = call noundef nonnull align 8 dereferenceable(104) ptr @_ZNKSt6vectorIN7hipsycl2rt15memory_locationESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %40, i64 noundef %41) #5
  call void @_ZN7hipsycl2rt15memory_locationC2ERKS1_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(104) %42) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNSt14numeric_limitsIdE3maxEv() #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIN7hipsycl2rt15memory_locationESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(104) ptr @_ZNKSt6vectorIN7hipsycl2rt15memory_locationESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN7hipsycl2rt15memory_locationC2ERKS1_(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(104)) unnamed_addr #4 align 2

attributes #0 = { mustprogress 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 nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { inlinehint 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 #5 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{i64 0, i64 24, !14}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

%"class.hipsycl::rt::static_array" = type { %"struct.std::array" }
%"struct.std::array" = type { [3 x i64] }
%"class.hipsycl::rt::memory_location" = type { %"class.hipsycl::rt::device_id", %"class.hipsycl::rt::static_array", %"class.hipsycl::rt::static_array", i64, i8, ptr, %"class.std::shared_ptr" }
%"class.hipsycl::rt::device_id" = type { %"struct.hipsycl::rt::backend_descriptor", i32 }
%"struct.hipsycl::rt::backend_descriptor" = type { i32, i32, i32 }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZNK7hipsycl2rt12memcpy_model21estimate_runtime_costERKNS0_15memory_locationES4_NS0_12static_arrayILi3EEE(ptr noundef nonnull align 1 dereferenceable(1), ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(104), ptr noundef byval(%"class.hipsycl::rt::static_array") align 8) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK7hipsycl2rt12memcpy_model13choose_sourceERKSt6vectorINS0_15memory_locationESaIS3_EERKS3_NS0_12static_arrayILi3EEE(ptr dead_on_unwind noalias writable sret(%"class.hipsycl::rt::memory_location") align 8 %0, ptr noundef nonnull align 1 dereferenceable(1) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(104) %3, ptr nocapture noundef readonly byval(%"class.hipsycl::rt::static_array") align 8 %4) local_unnamed_addr #0 align 2 {
  %6 = tail call noundef double @_ZNSt14numeric_limitsIdE3maxEv() #3
  %7 = tail call noundef i64 @_ZNKSt6vectorIN7hipsycl2rt15memory_locationESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %2) #3
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.0.lcssa = phi i64 [ 0, %5 ], [ %.1, %.lr.ph ]
  %8 = tail call noundef nonnull align 8 dereferenceable(104) ptr @_ZNKSt6vectorIN7hipsycl2rt15memory_locationESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef %.0.lcssa) #3
  tail call void @_ZN7hipsycl2rt15memory_locationC2ERKS1_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef nonnull align 8 dereferenceable(104) %8) #3
  ret void

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.018 = phi i64 [ %.1, %.lr.ph ], [ 0, %5 ]
  %.01217 = phi i64 [ %12, %.lr.ph ], [ 0, %5 ]
  %.01316 = phi double [ %.114, %.lr.ph ], [ %6, %5 ]
  %9 = tail call noundef nonnull align 8 dereferenceable(104) ptr @_ZNKSt6vectorIN7hipsycl2rt15memory_locationESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef %.01217) #3
  %10 = tail call noundef double @_ZNK7hipsycl2rt12memcpy_model21estimate_runtime_costERKNS0_15memory_locationES4_NS0_12static_arrayILi3EEE(ptr noundef nonnull align 1 dereferenceable(1) %1, ptr noundef nonnull align 8 dereferenceable(104) %9, ptr noundef nonnull align 8 dereferenceable(104) %3, ptr noundef nonnull byval(%"class.hipsycl::rt::static_array") align 8 %4)
  %11 = fcmp olt double %10, %.01316
  %.114 = select i1 %11, double %10, double %.01316
  %.1 = select i1 %11, i64 %.01217, i64 %.018
  %12 = add nuw i64 %.01217, 1
  %13 = tail call noundef i64 @_ZNKSt6vectorIN7hipsycl2rt15memory_locationESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %2) #3
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !5
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNSt14numeric_limitsIdE3maxEv() local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIN7hipsycl2rt15memory_locationESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(104) ptr @_ZNKSt6vectorIN7hipsycl2rt15memory_locationESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN7hipsycl2rt15memory_locationC2ERKS1_(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef nonnull align 8 dereferenceable(104)) unnamed_addr #2 align 2

attributes #0 = { mustprogress 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 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 = { inlinehint 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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