; LLVM IR from intel/qpl :: sources/c_api (utils_api)

; 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.qpl_hw_state = type { %struct.hw_decompress_analytics_descriptor, %struct.hw_iaa_completion_record, [2 x %struct.hw_iaa_aecs_analytic], [2 x %struct.hw_iaa_aecs_compress], %struct.qpl_buffer, %struct.qpl_execution_history, i32, i32, i32, %struct.hw_huffman_code, i32, %struct.hw_accelerator_context, i32, i32, i8, i8, i32, i32, %struct.qpl_execution_record }
%struct.hw_decompress_analytics_descriptor = type { i32, i32, ptr, ptr, ptr, i32, i16, i16, ptr, i32, i32, i32, i32 }
%struct.hw_iaa_completion_record = type { i8, i8, i8, i8, i32, i64, i64, i32, i8, i8, i16, i32, i32, i32, i32, i64, i64 }
%struct.hw_iaa_aecs_analytic = type { %struct.hw_iaa_aecs_filter, [36 x i32], %struct.hw_iaa_aecs_decompress }
%struct.hw_iaa_aecs_filter = type { i32, i32, i32, i32, i32, i32 }
%struct.hw_iaa_aecs_decompress = type { [2 x i32], i32, i32, [32 x i64], [32 x i8], i32, i8, i8, i16, [5 x i32], [5 x i32], [5 x i32], [5 x i32], [62 x i32], %union.anon, i16, i16, %union.anon.1, %struct.anon.3, i16, [4096 x i8], [6 x i32] }
%union.anon = type { %struct.anon }
%struct.anon = type { [6 x i32], [224 x i8], [5 x i32] }
%union.anon.1 = type { %struct.anon.2 }
%struct.anon.2 = type { [2 x i32], [144 x i8], [5 x i32] }
%struct.anon.3 = type { i16 }
%struct.hw_iaa_aecs_compress = type { i32, i32, [5 x i32], i32, [256 x i8], %struct.hw_iaa_histogram, [12288 x i8] }
%struct.hw_iaa_histogram = type { [286 x i32], [2 x i32], [30 x i32], [2 x i32] }
%struct.qpl_buffer = type { [1024 x i8], i32, i32 }
%struct.qpl_execution_history = type { i8, i32, i32, i32, ptr }
%struct.hw_huffman_code = type { i16, i8, i8 }
%struct.hw_accelerator_context = type { %struct.hw_device_properties, ptr }
%struct.hw_device_properties = type { i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8 }
%struct.qpl_execution_record = type { double, i32, i32 }

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @qpl_get_execution_record(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %15, label %12

12:                                               ; preds = %3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %12, %3
  store i32 50, ptr %4, align 4
  br label %45

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call noundef ptr @_ZN3qpl3jobL9get_stateEPK7qpl_job(ptr noundef %17) #3
  store ptr %18, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %16
  store i32 6, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %44

22:                                               ; preds = %16
  %23 = load i32, ptr %6, align 4, !tbaa !9
  switch i32 %23, label %42 [
    i32 0, label %24
    i32 1, label %30
    i32 2, label %36
  ]

24:                                               ; preds = %22
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.qpl_hw_state, ptr %25, i32 0, i32 18
  %27 = getelementptr inbounds %struct.qpl_execution_record, ptr %26, i32 0, i32 0
  %28 = load double, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  store double %28, ptr %29, align 8, !tbaa !30
  br label %43

30:                                               ; preds = %22
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.qpl_hw_state, ptr %31, i32 0, i32 18
  %33 = getelementptr inbounds %struct.qpl_execution_record, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !31
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %34, ptr %35, align 4, !tbaa !32
  br label %43

36:                                               ; preds = %22
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.qpl_hw_state, ptr %37, i32 0, i32 18
  %39 = getelementptr inbounds %struct.qpl_execution_record, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 4, !tbaa !33
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %40, ptr %41, align 4, !tbaa !32
  br label %43

42:                                               ; preds = %22
  store i32 55, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %44

43:                                               ; preds = %36, %30, %24
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %44

44:                                               ; preds = %43, %42, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %45

45:                                               ; preds = %44, %15
  %46 = load i32, ptr %4, align 4
  ret i32 %46
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN3qpl3jobL9get_stateEPK7qpl_job(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!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 = !{!"_ZTS22qpl_execution_record_t", !7, i64 0}
!11 = !{!12, !29, i64 39728}
!12 = !{!"_ZTS12qpl_hw_state", !13, i64 0, !16, i64 64, !7, i64 128, !7, i64 10880, !18, i64 38592, !19, i64 39624, !14, i64 39648, !14, i64 39652, !14, i64 39656, !23, i64 39660, !14, i64 39664, !24, i64 39672, !14, i64 39704, !14, i64 39708, !20, i64 39712, !20, i64 39713, !26, i64 39716, !27, i64 39720, !28, i64 39728}
!13 = !{!"_ZTS34hw_decompress_analytics_descriptor", !14, i64 0, !14, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !14, i64 32, !15, i64 36, !15, i64 38, !6, i64 40, !14, i64 48, !14, i64 52, !14, i64 56, !14, i64 60}
!14 = !{!"int", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"_ZTS24hw_iaa_completion_record", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !14, i64 4, !17, i64 8, !17, i64 16, !14, i64 24, !7, i64 28, !7, i64 29, !15, i64 30, !14, i64 32, !14, i64 36, !14, i64 40, !14, i64 44, !17, i64 48, !17, i64 56}
!17 = !{!"long", !7, i64 0}
!18 = !{!"_ZTS10qpl_buffer", !7, i64 0, !14, i64 1024, !14, i64 1028}
!19 = !{!"_ZTS21qpl_execution_history", !20, i64 0, !21, i64 4, !22, i64 8, !14, i64 12, !6, i64 16}
!20 = !{!"bool", !7, i64 0}
!21 = !{!"_ZTS23qpl_task_execution_step", !7, i64 0}
!22 = !{!"_ZTS14qpl_comp_style", !7, i64 0}
!23 = !{!"_ZTS15hw_huffman_code", !15, i64 0, !7, i64 2, !7, i64 3}
!24 = !{!"_ZTS22hw_accelerator_context", !25, i64 0, !6, i64 24}
!25 = !{!"_ZTS20hw_device_properties", !14, i64 0, !14, i64 4, !14, i64 8, !20, i64 12, !20, i64 13, !20, i64 14, !20, i64 15, !20, i64 16, !20, i64 17, !20, i64 18, !20, i64 19, !20, i64 20, !20, i64 21, !20, i64 22}
!26 = !{!"_ZTS25hw_multidescriptor_status", !7, i64 0}
!27 = !{!"_ZTS10qpl_status", !7, i64 0}
!28 = !{!"_ZTS20qpl_execution_record", !29, i64 0, !14, i64 8, !14, i64 12}
!29 = !{!"double", !7, i64 0}
!30 = !{!29, !29, i64 0}
!31 = !{!12, !14, i64 39736}
!32 = !{!14, !14, i64 0}
!33 = !{!12, !14, i64 39740}


; 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 range(i32 0, 56) i32 @qpl_get_execution_record(ptr noundef %0, i32 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %2, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %19, label %6

6:                                                ; preds = %3
  %7 = tail call noundef ptr @_ZN3qpl3jobL9get_stateEPK7qpl_job(ptr noundef nonnull %0) #2
  %8 = icmp eq ptr %7, null
  br i1 %8, label %19, label %9

9:                                                ; preds = %6
  switch i32 %1, label %19 [
    i32 0, label %10
    i32 1, label %13
    i32 2, label %16
  ]

10:                                               ; preds = %9
  %11 = getelementptr inbounds i8, ptr %7, i64 39728
  %12 = load double, ptr %11, align 8, !tbaa !5
  store double %12, ptr %2, align 8, !tbaa !27
  br label %19

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %7, i64 39736
  %15 = load i32, ptr %14, align 8, !tbaa !28
  store i32 %15, ptr %2, align 4, !tbaa !29
  br label %19

16:                                               ; preds = %9
  %17 = getelementptr inbounds i8, ptr %7, i64 39740
  %18 = load i32, ptr %17, align 4, !tbaa !30
  store i32 %18, ptr %2, align 4, !tbaa !29
  br label %19

19:                                               ; preds = %6, %9, %16, %13, %10, %3
  %.1 = phi i32 [ 50, %3 ], [ 6, %6 ], [ 55, %9 ], [ 0, %16 ], [ 0, %13 ], [ 0, %10 ]
  ret i32 %.1
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN3qpl3jobL9get_stateEPK7qpl_job(ptr noundef) local_unnamed_addr #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 = { 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 #2 = { 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, !26, i64 39728}
!6 = !{!"_ZTS12qpl_hw_state", !7, i64 0, !13, i64 64, !9, i64 128, !9, i64 10880, !15, i64 38592, !16, i64 39624, !8, i64 39648, !8, i64 39652, !8, i64 39656, !20, i64 39660, !8, i64 39664, !21, i64 39672, !8, i64 39704, !8, i64 39708, !17, i64 39712, !17, i64 39713, !23, i64 39716, !24, i64 39720, !25, i64 39728}
!7 = !{!"_ZTS34hw_decompress_analytics_descriptor", !8, i64 0, !8, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !8, i64 32, !12, i64 36, !12, i64 38, !11, i64 40, !8, i64 48, !8, i64 52, !8, i64 56, !8, i64 60}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"short", !9, i64 0}
!13 = !{!"_ZTS24hw_iaa_completion_record", !9, i64 0, !9, i64 1, !9, i64 2, !9, i64 3, !8, i64 4, !14, i64 8, !14, i64 16, !8, i64 24, !9, i64 28, !9, i64 29, !12, i64 30, !8, i64 32, !8, i64 36, !8, i64 40, !8, i64 44, !14, i64 48, !14, i64 56}
!14 = !{!"long", !9, i64 0}
!15 = !{!"_ZTS10qpl_buffer", !9, i64 0, !8, i64 1024, !8, i64 1028}
!16 = !{!"_ZTS21qpl_execution_history", !17, i64 0, !18, i64 4, !19, i64 8, !8, i64 12, !11, i64 16}
!17 = !{!"bool", !9, i64 0}
!18 = !{!"_ZTS23qpl_task_execution_step", !9, i64 0}
!19 = !{!"_ZTS14qpl_comp_style", !9, i64 0}
!20 = !{!"_ZTS15hw_huffman_code", !12, i64 0, !9, i64 2, !9, i64 3}
!21 = !{!"_ZTS22hw_accelerator_context", !22, i64 0, !11, i64 24}
!22 = !{!"_ZTS20hw_device_properties", !8, i64 0, !8, i64 4, !8, i64 8, !17, i64 12, !17, i64 13, !17, i64 14, !17, i64 15, !17, i64 16, !17, i64 17, !17, i64 18, !17, i64 19, !17, i64 20, !17, i64 21, !17, i64 22}
!23 = !{!"_ZTS25hw_multidescriptor_status", !9, i64 0}
!24 = !{!"_ZTS10qpl_status", !9, i64 0}
!25 = !{!"_ZTS20qpl_execution_record", !26, i64 0, !8, i64 8, !8, i64 12}
!26 = !{!"double", !9, i64 0}
!27 = !{!26, !26, i64 0}
!28 = !{!6, !8, i64 39736}
!29 = !{!8, !8, i64 0}
!30 = !{!6, !8, i64 39740}


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