; LLVM IR from intel/qpl :: tools/utils/hw_dispatcher (test_hw_dispatcher)

; 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.qpl::test::hw_dispatcher" = type { ptr, %"class.qpl::test::hw_dispatcher::hw_context", %"struct.std::array", i64, i8, i32 }
%"class.qpl::test::hw_dispatcher::hw_context" = type { ptr }
%"struct.std::array" = type { [100 x %"class.qpl::test::hw_device"] }
%"class.qpl::test::hw_device" = type { %"struct.std::array.0", %"struct.std::array.2", %"struct.std::array.3", i32, i64, i64, i32, i32, i8, i64, i32, i64 }
%"struct.std::array.0" = type { [100 x %"class.qpl::test::hw_queue"] }
%"class.qpl::test::hw_queue" = type { ptr, i32, i8, %"struct.std::array.1", i64, i64 }
%"struct.std::array.1" = type { [8 x i32] }
%"struct.std::array.2" = type { [100 x %"struct.std::array.1"] }
%"struct.std::array.3" = type { [100 x i64] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl4test13hw_dispatcher13initialize_hwEv(ptr noundef nonnull align 8 dereferenceable(1046432) %0) #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #7
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  %10 = invoke i32 @qpl_test_accfg_new(ptr noundef %4)
          to label %11 unwind label %53

11:                                               ; preds = %1
  store i32 %10, ptr %5, align 4, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp ne i32 0, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %11
  store i32 3, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %51

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = invoke ptr @qpl_test_accfg_device_get_first(ptr noundef %16)
          to label %18 unwind label %53

18:                                               ; preds = %15
  store ptr %17, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %19 = getelementptr inbounds %"class.qpl::test::hw_dispatcher", ptr %9, i32 0, i32 2
  %20 = call noundef ptr @_ZNSt5arrayIN3qpl4test9hw_deviceELm100EE5beginEv(ptr noundef nonnull align 8 dereferenceable(1046400) %19) #8
  store ptr %20, ptr %8, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %35, %18
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = icmp ne ptr null, %22
  br i1 %23, label %24, label %36

24:                                               ; preds = %21
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = call noundef i32 @_ZN3qpl4test9hw_device21initialize_new_deviceEPv(ptr noundef nonnull align 8 dereferenceable(10464) %25, ptr noundef %26) #7
  %28 = icmp eq i32 0, %27
  br i1 %28, label %29, label %32

29:                                               ; preds = %24
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.qpl::test::hw_device", ptr %30, i32 1
  store ptr %31, ptr %8, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %29, %24
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = invoke ptr @qpl_test_accfg_device_get_next(ptr noundef %33)
          to label %35 unwind label %53

35:                                               ; preds = %32
  store ptr %34, ptr %7, align 8, !tbaa !5
  br label %21, !llvm.loop !11

36:                                               ; preds = %21
  %37 = getelementptr inbounds %"class.qpl::test::hw_dispatcher", ptr %9, i32 0, i32 2
  %38 = call noundef ptr @_ZNSt5arrayIN3qpl4test9hw_deviceELm100EE5beginEv(ptr noundef nonnull align 8 dereferenceable(1046400) %37) #8
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = invoke noundef i64 @_ZSt8distanceIPN3qpl4test9hw_deviceEENSt15iterator_traitsIT_E15difference_typeES5_S5_(ptr noundef %38, ptr noundef %39)
          to label %41 unwind label %53

41:                                               ; preds = %36
  %42 = getelementptr inbounds %"class.qpl::test::hw_dispatcher", ptr %9, i32 0, i32 3
  store i64 %40, ptr %42, align 8, !tbaa !13
  %43 = getelementptr inbounds %"class.qpl::test::hw_dispatcher", ptr %9, i32 0, i32 3
  %44 = load i64, ptr %43, align 8, !tbaa !13
  %45 = icmp ule i64 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %41
  store i32 4, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %50

47:                                               ; preds = %41
  %48 = getelementptr inbounds %"class.qpl::test::hw_dispatcher", ptr %9, i32 0, i32 1
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN3qpl4test13hw_dispatcher10hw_context22set_driver_context_ptrEP9accfg_ctx(ptr noundef nonnull align 8 dereferenceable(8) %48, ptr noundef %49) #7
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %50

50:                                               ; preds = %47, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  br label %51

51:                                               ; preds = %50, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #7
  %52 = load i32, ptr %2, align 4
  ret i32 %52

53:                                               ; preds = %36, %32, %15, %1
  %54 = landingpad { ptr, i32 }
          catch ptr null
  %55 = extractvalue { ptr, i32 } %54, 0
  call void @__clang_call_terminate(ptr %55) #9
  unreachable
}

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

declare i32 @qpl_test_accfg_new(ptr noundef) #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #3

declare ptr @qpl_test_accfg_device_get_first(ptr noundef) #2

; Function Attrs: mustprogress nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIN3qpl4test9hw_deviceELm100EE5beginEv(ptr noundef nonnull align 8 dereferenceable(1046400)) #4 align 2

; Function Attrs: nounwind
declare noundef i32 @_ZN3qpl4test9hw_device21initialize_new_deviceEPv(ptr noundef nonnull align 8 dereferenceable(10464), ptr noundef) #5

declare ptr @qpl_test_accfg_device_get_next(ptr noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_ZSt8distanceIPN3qpl4test9hw_deviceEENSt15iterator_traitsIT_E15difference_typeES5_S5_(ptr noundef, ptr noundef) #6

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qpl4test13hw_dispatcher10hw_context22set_driver_context_ptrEP9accfg_ctx(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #0 align 2

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

attributes #0 = { 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 #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 = { noinline noreturn nounwind uwtable "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 = { mustprogress nounwind willreturn memory(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 #5 = { 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 #6 = { inlinehint 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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !17, i64 1046416}
!14 = !{!"_ZTSN3qpl4test13hw_dispatcherE", !15, i64 8, !16, i64 16, !17, i64 1046416, !18, i64 1046424, !19, i64 1046428}
!15 = !{!"_ZTSN3qpl4test13hw_dispatcher10hw_contextE", !6, i64 0}
!16 = !{!"_ZTSSt5arrayIN3qpl4test9hw_deviceELm100EE", !7, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = !{!"_ZTS30qpl_test_hw_accelerator_status", !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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 5) i32 @_ZN3qpl4test13hw_dispatcher13initialize_hwEv(ptr noundef nonnull align 8 dereferenceable(1046432) %0) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #7
  store ptr null, ptr %2, align 8, !tbaa !5
  %3 = invoke i32 @qpl_test_accfg_new(ptr noundef nonnull %2)
          to label %4 unwind label %.loopexit.split-lp

4:                                                ; preds = %1
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %5, label %24

5:                                                ; preds = %4
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = invoke ptr @qpl_test_accfg_device_get_first(ptr noundef %6)
          to label %8 unwind label %.loopexit.split-lp

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = call noundef ptr @_ZNSt5arrayIN3qpl4test9hw_deviceELm100EE5beginEv(ptr noundef nonnull align 8 dereferenceable(1046400) %9) #8
  br label %11

11:                                               ; preds = %12, %8
  %.08 = phi ptr [ %7, %8 ], [ %15, %12 ]
  %.0 = phi ptr [ %10, %8 ], [ %spec.select, %12 ]
  %.not11 = icmp eq ptr %.08, null
  br i1 %.not11, label %16, label %12

12:                                               ; preds = %11
  %13 = call noundef i32 @_ZN3qpl4test9hw_device21initialize_new_deviceEPv(ptr noundef nonnull align 8 dereferenceable(10464) %.0, ptr noundef nonnull %.08) #7
  %14 = icmp eq i32 %13, 0
  %spec.select.idx = select i1 %14, i64 10464, i64 0
  %spec.select = getelementptr inbounds i8, ptr %.0, i64 %spec.select.idx
  %15 = invoke ptr @qpl_test_accfg_device_get_next(ptr noundef nonnull %.08)
          to label %11 unwind label %.loopexit, !llvm.loop !9

16:                                               ; preds = %11
  %17 = invoke noundef i64 @_ZSt8distanceIPN3qpl4test9hw_deviceEENSt15iterator_traitsIT_E15difference_typeES5_S5_(ptr noundef %10, ptr noundef %.0)
          to label %18 unwind label %.loopexit.split-lp

18:                                               ; preds = %16
  %19 = getelementptr inbounds i8, ptr %0, i64 1046416
  store i64 %17, ptr %19, align 8, !tbaa !11
  %20 = icmp eq i64 %17, 0
  br i1 %20, label %24, label %21

21:                                               ; preds = %18
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN3qpl4test13hw_dispatcher10hw_context22set_driver_context_ptrEP9accfg_ctx(ptr noundef nonnull align 8 dereferenceable(8) %22, ptr noundef %23) #7
  br label %24

24:                                               ; preds = %21, %18, %4
  %.110 = phi i32 [ 3, %4 ], [ 0, %21 ], [ 4, %18 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #7
  ret i32 %.110

.loopexit:                                        ; preds = %12
  %lpad.loopexit = landingpad { ptr, i32 }
          catch ptr null
  br label %25

.loopexit.split-lp:                               ; preds = %1, %5, %16
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          catch ptr null
  br label %25

25:                                               ; preds = %.loopexit.split-lp, %.loopexit
  %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %.loopexit ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  %26 = extractvalue { ptr, i32 } %lpad.phi, 0
  call void @__clang_call_terminate(ptr %26) #9
  unreachable
}

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

declare i32 @qpl_test_accfg_new(ptr noundef) local_unnamed_addr #2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #3

declare ptr @qpl_test_accfg_device_get_first(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIN3qpl4test9hw_deviceELm100EE5beginEv(ptr noundef nonnull align 8 dereferenceable(1046400)) local_unnamed_addr #4 align 2

; Function Attrs: nounwind
declare noundef i32 @_ZN3qpl4test9hw_device21initialize_new_deviceEPv(ptr noundef nonnull align 8 dereferenceable(10464), ptr noundef) local_unnamed_addr #5

declare ptr @qpl_test_accfg_device_get_next(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i64 @_ZSt8distanceIPN3qpl4test9hw_deviceEENSt15iterator_traitsIT_E15difference_typeES5_S5_(ptr noundef, ptr noundef) local_unnamed_addr #6

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3qpl4test13hw_dispatcher10hw_context22set_driver_context_ptrEP9accfg_ctx(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0 align 2

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

attributes #0 = { 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 #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 = { noinline noreturn nounwind uwtable "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 = { mustprogress nofree nosync nounwind willreturn memory(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 #5 = { 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 #6 = { inlinehint 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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !15, i64 1046416}
!12 = !{!"_ZTSN3qpl4test13hw_dispatcherE", !13, i64 8, !14, i64 16, !15, i64 1046416, !16, i64 1046424, !17, i64 1046428}
!13 = !{!"_ZTSN3qpl4test13hw_dispatcher10hw_contextE", !6, i64 0}
!14 = !{!"_ZTSSt5arrayIN3qpl4test9hw_deviceELm100EE", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!"_ZTS30qpl_test_hw_accelerator_status", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass