; LLVM IR from fwip/fastqz :: libzpaq.ll (ZN7libzpaq10Compressor8compressEi)

; 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.libzpaq::Compressor" = type <{ %"class.libzpaq::ZPAQL", %"class.libzpaq::Encoder", ptr, i32, [4 x i8] }>
%"class.libzpaq::ZPAQL" = type { ptr, ptr, %"class.libzpaq::Array.0", i32, i32, i32, [4 x i8], %"class.libzpaq::Array.0", %"class.libzpaq::Array", %"class.libzpaq::Array", %"class.libzpaq::Array.4", i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%"class.libzpaq::Array.0" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::Array" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::Array.4" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::Encoder" = type { ptr, i32, i32, %"class.libzpaq::Predictor", %"class.libzpaq::Array.4" }
%"class.libzpaq::Predictor" = type <{ i32, i32, [256 x i32], [256 x i32], ptr, [256 x %"struct.libzpaq::Component"], [256 x i32], [1024 x i32], [4096 x i16], [32768 x i16], %"class.libzpaq::StateTable", ptr, i32, [4 x i8] }>
%"struct.libzpaq::Component" = type { i64, i64, i64, i64, i64, %"class.libzpaq::Array", %"class.libzpaq::Array.0", %"class.libzpaq::Array.2" }
%"class.libzpaq::Array.2" = type <{ ptr, i64, i32, [4 x i8] }>
%"class.libzpaq::StateTable" = type { [1024 x i8] }

; 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
declare dso_local void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7libzpaq10Compressor8compressEi(ptr noundef nonnull align 8 dereferenceable(110868) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %28, %2
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %10, label %18

10:                                               ; preds = %7
  %11 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %6, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load ptr, ptr %12, align 8, !tbaa !22
  %14 = getelementptr inbounds ptr, ptr %13, i64 0
  %15 = load ptr, ptr %14, align 8
  %16 = call noundef i32 %15(ptr noundef nonnull align 8 dereferenceable(8) %12)
  store i32 %16, ptr %5, align 4, !tbaa !9
  %17 = icmp sge i32 %16, 0
  br label %18

18:                                               ; preds = %10, %7
  %19 = phi i1 [ false, %7 ], [ %17, %10 ]
  br i1 %19, label %20, label %29

20:                                               ; preds = %18
  %21 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %6, i32 0, i32 1
  %22 = load i32, ptr %5, align 4, !tbaa !9
  call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %21, i32 noundef %22)
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %20
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %4, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %25, %20
  br label %7, !llvm.loop !24

29:                                               ; preds = %18
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = icmp sge i32 %30, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i1 %31
}

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 110856}
!12 = !{!"_ZTSN7libzpaq10CompressorE", !13, i64 0, !18, i64 192, !6, i64 110856, !21, i64 110864}
!13 = !{!"_ZTSN7libzpaq5ZPAQLE", !6, i64 0, !6, i64 8, !14, i64 16, !10, i64 40, !10, i64 44, !10, i64 48, !14, i64 56, !16, i64 80, !16, i64 104, !17, i64 128, !10, i64 152, !10, i64 156, !10, i64 160, !10, i64 164, !10, i64 168, !10, i64 172, !10, i64 176, !10, i64 180, !6, i64 184}
!14 = !{!"_ZTSN7libzpaq5ArrayIhEE", !6, i64 0, !15, i64 8, !10, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!"_ZTSN7libzpaq5ArrayIjEE", !6, i64 0, !15, i64 8, !10, i64 16}
!17 = !{!"_ZTSN7libzpaq5ArrayIcEE", !6, i64 0, !15, i64 8, !10, i64 16}
!18 = !{!"_ZTSN7libzpaq7EncoderE", !6, i64 0, !10, i64 8, !10, i64 12, !19, i64 16, !17, i64 110640}
!19 = !{!"_ZTSN7libzpaq9PredictorE", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 1032, !6, i64 2056, !7, i64 2064, !7, i64 30736, !7, i64 31760, !7, i64 35856, !7, i64 44048, !20, i64 109584, !6, i64 110608, !10, i64 110616}
!20 = !{!"_ZTSN7libzpaq10StateTableE", !7, i64 0}
!21 = !{!"_ZTSN7libzpaq10CompressorUt_E", !7, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !8, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"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: mustprogress uwtable
declare dso_local void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7libzpaq10Compressor8compressEi(ptr noundef nonnull align 8 dereferenceable(110868) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 110856
  %.not9 = icmp eq i32 %1, 0
  br i1 %.not9, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 192
  br label %5

5:                                                ; preds = %.lr.ph, %select.unfold
  %.0510 = phi i32 [ %1, %.lr.ph ], [ %spec.select, %select.unfold ]
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %6, align 8, !tbaa !20
  %8 = load ptr, ptr %7, align 8
  %9 = tail call noundef i32 %8(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %10 = icmp sgt i32 %9, -1
  br i1 %10, label %select.unfold, label %.critedge

select.unfold:                                    ; preds = %5
  tail call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %4, i32 noundef %9)
  %11 = icmp sgt i32 %.0510, 0
  %12 = sext i1 %11 to i32
  %spec.select = add nsw i32 %.0510, %12
  %.not = icmp eq i32 %spec.select, 0
  br i1 %.not, label %.critedge, label %5

.critedge:                                        ; preds = %5, %select.unfold, %2
  %.not.lcssa = phi i1 [ true, %2 ], [ %10, %select.unfold ], [ %10, %5 ]
  ret i1 %.not.lcssa
}

attributes #0 = { 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" }

!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, !8, i64 110856}
!6 = !{!"_ZTSN7libzpaq10CompressorE", !7, i64 0, !16, i64 192, !8, i64 110856, !19, i64 110864}
!7 = !{!"_ZTSN7libzpaq5ZPAQLE", !8, i64 0, !8, i64 8, !11, i64 16, !13, i64 40, !13, i64 44, !13, i64 48, !11, i64 56, !14, i64 80, !14, i64 104, !15, i64 128, !13, i64 152, !13, i64 156, !13, i64 160, !13, i64 164, !13, i64 168, !13, i64 172, !13, i64 176, !13, i64 180, !8, i64 184}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN7libzpaq5ArrayIhEE", !8, i64 0, !12, i64 8, !13, i64 16}
!12 = !{!"long", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!"_ZTSN7libzpaq5ArrayIjEE", !8, i64 0, !12, i64 8, !13, i64 16}
!15 = !{!"_ZTSN7libzpaq5ArrayIcEE", !8, i64 0, !12, i64 8, !13, i64 16}
!16 = !{!"_ZTSN7libzpaq7EncoderE", !8, i64 0, !13, i64 8, !13, i64 12, !17, i64 16, !15, i64 110640}
!17 = !{!"_ZTSN7libzpaq9PredictorE", !13, i64 0, !13, i64 4, !9, i64 8, !9, i64 1032, !8, i64 2056, !9, i64 2064, !9, i64 30736, !9, i64 31760, !9, i64 35856, !9, i64 44048, !18, i64 109584, !8, i64 110608, !13, i64 110616}
!18 = !{!"_ZTSN7libzpaq10StateTableE", !9, i64 0}
!19 = !{!"_ZTSN7libzpaq10CompressorUt_E", !9, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !10, i64 0}


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