; LLVM IR from intel/qpl :: sources/core-iaa/sources/aecs (hw_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.bitbuf2 = type { i64, ptr, ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
declare dso_local void @hw_create_huff_tree(ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 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: nounwind uwtable
declare dso_local void @hw_compute_codes(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @hw_create_header(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @hw_create_huff_tables(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6) #0 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca [16 x i32], align 16
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca %struct.bitbuf2, align 8
  %23 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  store ptr %6, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %15) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  store i32 0, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  store i32 0, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #2
  store i32 0, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #2
  store i32 0, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #2
  store i32 0, ptr %20, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #2
  store i32 0, ptr %21, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %22) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #2
  store i32 0, ptr %23, align 4, !tbaa !9
  %24 = load ptr, ptr %13, align 8, !tbaa !5
  %25 = getelementptr inbounds i32, ptr %24, i64 256
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %7
  %29 = load ptr, ptr %13, align 8, !tbaa !5
  %30 = getelementptr inbounds i32, ptr %29, i64 256
  store i32 1, ptr %30, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %28, %7
  %32 = load ptr, ptr %13, align 8, !tbaa !5
  %33 = getelementptr inbounds [16 x i32], ptr %15, i64 0, i64 0
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  call void @hw_create_huff_tree(ptr noundef %32, i32 noundef 286, ptr noundef %33, ptr noundef %34, i32 noundef 15)
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds [16 x i32], ptr %15, i64 0, i64 0
  call void @hw_compute_codes(ptr noundef %35, i32 noundef 286, ptr noundef %36, i32 noundef 15, ptr noundef %16)
  %37 = load ptr, ptr %14, align 8, !tbaa !5
  %38 = getelementptr inbounds [16 x i32], ptr %15, i64 0, i64 0
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  call void @hw_create_huff_tree(ptr noundef %37, i32 noundef 30, ptr noundef %38, ptr noundef %39, i32 noundef 15)
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds [16 x i32], ptr %15, i64 0, i64 0
  call void @hw_compute_codes(ptr noundef %40, i32 noundef 30, ptr noundef %41, i32 noundef 15, ptr noundef %17)
  %42 = load i32, ptr %12, align 4, !tbaa !9
  %43 = and i32 %42, 7
  store i32 %43, ptr %19, align 4, !tbaa !9
  %44 = load i32, ptr %12, align 4, !tbaa !9
  %45 = lshr i32 %44, 3
  store i32 %45, ptr %20, align 4, !tbaa !9
  %46 = load i32, ptr %20, align 4, !tbaa !9
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = zext i32 %46 to i64
  %49 = getelementptr inbounds i8, ptr %47, i64 %48
  store ptr %49, ptr %10, align 8, !tbaa !5
  %50 = load i32, ptr %20, align 4, !tbaa !9
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = sub i32 %51, %50
  store i32 %52, ptr %11, align 4, !tbaa !9
  %53 = load i32, ptr %19, align 4, !tbaa !9
  %54 = and i32 %53, -8
  store i32 %54, ptr %23, align 4, !tbaa !9
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = load i64, ptr %55, align 8, !tbaa !11
  %57 = load i32, ptr %23, align 4, !tbaa !9
  %58 = zext i32 %57 to i64
  %59 = lshr i64 %56, %58
  %60 = load i32, ptr %19, align 4, !tbaa !9
  %61 = and i32 %60, 7
  %62 = shl i32 1, %61
  %63 = sub i32 %62, 1
  %64 = zext i32 %63 to i64
  %65 = and i64 %59, %64
  %66 = getelementptr inbounds %struct.bitbuf2, ptr %22, i32 0, i32 0
  store i64 %65, ptr %66, align 8, !tbaa !13
  %67 = load i32, ptr %19, align 4, !tbaa !9
  %68 = load i32, ptr %23, align 4, !tbaa !9
  %69 = sub i32 %67, %68
  %70 = getelementptr inbounds %struct.bitbuf2, ptr %22, i32 0, i32 4
  store i32 %69, ptr %70, align 8, !tbaa !15
  %71 = load i32, ptr %23, align 4, !tbaa !9
  %72 = udiv i32 %71, 8
  store i32 %72, ptr %23, align 4, !tbaa !9
  %73 = load ptr, ptr %10, align 8, !tbaa !5
  %74 = load i32, ptr %23, align 4, !tbaa !9
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds i8, ptr %73, i64 %75
  %77 = getelementptr inbounds %struct.bitbuf2, ptr %22, i32 0, i32 1
  store ptr %76, ptr %77, align 8, !tbaa !16
  %78 = getelementptr inbounds %struct.bitbuf2, ptr %22, i32 0, i32 2
  store ptr %76, ptr %78, align 8, !tbaa !17
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = zext i32 %80 to i64
  %82 = getelementptr inbounds i8, ptr %79, i64 %81
  %83 = getelementptr inbounds i8, ptr %82, i64 -7
  %84 = getelementptr inbounds %struct.bitbuf2, ptr %22, i32 0, i32 3
  store ptr %83, ptr %84, align 8, !tbaa !18
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = load i32, ptr %16, align 4, !tbaa !9
  %87 = add i32 %86, 1
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  %89 = load i32, ptr %17, align 4, !tbaa !9
  %90 = add i32 %89, 1
  %91 = call i32 @hw_create_header(ptr noundef %22, ptr noundef %85, i32 noundef %87, ptr noundef %88, i32 noundef %90, i32 noundef 0)
  store i32 %91, ptr %18, align 4, !tbaa !9
  call void @hw_bitbuf_2_flush(ptr noundef %22)
  %92 = load i32, ptr %12, align 4, !tbaa !9
  %93 = load i32, ptr %18, align 4, !tbaa !9
  %94 = add i32 %92, %93
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #2
  call void @llvm.lifetime.end.p0(i64 40, ptr %22) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 64, ptr %15) #2
  ret i32 %94
}

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

attributes #0 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"", !12, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!15 = !{!14, !10, i64 32}
!16 = !{!14, !6, i64 8}
!17 = !{!14, !6, i64 16}
!18 = !{!14, !6, i64 24}


; 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.bitbuf2 = type { i64, ptr, ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
declare dso_local void @hw_create_huff_tree(ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 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: nounwind uwtable
declare dso_local void @hw_compute_codes(ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @hw_create_header(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @hw_create_huff_tables(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #0 {
  %8 = alloca [16 x i32], align 16
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.bitbuf2, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #2
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #2
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %11) #2
  %12 = getelementptr inbounds i8, ptr %5, i64 1024
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %7
  store i32 1, ptr %12, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %15, %7
  call void @hw_create_huff_tree(ptr noundef nonnull %5, i32 noundef 286, ptr noundef nonnull %8, ptr noundef %0, i32 noundef 15)
  call void @hw_compute_codes(ptr noundef %0, i32 noundef 286, ptr noundef nonnull %8, i32 noundef 15, ptr noundef nonnull %9)
  call void @hw_create_huff_tree(ptr noundef %6, i32 noundef 30, ptr noundef nonnull %8, ptr noundef %1, i32 noundef 15)
  call void @hw_compute_codes(ptr noundef %1, i32 noundef 30, ptr noundef nonnull %8, i32 noundef 15, ptr noundef nonnull %10)
  %17 = and i32 %4, 7
  %18 = lshr i32 %4, 3
  %19 = zext nneg i32 %18 to i64
  %20 = getelementptr inbounds i8, ptr %2, i64 %19
  %21 = sub i32 %3, %18
  %22 = load i64, ptr %20, align 8, !tbaa !9
  %notmask = shl nsw i32 -1, %17
  %23 = xor i32 %notmask, -1
  %24 = zext nneg i32 %23 to i64
  %25 = and i64 %22, %24
  store i64 %25, ptr %11, align 8, !tbaa !11
  %26 = getelementptr inbounds i8, ptr %11, i64 32
  store i32 %17, ptr %26, align 8, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %11, i64 8
  store ptr %20, ptr %27, align 8, !tbaa !15
  %28 = getelementptr inbounds i8, ptr %11, i64 16
  store ptr %20, ptr %28, align 8, !tbaa !16
  %29 = zext i32 %21 to i64
  %30 = getelementptr inbounds i8, ptr %20, i64 %29
  %31 = getelementptr inbounds i8, ptr %30, i64 -7
  %32 = getelementptr inbounds i8, ptr %11, i64 24
  store ptr %31, ptr %32, align 8, !tbaa !17
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = add i32 %33, 1
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = add i32 %35, 1
  %37 = call i32 @hw_create_header(ptr noundef nonnull %11, ptr noundef %0, i32 noundef %34, ptr noundef %1, i32 noundef %36, i32 noundef 0)
  call void @hw_bitbuf_2_flush(ptr noundef nonnull %11)
  %38 = add i32 %37, %4
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #2
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %8) #2
  ret i32 %38
}

; Function Attrs: nounwind uwtable
declare hidden void @hw_bitbuf_2_flush(ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !6, i64 32}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!12, !6, i64 32}
!15 = !{!12, !13, i64 8}
!16 = !{!12, !13, i64 16}
!17 = !{!12, !13, i64 24}


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