; LLVM IR from intel/qpl :: tools/utils/common (compare_huffman_table)

; 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::ml::compression::huffman_table_meta_t" = type { [4 x i8], i32, i8, i8, i8, i8, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN3qpl4test25qpl_huffman_table_compareEP17qpl_huffman_tableS2_Pb(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca i32, align 4
  %15 = alloca i8, align 1
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  store i8 0, ptr %18, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef %19) #5
  store i32 %20, ptr %8, align 4, !tbaa !11
  %21 = load i32, ptr %8, align 4, !tbaa !11
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %3
  %24 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %24, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %26

25:                                               ; preds = %3
  store i32 0, ptr %9, align 4
  br label %26

26:                                               ; preds = %25, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %27 = load i32, ptr %9, align 4
  switch i32 %27, label %73 [
    i32 0, label %28
    i32 1, label %71
  ]

28:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef %29) #5
  store i32 %30, ptr %10, align 4, !tbaa !11
  %31 = load i32, ptr %10, align 4, !tbaa !11
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %28
  %34 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %34, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %36

35:                                               ; preds = %28
  store i32 0, ptr %9, align 4
  br label %36

36:                                               ; preds = %35, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %37 = load i32, ptr %9, align 4
  switch i32 %37, label %73 [
    i32 0, label %38
    i32 1, label %71
  ]

38:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %39, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %40, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #5
  store i8 1, ptr %13, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  %43 = call i32 @memcmp(ptr noundef %41, ptr noundef %42, i64 noundef 16) #6
  store i32 %43, ptr %14, align 4, !tbaa !11
  %44 = load i32, ptr %14, align 4, !tbaa !11
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %38
  store i8 0, ptr %13, align 1, !tbaa !9
  br label %47

47:                                               ; preds = %46, %38
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #5
  store i8 1, ptr %15, align 1, !tbaa !9
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.qpl::ml::compression::huffman_table_meta_t", ptr %48, i32 0, i32 2
  %50 = load i8, ptr %49, align 4, !tbaa !13
  %51 = icmp eq i8 %50, 0
  br i1 %51, label %52, label %59

52:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %53, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %54, ptr %17, align 8, !tbaa !5
  %55 = load ptr, ptr %16, align 8, !tbaa !5
  %56 = load ptr, ptr %17, align 8, !tbaa !5
  %57 = call noundef zeroext i1 @_ZNK3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE8is_equalERKS4_(ptr noundef nonnull align 8 dereferenceable(72) %55, ptr noundef nonnull align 8 dereferenceable(72) %56) #5
  %58 = zext i1 %57 to i8
  store i8 %58, ptr %15, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %60

59:                                               ; preds = %47
  store i32 52, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %70

60:                                               ; preds = %52
  %61 = load i8, ptr %13, align 1, !tbaa !9, !range !19, !noundef !20
  %62 = trunc i8 %61 to i1
  br i1 %62, label %63, label %66

63:                                               ; preds = %60
  %64 = load i8, ptr %15, align 1, !tbaa !9, !range !19, !noundef !20
  %65 = trunc i8 %64 to i1
  br label %66

66:                                               ; preds = %63, %60
  %67 = phi i1 [ false, %60 ], [ %65, %63 ]
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = zext i1 %67 to i8
  store i8 %69, ptr %68, align 1, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %70

70:                                               ; preds = %66, %59
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %71

71:                                               ; preds = %70, %36, %26
  %72 = load i32, ptr %4, align 4
  ret i32 %72

73:                                               ; preds = %36, %26
  unreachable
}

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

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

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE8is_equalERKS4_(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef nonnull align 8 dereferenceable(72)) #4

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 = { 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 willreturn memory(read) "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 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !15, i64 8}
!14 = !{!"_ZTSN3qpl2ml11compression20huffman_table_meta_tE", !7, i64 0, !12, i64 4, !15, i64 8, !16, i64 9, !17, i64 10, !18, i64 11, !12, i64 12}
!15 = !{!"_ZTSN3qpl2ml11compression23compression_algorithm_eE", !7, i64 0}
!16 = !{!"_ZTSN3qpl2ml11compression15table_version_eE", !7, i64 0}
!17 = !{!"_ZTSN3qpl2ml11compression20huffman_table_type_eE", !7, i64 0}
!18 = !{!"_ZTSN3qpl2ml16execution_path_tE", !7, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}


; 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 i32 @_ZN3qpl4test25qpl_huffman_table_compareEP17qpl_huffman_tableS2_Pb(ptr noundef %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  store i8 0, ptr %2, align 1, !tbaa !5
  %4 = tail call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef %0) #4
  %.not.not = icmp eq i32 %4, 0
  br i1 %.not.not, label %5, label %15

5:                                                ; preds = %3
  %6 = tail call noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef %1) #4
  %.not25.not = icmp eq i32 %6, 0
  br i1 %.not25.not, label %7, label %15

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i8, ptr %8, align 4, !tbaa !9
  %10 = icmp eq i8 %9, 0
  br i1 %10, label %11, label %15

11:                                               ; preds = %7
  %bcmp = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(16) %0, ptr noundef nonnull dereferenceable(16) %1, i64 16)
  %.not26 = icmp eq i32 %bcmp, 0
  %12 = tail call noundef zeroext i1 @_ZNK3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE8is_equalERKS4_(ptr noundef nonnull align 8 dereferenceable(72) %0, ptr noundef nonnull align 8 dereferenceable(72) %1) #4
  %13 = and i1 %.not26, %12
  %14 = zext i1 %13 to i8
  store i8 %14, ptr %2, align 1, !tbaa !5
  br label %15

15:                                               ; preds = %5, %3, %11, %7
  %.3 = phi i32 [ %4, %3 ], [ %6, %5 ], [ 0, %11 ], [ 52, %7 ]
  ret i32 %.3
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZN3qpl2ml12bad_argumentL17check_for_nullptrIP17qpl_huffman_tableJEEEjT_DpT0_(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare noundef zeroext i1 @_ZNK3qpl2ml11compression15huffman_table_tILNS1_23compression_algorithm_eE0EE8is_equalERKS4_(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef nonnull align 8 dereferenceable(72)) local_unnamed_addr #2

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #3

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 "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 = { nofree nounwind willreturn memory(argmem: read) }
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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"_ZTSN3qpl2ml11compression20huffman_table_meta_tE", !7, i64 0, !11, i64 4, !12, i64 8, !13, i64 9, !14, i64 10, !15, i64 11, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSN3qpl2ml11compression23compression_algorithm_eE", !7, i64 0}
!13 = !{!"_ZTSN3qpl2ml11compression15table_version_eE", !7, i64 0}
!14 = !{!"_ZTSN3qpl2ml11compression20huffman_table_type_eE", !7, i64 0}
!15 = !{!"_ZTSN3qpl2ml16execution_path_tE", !7, i64 0}


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