; LLVM IR from AdaptiveCpp/AdaptiveCpp :: src/runtime/cuda (cuda_backend)

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

@.str = external hidden unnamed_addr constant [91 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [51 x i8], align 1
@__PRETTY_FUNCTION__._ZNK7hipsycl2rt12cuda_backend13get_allocatorENS0_9device_idE = external hidden unnamed_addr constant [85 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK7hipsycl2rt12cuda_backend13get_allocatorENS0_9device_idE(ptr noundef nonnull align 8 dereferenceable(136) %0, i64 %1, i64 %2) unnamed_addr #0 align 2 {
  %4 = alloca %"class.hipsycl::rt::device_id", align 4
  %5 = alloca ptr, align 8
  %6 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 0
  store i64 %1, ptr %6, align 4
  %7 = getelementptr inbounds { i64, i64 }, ptr %4, i32 0, i32 1
  store i64 %2, ptr %7, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8
  %9 = call noundef i32 @_ZNK7hipsycl2rt9device_id11get_backendEv(ptr noundef nonnull align 4 dereferenceable(16) %4)
  %10 = load ptr, ptr %8, align 8, !tbaa !9
  %11 = getelementptr inbounds ptr, ptr %10, i64 2
  %12 = load ptr, ptr %11, align 8
  %13 = call noundef i32 %12(ptr noundef nonnull align 8 dereferenceable(136) %8)
  %14 = icmp eq i32 %9, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  br label %18

16:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str, i32 noundef 79, ptr noundef @__PRETTY_FUNCTION__._ZNK7hipsycl2rt12cuda_backend13get_allocatorENS0_9device_idE) #3
  unreachable

17:                                               ; No predecessors!
  br label %18

18:                                               ; preds = %17, %15
  %19 = load ptr, ptr %8, align 8, !tbaa !9
  %20 = getelementptr inbounds ptr, ptr %19, i64 3
  %21 = load ptr, ptr %20, align 8
  %22 = call noundef ptr %21(ptr noundef nonnull align 8 dereferenceable(136) %8)
  %23 = call noundef i32 @_ZNK7hipsycl2rt9device_id6get_idEv(ptr noundef nonnull align 4 dereferenceable(16) %4)
  %24 = sext i32 %23 to i64
  %25 = load ptr, ptr %22, align 8, !tbaa !9
  %26 = getelementptr inbounds ptr, ptr %25, i64 2
  %27 = load ptr, ptr %26, align 8
  %28 = call noundef ptr %27(ptr noundef nonnull align 8 dereferenceable(8) %22, i64 noundef %24)
  %29 = call noundef ptr @_ZNK7hipsycl2rt21cuda_hardware_context13get_allocatorEv(ptr noundef nonnull align 8 dereferenceable(36) %28)
  ret ptr %29
}

declare noundef i32 @_ZNK7hipsycl2rt9device_id11get_backendEv(ptr noundef nonnull align 4 dereferenceable(16)) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare noundef i32 @_ZNK7hipsycl2rt9device_id6get_idEv(ptr noundef nonnull align 4 dereferenceable(16)) #1

declare noundef ptr @_ZNK7hipsycl2rt21cuda_hardware_context13get_allocatorEv(ptr noundef nonnull align 8 dereferenceable(36)) #1

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 = { "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 = { noreturn nounwind "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 = { noreturn 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 = !{!"vtable pointer", !8, 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::device_id" = type { %"struct.hipsycl::rt::backend_descriptor", i32 }
%"struct.hipsycl::rt::backend_descriptor" = type { i32, i32, i32 }

@.str = external hidden unnamed_addr constant [91 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [51 x i8], align 1
@__PRETTY_FUNCTION__._ZNK7hipsycl2rt12cuda_backend13get_allocatorENS0_9device_idE = external hidden unnamed_addr constant [85 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK7hipsycl2rt12cuda_backend13get_allocatorENS0_9device_idE(ptr noundef nonnull align 8 dereferenceable(136) %0, i64 %1, i64 %2) unnamed_addr #0 align 2 {
  %4 = alloca %"class.hipsycl::rt::device_id", align 8
  store i64 %1, ptr %4, align 8
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  store i64 %2, ptr %5, align 8
  %6 = call noundef i32 @_ZNK7hipsycl2rt9device_id11get_backendEv(ptr noundef nonnull align 4 dereferenceable(16) %4)
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %9 = load ptr, ptr %8, align 8
  %10 = call noundef i32 %9(ptr noundef nonnull align 8 dereferenceable(136) %0)
  %11 = icmp eq i32 %6, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %3
  call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str, i32 noundef 79, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK7hipsycl2rt12cuda_backend13get_allocatorENS0_9device_idE) #3
  unreachable

13:                                               ; preds = %3
  %14 = load ptr, ptr %0, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 24
  %16 = load ptr, ptr %15, align 8
  %17 = call noundef ptr %16(ptr noundef nonnull align 8 dereferenceable(136) %0)
  %18 = call noundef i32 @_ZNK7hipsycl2rt9device_id6get_idEv(ptr noundef nonnull align 4 dereferenceable(16) %4)
  %19 = sext i32 %18 to i64
  %20 = load ptr, ptr %17, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %22 = load ptr, ptr %21, align 8
  %23 = call noundef ptr %22(ptr noundef nonnull align 8 dereferenceable(8) %17, i64 noundef %19)
  %24 = call noundef ptr @_ZNK7hipsycl2rt21cuda_hardware_context13get_allocatorEv(ptr noundef nonnull align 8 dereferenceable(36) %23)
  ret ptr %24
}

declare noundef i32 @_ZNK7hipsycl2rt9device_id11get_backendEv(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare noundef i32 @_ZNK7hipsycl2rt9device_id6get_idEv(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #1

declare noundef ptr @_ZNK7hipsycl2rt21cuda_hardware_context13get_allocatorEv(ptr noundef nonnull align 8 dereferenceable(36)) local_unnamed_addr #1

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 = { "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 = { noreturn nounwind "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 = { noreturn 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InstCombinePass,SROAPass,SimplifyCFGPass