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

; 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::Decompresser" = type { %"class.libzpaq::ZPAQL", %"class.libzpaq::Decoder", %"class.libzpaq::PostProcessor", i32, i32 }
%"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::Decoder" = type { ptr, i32, i32, i32, [4 x i8], %"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] }
%"class.libzpaq::PostProcessor" = type { i32, i32, i32, i32, %"class.libzpaq::ZPAQL" }

; 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 nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20), i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7libzpaq7Decoder4initEv(ptr noundef nonnull align 8 dereferenceable(110672)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7libzpaq7Decoder10decompressEv(ptr noundef nonnull align 8 dereferenceable(110672)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7libzpaq13PostProcessor4initEii(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7libzpaq13PostProcessor5writeEi(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7libzpaq12Decompresser10decompressEi(ptr noundef nonnull align 8 dereferenceable(111080) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 4
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %26

12:                                               ; preds = %2
  %13 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 1
  call void @_ZN7libzpaq7Decoder4initEv(ptr noundef nonnull align 8 dereferenceable(110672) %13)
  %14 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 2
  %15 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 0
  %16 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %15, i32 0, i32 2
  %17 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %16, i64 noundef 4)
  %18 = load i8, ptr %17, align 1, !tbaa !24
  %19 = zext i8 %18 to i32
  %20 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 0
  %21 = getelementptr inbounds %"class.libzpaq::ZPAQL", ptr %20, i32 0, i32 2
  %22 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %21, i64 noundef 5)
  %23 = load i8, ptr %22, align 1, !tbaa !24
  %24 = zext i8 %23 to i32
  call void @_ZN7libzpaq13PostProcessor4initEii(ptr noundef nonnull align 8 dereferenceable(208) %14, i32 noundef %19, i32 noundef %24)
  %25 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 4
  store i32 1, ptr %25, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %12, %2
  br label %27

27:                                               ; preds = %32, %26
  %28 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 2
  %29 = call noundef i32 @_ZNK7libzpaq13PostProcessor8getStateEv(ptr noundef nonnull align 8 dereferenceable(208) %28)
  %30 = and i32 %29, 3
  %31 = icmp ne i32 %30, 1
  br i1 %31, label %32, label %37

32:                                               ; preds = %27
  %33 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 2
  %34 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 1
  %35 = call noundef i32 @_ZN7libzpaq7Decoder10decompressEv(ptr noundef nonnull align 8 dereferenceable(110672) %34)
  %36 = call noundef i32 @_ZN7libzpaq13PostProcessor5writeEi(ptr noundef nonnull align 8 dereferenceable(208) %33, i32 noundef %35)
  br label %27, !llvm.loop !25

37:                                               ; preds = %27
  br label %38

38:                                               ; preds = %60, %37
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %61

41:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %42 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 1
  %43 = call noundef i32 @_ZN7libzpaq7Decoder10decompressEv(ptr noundef nonnull align 8 dereferenceable(110672) %42)
  store i32 %43, ptr %6, align 4, !tbaa !9
  %44 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 2
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = call noundef i32 @_ZN7libzpaq13PostProcessor5writeEi(ptr noundef nonnull align 8 dereferenceable(208) %44, i32 noundef %45)
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = icmp eq i32 %47, -1
  br i1 %48, label %49, label %51

49:                                               ; preds = %41
  %50 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %8, i32 0, i32 3
  store i32 4, ptr %50, align 8, !tbaa !27
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %58

51:                                               ; preds = %41
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = icmp sgt i32 %52, 0
  br i1 %53, label %54, label %57

54:                                               ; preds = %51
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %5, align 4, !tbaa !9
  br label %57

57:                                               ; preds = %54, %51
  store i32 0, ptr %7, align 4
  br label %58

58:                                               ; preds = %57, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %59 = load i32, ptr %7, align 4
  switch i32 %59, label %64 [
    i32 0, label %60
    i32 1, label %62
  ]

60:                                               ; preds = %58
  br label %38, !llvm.loop !28

61:                                               ; preds = %38
  store i1 true, ptr %3, align 1
  br label %62

62:                                               ; preds = %61, %58
  %63 = load i1, ptr %3, align 1
  ret i1 %63

64:                                               ; preds = %58
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7libzpaq13PostProcessor8getStateEv(ptr noundef nonnull align 8 dereferenceable(208)) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !23, i64 111076}
!12 = !{!"_ZTSN7libzpaq12DecompresserE", !13, i64 0, !18, i64 192, !21, i64 110864, !22, i64 111072, !23, i64 111076}
!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 = !{!"_ZTSN7libzpaq7DecoderE", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !19, i64 24, !17, i64 110648}
!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 = !{!"_ZTSN7libzpaq13PostProcessorE", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !13, i64 16}
!22 = !{!"_ZTSN7libzpaq12DecompresserUt_E", !7, i64 0}
!23 = !{!"_ZTSN7libzpaq12DecompresserUt0_E", !7, i64 0}
!24 = !{!7, !7, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!12, !22, i64 111072}
!28 = distinct !{!28, !26}


; 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
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20), i64 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7libzpaq7Decoder10decompressEv(ptr noundef nonnull align 8 dereferenceable(110672)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN7libzpaq13PostProcessor5writeEi(ptr noundef nonnull align 8 dereferenceable(208), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7libzpaq12Decompresser10decompressEi(ptr noundef nonnull align 8 dereferenceable(111080) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 111076
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %6, label %16

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 192
  tail call void @_ZN7libzpaq7Decoder4initEv(ptr noundef nonnull align 8 dereferenceable(110672) %7)
  %8 = getelementptr inbounds i8, ptr %0, i64 110864
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %9, i64 noundef 4)
  %11 = load i8, ptr %10, align 1, !tbaa !22
  %12 = zext i8 %11 to i32
  %13 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZN7libzpaq5ArrayIhEixEm(ptr noundef nonnull align 8 dereferenceable(20) %9, i64 noundef 5)
  %14 = load i8, ptr %13, align 1, !tbaa !22
  %15 = zext i8 %14 to i32
  tail call void @_ZN7libzpaq13PostProcessor4initEii(ptr noundef nonnull align 8 dereferenceable(208) %8, i32 noundef %12, i32 noundef %15)
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %6, %2
  %17 = getelementptr inbounds i8, ptr %0, i64 110864
  %18 = tail call noundef i32 @_ZNK7libzpaq13PostProcessor8getStateEv(ptr noundef nonnull align 8 dereferenceable(208) %17)
  %19 = and i32 %18, 3
  %.not16 = icmp eq i32 %19, 1
  br i1 %.not16, label %select.unfold.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %16
  %20 = getelementptr inbounds i8, ptr %0, i64 192
  br label %22

select.unfold.preheader:                          ; preds = %22, %16
  %.not1117 = icmp eq i32 %1, 0
  br i1 %.not1117, label %.loopexit, label %.lr.ph20

.lr.ph20:                                         ; preds = %select.unfold.preheader
  %21 = getelementptr inbounds i8, ptr %0, i64 192
  br label %27

22:                                               ; preds = %.lr.ph, %22
  %23 = tail call noundef i32 @_ZN7libzpaq7Decoder10decompressEv(ptr noundef nonnull align 8 dereferenceable(110672) %20)
  %24 = tail call noundef i32 @_ZN7libzpaq13PostProcessor5writeEi(ptr noundef nonnull align 8 dereferenceable(208) %17, i32 noundef %23)
  %25 = tail call noundef i32 @_ZNK7libzpaq13PostProcessor8getStateEv(ptr noundef nonnull align 8 dereferenceable(208) %17)
  %26 = and i32 %25, 3
  %.not = icmp eq i32 %26, 1
  br i1 %.not, label %select.unfold.preheader, label %22, !llvm.loop !23

27:                                               ; preds = %.lr.ph20, %select.unfold
  %.0818 = phi i32 [ %1, %.lr.ph20 ], [ %spec.select, %select.unfold ]
  %28 = tail call noundef i32 @_ZN7libzpaq7Decoder10decompressEv(ptr noundef nonnull align 8 dereferenceable(110672) %21)
  %29 = tail call noundef i32 @_ZN7libzpaq13PostProcessor5writeEi(ptr noundef nonnull align 8 dereferenceable(208) %17, i32 noundef %28)
  %30 = icmp eq i32 %28, -1
  br i1 %30, label %.thread, label %select.unfold

.thread:                                          ; preds = %27
  %31 = getelementptr inbounds i8, ptr %0, i64 111072
  store i32 4, ptr %31, align 8, !tbaa !25
  br label %.loopexit

select.unfold:                                    ; preds = %27
  %32 = icmp sgt i32 %.0818, 0
  %33 = sext i1 %32 to i32
  %spec.select = add nsw i32 %.0818, %33
  %.not11 = icmp eq i32 %spec.select, 0
  br i1 %.not11, label %.loopexit, label %27

.loopexit:                                        ; preds = %select.unfold, %select.unfold.preheader, %.thread
  %.not1115 = phi i1 [ false, %.thread ], [ true, %select.unfold.preheader ], [ true, %select.unfold ]
  ret i1 %.not1115
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7libzpaq13PostProcessor8getStateEv(ptr noundef nonnull align 8 dereferenceable(208)) local_unnamed_addr #0 align 2

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 = { 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, !21, i64 111076}
!6 = !{!"_ZTSN7libzpaq12DecompresserE", !7, i64 0, !16, i64 192, !19, i64 110864, !20, i64 111072, !21, i64 111076}
!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 = !{!"_ZTSN7libzpaq7DecoderE", !8, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !17, i64 24, !15, i64 110648}
!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 = !{!"_ZTSN7libzpaq13PostProcessorE", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !7, i64 16}
!20 = !{!"_ZTSN7libzpaq12DecompresserUt_E", !9, i64 0}
!21 = !{!"_ZTSN7libzpaq12DecompresserUt0_E", !9, i64 0}
!22 = !{!9, !9, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!6, !20, i64 111072}


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