; 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::device_id" = type { %"struct.hipsycl::rt::backend_descriptor", i32 }
%"struct.hipsycl::rt::backend_descriptor" = type { i32, i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK7hipsycl2rt12memcpy_model21estimate_runtime_costERKNS0_15memory_locationES4_NS0_12static_arrayILi3EEE(ptr noundef nonnull align 1 dereferenceable(1) %0, ptr noundef nonnull align 8 dereferenceable(104) %1, ptr noundef nonnull align 8 dereferenceable(104) %2, ptr noundef byval(%"class.hipsycl::rt::static_array") align 8 %3) #0 align 2 {
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %"class.hipsycl::rt::device_id", align 4
  %10 = alloca %"class.hipsycl::rt::device_id", align 4
  %11 = alloca %"struct.hipsycl::rt::backend_descriptor", align 4
  %12 = alloca %"class.hipsycl::rt::device_id", align 4
  %13 = alloca { i64, i32 }, align 8
  %14 = alloca %"struct.hipsycl::rt::backend_descriptor", align 4
  %15 = alloca %"class.hipsycl::rt::device_id", align 4
  %16 = alloca { i64, i32 }, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = call { i64, i64 } @_ZNK7hipsycl2rt15memory_location10get_deviceEv(ptr noundef nonnull align 8 dereferenceable(104) %18)
  %20 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  %21 = extractvalue { i64, i64 } %19, 0
  store i64 %21, ptr %20, align 4
  %22 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  %23 = extractvalue { i64, i64 } %19, 1
  store i64 %23, ptr %22, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = call { i64, i64 } @_ZNK7hipsycl2rt15memory_location10get_deviceEv(ptr noundef nonnull align 8 dereferenceable(104) %24)
  %26 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 0
  %27 = extractvalue { i64, i64 } %25, 0
  store i64 %27, ptr %26, align 4
  %28 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 1
  %29 = extractvalue { i64, i64 } %25, 1
  store i64 %29, ptr %28, align 4
  %30 = call noundef zeroext i1 @_ZN7hipsycl2rteqERKNS0_9device_idES3_(ptr noundef nonnull align 4 dereferenceable(16) %9, ptr noundef nonnull align 4 dereferenceable(16) %10)
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  br i1 %30, label %31, label %32

31:                                               ; preds = %4
  store double 1.000000e+00, ptr %5, align 8
  br label %54

32:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 12, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = call { i64, i64 } @_ZNK7hipsycl2rt15memory_location10get_deviceEv(ptr noundef nonnull align 8 dereferenceable(104) %33)
  %35 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 0
  %36 = extractvalue { i64, i64 } %34, 0
  store i64 %36, ptr %35, align 4
  %37 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 1
  %38 = extractvalue { i64, i64 } %34, 1
  store i64 %38, ptr %37, align 4
  %39 = call { i64, i32 } @_ZNK7hipsycl2rt9device_id27get_full_backend_descriptorEv(ptr noundef nonnull align 4 dereferenceable(16) %12)
  store { i64, i32 } %39, ptr %13, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 8 %13, i64 12, i1 false)
  %40 = getelementptr inbounds %"struct.hipsycl::rt::backend_descriptor", ptr %11, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 12, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #4
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = call { i64, i64 } @_ZNK7hipsycl2rt15memory_location10get_deviceEv(ptr noundef nonnull align 8 dereferenceable(104) %42)
  %44 = getelementptr inbounds { i64, i64 }, ptr %15, i32 0, i32 0
  %45 = extractvalue { i64, i64 } %43, 0
  store i64 %45, ptr %44, align 4
  %46 = getelementptr inbounds { i64, i64 }, ptr %15, i32 0, i32 1
  %47 = extractvalue { i64, i64 } %43, 1
  store i64 %47, ptr %46, align 4
  %48 = call { i64, i32 } @_ZNK7hipsycl2rt9device_id27get_full_backend_descriptorEv(ptr noundef nonnull align 4 dereferenceable(16) %15)
  store { i64, i32 } %48, ptr %16, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 8 %16, i64 12, i1 false)
  %49 = getelementptr inbounds %"struct.hipsycl::rt::backend_descriptor", ptr %14, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = icmp eq i32 %41, %50
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %11) #4
  br i1 %51, label %52, label %53

52:                                               ; preds = %32
  store double 2.000000e+00, ptr %5, align 8
  br label %54

53:                                               ; preds = %32
  store double 3.000000e+00, ptr %5, align 8
  br label %54

54:                                               ; preds = %53, %52, %31
  %55 = load double, ptr %5, align 8
  ret double %55
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN7hipsycl2rteqERKNS0_9device_idES3_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare { i64, i64 } @_ZNK7hipsycl2rt15memory_location10get_deviceEv(ptr noundef nonnull align 8 dereferenceable(104)) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare { i64, i32 } @_ZNK7hipsycl2rt9device_id27get_full_backend_descriptorEv(ptr noundef nonnull align 4 dereferenceable(16)) #2

; 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) #3

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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !12, i64 4}
!10 = !{!"_ZTSN7hipsycl2rt18backend_descriptorE", !11, i64 0, !12, i64 4, !13, i64 8}
!11 = !{!"_ZTSN7hipsycl2rt10backend_idE", !7, i64 0}
!12 = !{!"_ZTSN7hipsycl2rt17hardware_platformE", !7, i64 0}
!13 = !{!"_ZTSN7hipsycl2rt12api_platformE", !7, i64 0}


; 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::device_id" = type { %"struct.hipsycl::rt::backend_descriptor", i32 }
%"struct.hipsycl::rt::backend_descriptor" = type { i32, i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK7hipsycl2rt12memcpy_model21estimate_runtime_costERKNS0_15memory_locationES4_NS0_12static_arrayILi3EEE(ptr nocapture noundef nonnull readnone align 1 dereferenceable(1) %0, ptr noundef nonnull align 8 dereferenceable(104) %1, ptr noundef nonnull align 8 dereferenceable(104) %2, ptr nocapture noundef readnone byval(%"class.hipsycl::rt::static_array") align 8 %3) local_unnamed_addr #0 align 2 {
  %5 = alloca %"class.hipsycl::rt::device_id", align 8
  %6 = alloca %"class.hipsycl::rt::device_id", align 8
  %7 = alloca %"class.hipsycl::rt::device_id", align 8
  %8 = alloca %"class.hipsycl::rt::device_id", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  %9 = tail call { i64, i64 } @_ZNK7hipsycl2rt15memory_location10get_deviceEv(ptr noundef nonnull align 8 dereferenceable(104) %1)
  %10 = extractvalue { i64, i64 } %9, 0
  store i64 %10, ptr %5, align 8
  %11 = getelementptr inbounds i8, ptr %5, i64 8
  %12 = extractvalue { i64, i64 } %9, 1
  store i64 %12, ptr %11, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #3
  %13 = tail call { i64, i64 } @_ZNK7hipsycl2rt15memory_location10get_deviceEv(ptr noundef nonnull align 8 dereferenceable(104) %2)
  %14 = extractvalue { i64, i64 } %13, 0
  store i64 %14, ptr %6, align 8
  %15 = getelementptr inbounds i8, ptr %6, i64 8
  %16 = extractvalue { i64, i64 } %13, 1
  store i64 %16, ptr %15, align 8
  %17 = call noundef zeroext i1 @_ZN7hipsycl2rteqERKNS0_9device_idES3_(ptr noundef nonnull align 4 dereferenceable(16) %5, ptr noundef nonnull align 4 dereferenceable(16) %6)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  br i1 %17, label %30, label %18

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #3
  %19 = call { i64, i64 } @_ZNK7hipsycl2rt15memory_location10get_deviceEv(ptr noundef nonnull align 8 dereferenceable(104) %1)
  %20 = extractvalue { i64, i64 } %19, 0
  store i64 %20, ptr %7, align 8
  %21 = getelementptr inbounds i8, ptr %7, i64 8
  %22 = extractvalue { i64, i64 } %19, 1
  store i64 %22, ptr %21, align 8
  %23 = call { i64, i32 } @_ZNK7hipsycl2rt9device_id27get_full_backend_descriptorEv(ptr noundef nonnull align 4 dereferenceable(16) %7)
  %.fca.0.extract2 = extractvalue { i64, i32 } %23, 0
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #3
  %24 = call { i64, i64 } @_ZNK7hipsycl2rt15memory_location10get_deviceEv(ptr noundef nonnull align 8 dereferenceable(104) %2)
  %25 = extractvalue { i64, i64 } %24, 0
  store i64 %25, ptr %8, align 8
  %26 = getelementptr inbounds i8, ptr %8, i64 8
  %27 = extractvalue { i64, i64 } %24, 1
  store i64 %27, ptr %26, align 8
  %28 = call { i64, i32 } @_ZNK7hipsycl2rt9device_id27get_full_backend_descriptorEv(ptr noundef nonnull align 4 dereferenceable(16) %8)
  %.fca.0.extract = extractvalue { i64, i32 } %28, 0
  %.unshifted = xor i64 %.fca.0.extract, %.fca.0.extract2
  %29 = icmp ult i64 %.unshifted, 4294967296
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #3
  %. = select i1 %29, double 2.000000e+00, double 3.000000e+00
  br label %30

30:                                               ; preds = %18, %4
  %.0 = phi double [ 1.000000e+00, %4 ], [ %., %18 ]
  ret double %.0
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN7hipsycl2rteqERKNS0_9device_idES3_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare { i64, i64 } @_ZNK7hipsycl2rt15memory_location10get_deviceEv(ptr noundef nonnull align 8 dereferenceable(104)) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare { i64, i32 } @_ZNK7hipsycl2rt9device_id27get_full_backend_descriptorEv(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass