; LLVM IR from intel/qpl :: tools/utils/generators/deflate_generator (bitbuffer)

; 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.gz_generator::BitBuffer" = type { i8, i32, %struct.anon, ptr }
%struct.anon = type { i64, 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 uwtable
define dso_local void @_ZN12gz_generator9BitBuffer5writeEmj(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  %12 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !11
  %13 = load i32, ptr %6, align 4, !tbaa !11
  %14 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = add i32 %15, %13
  store i32 %16, ptr %14, align 4, !tbaa !13
  %17 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 2
  %18 = getelementptr inbounds %struct.anon, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 8, !tbaa !17
  store i32 %19, ptr %7, align 4, !tbaa !11
  %20 = load i32, ptr %7, align 4, !tbaa !11
  %21 = load i64, ptr %5, align 8, !tbaa !9
  %22 = zext i32 %20 to i64
  %23 = shl i64 %21, %22
  store i64 %23, ptr %5, align 8, !tbaa !9
  %24 = load i64, ptr %5, align 8, !tbaa !9
  %25 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 2
  %26 = getelementptr inbounds %struct.anon, ptr %25, i32 0, i32 0
  %27 = load i64, ptr %26, align 8, !tbaa !18
  %28 = or i64 %27, %24
  store i64 %28, ptr %26, align 8, !tbaa !18
  %29 = load i32, ptr %6, align 4, !tbaa !11
  %30 = load i32, ptr %7, align 4, !tbaa !11
  %31 = add i32 %30, %29
  store i32 %31, ptr %7, align 4, !tbaa !11
  %32 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 0
  %33 = load i8, ptr %32, align 8, !tbaa !19, !range !20, !noundef !21
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %63

35:                                               ; preds = %3
  br label %36

36:                                               ; preds = %39, %35
  %37 = load i32, ptr %7, align 4, !tbaa !11
  %38 = icmp uge i32 %37, 16
  br i1 %38, label %39, label %62

39:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #3
  store i16 0, ptr %8, align 2, !tbaa !22
  %40 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 2
  %41 = getelementptr inbounds %struct.anon, ptr %40, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !18
  %43 = trunc i64 %42 to i16
  store i16 %43, ptr %8, align 2, !tbaa !22
  %44 = load i16, ptr %8, align 2, !tbaa !22
  %45 = call noundef zeroext i16 @_ZN12gz_generator9BitBuffer7bitFlipEt(i16 noundef zeroext %44)
  store i16 %45, ptr %8, align 2, !tbaa !22
  %46 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 3
  %47 = load ptr, ptr %46, align 8, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %48 = load i16, ptr %8, align 2, !tbaa !22
  %49 = trunc i16 %48 to i8
  store i8 %49, ptr %9, align 1, !tbaa !25
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %47, ptr noundef nonnull align 1 dereferenceable(1) %9)
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  %50 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 3
  %51 = load ptr, ptr %50, align 8, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %52 = load i16, ptr %8, align 2, !tbaa !22
  %53 = zext i16 %52 to i32
  %54 = ashr i32 %53, 8
  %55 = trunc i32 %54 to i8
  store i8 %55, ptr %10, align 1, !tbaa !25
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %51, ptr noundef nonnull align 1 dereferenceable(1) %10)
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  %56 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 2
  %57 = getelementptr inbounds %struct.anon, ptr %56, i32 0, i32 0
  %58 = load i64, ptr %57, align 8, !tbaa !18
  %59 = lshr i64 %58, 16
  store i64 %59, ptr %57, align 8, !tbaa !18
  %60 = load i32, ptr %7, align 4, !tbaa !11
  %61 = sub i32 %60, 16
  store i32 %61, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #3
  br label %36, !llvm.loop !26

62:                                               ; preds = %36
  br label %81

63:                                               ; preds = %3
  br label %64

64:                                               ; preds = %67, %63
  %65 = load i32, ptr %7, align 4, !tbaa !11
  %66 = icmp uge i32 %65, 8
  br i1 %66, label %67, label %80

67:                                               ; preds = %64
  %68 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 3
  %69 = load ptr, ptr %68, align 8, !tbaa !24
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  %70 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 2
  %71 = getelementptr inbounds %struct.anon, ptr %70, i32 0, i32 0
  %72 = load i64, ptr %71, align 8, !tbaa !18
  %73 = trunc i64 %72 to i8
  store i8 %73, ptr %11, align 1, !tbaa !25
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %69, ptr noundef nonnull align 1 dereferenceable(1) %11)
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  %74 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 2
  %75 = getelementptr inbounds %struct.anon, ptr %74, i32 0, i32 0
  %76 = load i64, ptr %75, align 8, !tbaa !18
  %77 = lshr i64 %76, 8
  store i64 %77, ptr %75, align 8, !tbaa !18
  %78 = load i32, ptr %7, align 4, !tbaa !11
  %79 = sub i32 %78, 8
  store i32 %79, ptr %7, align 4, !tbaa !11
  br label %64, !llvm.loop !28

80:                                               ; preds = %64
  br label %81

81:                                               ; preds = %80, %62
  %82 = load i32, ptr %7, align 4, !tbaa !11
  %83 = getelementptr inbounds %"class.gz_generator::BitBuffer", ptr %12, i32 0, i32 2
  %84 = getelementptr inbounds %struct.anon, ptr %83, i32 0, i32 1
  store i32 %82, ptr %84, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZN12gz_generator9BitBuffer7bitFlipEt(i16 noundef zeroext) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 1 dereferenceable(1)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 4}
!14 = !{!"_ZTSN12gz_generator9BitBufferE", !15, i64 0, !12, i64 4, !16, i64 8, !6, i64 24}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSN12gz_generator9BitBufferUt_E", !10, i64 0, !12, i64 8}
!17 = !{!14, !12, i64 16}
!18 = !{!14, !10, i64 8}
!19 = !{!14, !15, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!23, !23, i64 0}
!23 = !{!"short", !7, i64 0}
!24 = !{!14, !6, i64 24}
!25 = !{!7, !7, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = distinct !{!28, !27}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12gz_generator9BitBuffer5writeEmj(ptr nocapture noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = alloca i8, align 1
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = add i32 %8, %2
  store i32 %9, ptr %7, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load i32, ptr %11, align 8, !tbaa !14
  %13 = zext nneg i32 %12 to i64
  %14 = shl i64 %1, %13
  %15 = load i64, ptr %10, align 8, !tbaa !15
  %16 = or i64 %14, %15
  store i64 %16, ptr %10, align 8, !tbaa !15
  %17 = add i32 %12, %2
  %18 = load i8, ptr %0, align 8, !tbaa !16, !range !17, !noundef !18
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %.preheader, label %.preheader14

.preheader14:                                     ; preds = %3
  %20 = icmp ugt i32 %17, 7
  br i1 %20, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader14
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  br label %37

.preheader:                                       ; preds = %3
  %22 = icmp ugt i32 %17, 15
  br i1 %22, label %.lr.ph18, label %.loopexit

.lr.ph18:                                         ; preds = %.preheader
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  br label %24

24:                                               ; preds = %.lr.ph18, %24
  %25 = phi i64 [ %16, %.lr.ph18 ], [ %34, %24 ]
  %.017 = phi i32 [ %17, %.lr.ph18 ], [ %35, %24 ]
  %26 = trunc i64 %25 to i16
  %27 = call noundef zeroext i16 @_ZN12gz_generator9BitBuffer7bitFlipEt(i16 noundef zeroext %26)
  %28 = load ptr, ptr %23, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #3
  %29 = trunc i16 %27 to i8
  store i8 %29, ptr %4, align 1, !tbaa !20
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %28, ptr noundef nonnull align 1 dereferenceable(1) %4)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #3
  %30 = load ptr, ptr %23, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %5) #3
  %31 = lshr i16 %27, 8
  %32 = trunc nuw i16 %31 to i8
  store i8 %32, ptr %5, align 1, !tbaa !20
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %30, ptr noundef nonnull align 1 dereferenceable(1) %5)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %5) #3
  %33 = load i64, ptr %10, align 8, !tbaa !15
  %34 = lshr i64 %33, 16
  store i64 %34, ptr %10, align 8, !tbaa !15
  %35 = add i32 %.017, -16
  %36 = icmp ugt i32 %35, 15
  br i1 %36, label %24, label %.loopexit, !llvm.loop !21

37:                                               ; preds = %.lr.ph, %37
  %38 = phi i64 [ %16, %.lr.ph ], [ %42, %37 ]
  %.116 = phi i32 [ %17, %.lr.ph ], [ %43, %37 ]
  %39 = load ptr, ptr %21, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %6) #3
  %40 = trunc i64 %38 to i8
  store i8 %40, ptr %6, align 1, !tbaa !20
  call void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24) %39, ptr noundef nonnull align 1 dereferenceable(1) %6)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %6) #3
  %41 = load i64, ptr %10, align 8, !tbaa !15
  %42 = lshr i64 %41, 8
  store i64 %42, ptr %10, align 8, !tbaa !15
  %43 = add i32 %.116, -8
  %44 = icmp ugt i32 %43, 7
  br i1 %44, label %37, label %.loopexit, !llvm.loop !23

.loopexit:                                        ; preds = %37, %24, %.preheader14, %.preheader
  %.2 = phi i32 [ %17, %.preheader ], [ %17, %.preheader14 ], [ %35, %24 ], [ %43, %37 ]
  store i32 %.2, ptr %11, align 8, !tbaa !14
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i16 @_ZN12gz_generator9BitBuffer7bitFlipEt(i16 noundef zeroext) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIhSaIhEE9push_backEOh(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 1 dereferenceable(1)) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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, !10, i64 4}
!6 = !{!"_ZTSN12gz_generator9BitBufferE", !7, i64 0, !10, i64 4, !11, i64 8, !13, i64 24}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTSN12gz_generator9BitBufferUt_E", !12, i64 0, !10, i64 8}
!12 = !{!"long", !8, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !12, i64 8}
!16 = !{!6, !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!6, !13, i64 24}
!20 = !{!8, !8, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass