; LLVM IR from ebiggers/libdeflate :: programs (test_util)

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @flush_bits(ptr noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %18, %1
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.output_bitstream, ptr %5, i32 0, i32 1
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %9, label %35

9:                                                ; preds = %4
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.output_bitstream, ptr %10, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.output_bitstream, ptr %13, i32 0, i32 3
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = icmp eq ptr %12, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %9
  store i1 false, ptr %2, align 1
  br label %38

18:                                               ; preds = %9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.output_bitstream, ptr %19, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = trunc i64 %21 to i8
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.output_bitstream, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %25, i32 1
  store ptr %26, ptr %24, align 8, !tbaa !13
  store i8 %22, ptr %25, align 1, !tbaa !16
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.output_bitstream, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = sub nsw i32 %29, 8
  store i32 %30, ptr %28, align 8, !tbaa !9
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.output_bitstream, ptr %31, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !15
  %34 = lshr i64 %33, 8
  store i64 %34, ptr %32, align 8, !tbaa !15
  br label %4, !llvm.loop !17

35:                                               ; preds = %4
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.output_bitstream, ptr %36, i32 0, i32 1
  store i32 0, ptr %37, align 8, !tbaa !9
  store i1 true, ptr %2, align 1
  br label %38

38:                                               ; preds = %35, %17
  %39 = load i1, ptr %2, align 1
  ret i1 %39
}

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

!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, !12, i64 8}
!10 = !{!"output_bitstream", !11, i64 0, !12, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !11, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @flush_bits(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp slt i32 %3, 1
  br i1 %4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  br label %7

7:                                                ; preds = %.lr.ph, %11
  %8 = load ptr, ptr %5, align 8, !tbaa !12
  %9 = load ptr, ptr %6, align 8, !tbaa !13
  %10 = icmp eq ptr %8, %9
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %7
  %12 = load i64, ptr %0, align 8, !tbaa !14
  %13 = trunc i64 %12 to i8
  %14 = getelementptr inbounds i8, ptr %8, i64 1
  store ptr %14, ptr %5, align 8, !tbaa !12
  store i8 %13, ptr %8, align 1, !tbaa !15
  %15 = load i32, ptr %2, align 8, !tbaa !5
  %16 = add nsw i32 %15, -8
  store i32 %16, ptr %2, align 8, !tbaa !5
  %17 = load i64, ptr %0, align 8, !tbaa !14
  %18 = lshr i64 %17, 8
  store i64 %18, ptr %0, align 8, !tbaa !14
  %19 = icmp slt i32 %15, 9
  br i1 %19, label %._crit_edge, label %7, !llvm.loop !16

._crit_edge:                                      ; preds = %11, %1
  store i32 0, ptr %2, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %7, %._crit_edge
  %20 = phi i1 [ true, %._crit_edge ], [ false, %7 ]
  ret i1 %20
}

attributes #0 = { nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) 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" }

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


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