; LLVM IR from intel/qpl :: sources/middle-layer/dispatcher (hw_queue)

; 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"

%struct.hw_descriptor = type { [64 x i8] }
%struct.hw_completion_record = type { i8, i8, [62 x i8] }

declare i32 @__gxx_personality_v0(...)

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

; 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3qpl2ml10dispatcher8hw_queue18enqueue_descriptorEPvPNS0_4util22execution_record_ext_tE(ptr noundef nonnull align 8 dereferenceable(96), ptr noundef, ptr noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK3qpl2ml10dispatcher8hw_queue12execute_noopEv(ptr noundef nonnull align 8 dereferenceable(96) %0) #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %struct.hw_descriptor, align 64
  %5 = alloca %struct.hw_completion_record, align 64
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr %4) #5
  call void @llvm.memset.p0.i64(ptr align 64 %4, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr %5) #5
  call void @llvm.memset.p0.i64(ptr align 64 %5, i8 0, i64 64, i1 true)
  invoke void @hw_iaa_descriptor_init_noop_operation(ptr noundef %4)
          to label %9 unwind label %33

9:                                                ; preds = %1
  invoke void @hw_iaa_descriptor_set_completion_record(ptr noundef %4, ptr noundef %5)
          to label %10 unwind label %33

10:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %11 = call noundef i32 @_ZNK3qpl2ml10dispatcher8hw_queue18enqueue_descriptorEPvPNS0_4util22execution_record_ext_tE(ptr noundef nonnull align 8 dereferenceable(96) %8, ptr noundef %4, ptr noundef null) #5
  store i32 %11, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp eq i32 0, %12
  br i1 %13, label %14, label %28

14:                                               ; preds = %10
  br label %15

15:                                               ; preds = %20, %14
  %16 = getelementptr inbounds %struct.hw_completion_record, ptr %5, i32 0, i32 0
  %17 = load volatile i8, ptr %16, align 64, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  call void @llvm.x86.sse2.pause()
  br label %15, !llvm.loop !13

21:                                               ; preds = %15
  %22 = getelementptr inbounds %struct.hw_completion_record, ptr %5, i32 0, i32 0
  %23 = load volatile i8, ptr %22, align 64, !tbaa !11
  %24 = zext i8 %23 to i32
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %31

27:                                               ; preds = %21
  br label %30

28:                                               ; preds = %10
  %29 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %29, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %31

30:                                               ; preds = %27
  store i32 500, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %31

31:                                               ; preds = %30, %28, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %4) #5
  %32 = load i32, ptr %2, align 4
  ret i32 %32

33:                                               ; preds = %9, %1
  %34 = landingpad { ptr, i32 }
          catch ptr null
  %35 = extractvalue { ptr, i32 } %34, 0
  call void @__clang_call_terminate(ptr %35) #6
  unreachable
}

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

declare void @hw_iaa_descriptor_init_noop_operation(ptr noundef) #4

declare void @hw_iaa_descriptor_set_completion_record(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind
declare void @llvm.x86.sse2.pause() #5

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { "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 }
attributes #6 = { 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 = !{!"_ZTS10qpl_status", !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"_ZTS20hw_completion_record", !7, i64 0, !7, i64 1, !7, i64 2}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%struct.hw_descriptor = type { [64 x i8] }
%struct.hw_completion_record = type { i8, i8, [62 x i8] }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) 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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3qpl2ml10dispatcher8hw_queue18enqueue_descriptorEPvPNS0_4util22execution_record_ext_tE(ptr noundef nonnull align 8 dereferenceable(96), ptr noundef, ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK3qpl2ml10dispatcher8hw_queue12execute_noopEv(ptr noundef nonnull align 8 dereferenceable(96) %0) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %struct.hw_descriptor, align 64
  %3 = alloca %struct.hw_completion_record, align 64
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %2) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 64 dereferenceable(64) %2, i8 0, i64 64, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #5
  call void @llvm.memset.p0.i64(ptr nonnull align 64 %3, i8 0, i64 64, i1 true)
  invoke void @hw_iaa_descriptor_init_noop_operation(ptr noundef nonnull %2)
          to label %4 unwind label %15

4:                                                ; preds = %1
  invoke void @hw_iaa_descriptor_set_completion_record(ptr noundef nonnull %2, ptr noundef nonnull %3)
          to label %5 unwind label %15

5:                                                ; preds = %4
  %6 = call noundef i32 @_ZNK3qpl2ml10dispatcher8hw_queue18enqueue_descriptorEPvPNS0_4util22execution_record_ext_tE(ptr noundef nonnull align 8 dereferenceable(96) %0, ptr noundef nonnull %2, ptr noundef null) #5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %.preheader, label %14

.preheader:                                       ; preds = %5
  %8 = load volatile i8, ptr %3, align 64, !tbaa !5
  %9 = icmp eq i8 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  call void @llvm.x86.sse2.pause()
  %10 = load volatile i8, ptr %3, align 64, !tbaa !5
  %11 = icmp eq i8 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %12 = load volatile i8, ptr %3, align 64, !tbaa !5
  %13 = icmp eq i8 %12, 1
  %. = select i1 %13, i32 0, i32 500
  br label %14

14:                                               ; preds = %5, %._crit_edge
  %.0 = phi i32 [ %., %._crit_edge ], [ %6, %5 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %2) #5
  ret i32 %.0

15:                                               ; preds = %4, %1
  %16 = landingpad { ptr, i32 }
          catch ptr null
  %17 = extractvalue { ptr, i32 } %16, 0
  call void @__clang_call_terminate(ptr %17) #6
  unreachable
}

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

declare void @hw_iaa_descriptor_init_noop_operation(ptr noundef) local_unnamed_addr #4

declare void @hw_iaa_descriptor_set_completion_record(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare void @llvm.x86.sse2.pause() #5

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { "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 }
attributes #6 = { 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, !7, i64 0}
!6 = !{!"_ZTS20hw_completion_record", !7, i64 0, !7, i64 1, !7, i64 2}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass