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

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

@.str.33 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [22 x i8], align 1

; 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

declare void @_ZN7libzpaq5errorEPKc(ptr noundef) #1

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

9:                                                ; preds = %36, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %10 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %7, i32 0, i32 1
  %11 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !23
  %13 = load ptr, ptr %12, align 8, !tbaa !24
  %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 !26
  %17 = load i32, ptr %5, align 4, !tbaa !26
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %19, label %20

19:                                               ; preds = %9
  call void @_ZN7libzpaq5errorEPKc(ptr noundef @.str.33)
  br label %20

20:                                               ; preds = %19, %9
  %21 = load i32, ptr %5, align 4, !tbaa !26
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i32 3, ptr %6, align 4
  br label %34

24:                                               ; preds = %20
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %33

27:                                               ; preds = %24
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !26
  %30 = load ptr, ptr %28, align 8, !tbaa !24
  %31 = getelementptr inbounds ptr, ptr %30, i64 0
  %32 = load ptr, ptr %31, align 8
  call void %32(ptr noundef nonnull align 8 dereferenceable(8) %28, i32 noundef %29)
  br label %33

33:                                               ; preds = %27, %24
  store i32 0, ptr %6, align 4
  br label %34

34:                                               ; preds = %33, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %35 = load i32, ptr %6, align 4
  switch i32 %35, label %48 [
    i32 0, label %36
    i32 3, label %37
  ]

36:                                               ; preds = %34
  br label %9, !llvm.loop !27

37:                                               ; preds = %34
  %38 = getelementptr inbounds %"class.libzpaq::Decompresser", ptr %7, i32 0, i32 1
  %39 = getelementptr inbounds %"class.libzpaq::Decoder", ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !23
  %41 = load ptr, ptr %40, align 8, !tbaa !24
  %42 = getelementptr inbounds ptr, ptr %41, i64 0
  %43 = load ptr, ptr %42, align 8
  %44 = call noundef i32 %43(ptr noundef nonnull align 8 dereferenceable(8) %40)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %37
  call void @_ZN7libzpaq5errorEPKc(ptr noundef @.str.35)
  br label %47

47:                                               ; preds = %46, %37
  ret void

48:                                               ; preds = %34
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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, !21, i64 111072}
!10 = !{!"_ZTSN7libzpaq12DecompresserE", !11, i64 0, !17, i64 192, !20, i64 110864, !21, i64 111072, !22, i64 111076}
!11 = !{!"_ZTSN7libzpaq5ZPAQLE", !6, i64 0, !6, i64 8, !12, i64 16, !14, i64 40, !14, i64 44, !14, i64 48, !12, i64 56, !15, i64 80, !15, i64 104, !16, i64 128, !14, i64 152, !14, i64 156, !14, i64 160, !14, i64 164, !14, i64 168, !14, i64 172, !14, i64 176, !14, i64 180, !6, i64 184}
!12 = !{!"_ZTSN7libzpaq5ArrayIhEE", !6, i64 0, !13, i64 8, !14, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTSN7libzpaq5ArrayIjEE", !6, i64 0, !13, i64 8, !14, i64 16}
!16 = !{!"_ZTSN7libzpaq5ArrayIcEE", !6, i64 0, !13, i64 8, !14, i64 16}
!17 = !{!"_ZTSN7libzpaq7DecoderE", !6, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !18, i64 24, !16, i64 110648}
!18 = !{!"_ZTSN7libzpaq9PredictorE", !14, i64 0, !14, 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, !19, i64 109584, !6, i64 110608, !14, i64 110616}
!19 = !{!"_ZTSN7libzpaq10StateTableE", !7, i64 0}
!20 = !{!"_ZTSN7libzpaq13PostProcessorE", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !11, i64 16}
!21 = !{!"_ZTSN7libzpaq12DecompresserUt_E", !7, i64 0}
!22 = !{!"_ZTSN7libzpaq12DecompresserUt0_E", !7, i64 0}
!23 = !{!10, !6, i64 192}
!24 = !{!25, !25, i64 0}
!25 = !{!"vtable pointer", !8, i64 0}
!26 = !{!14, !14, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"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"

@.str.33 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [22 x i8], align 1

declare void @_ZN7libzpaq5errorEPKc(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7libzpaq12Decompresser11readCommentEPNS_6WriterE(ptr nocapture noundef nonnull align 8 dereferenceable(111080) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 111072
  store i32 3, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 192
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %.split.us, label %.split

.split.us:                                        ; preds = %2, %.split.us.backedge
  %5 = load ptr, ptr %4, align 8, !tbaa !22
  %6 = load ptr, ptr %5, align 8, !tbaa !23
  %7 = load ptr, ptr %6, align 8
  %8 = tail call noundef i32 %7(ptr noundef nonnull align 8 dereferenceable(8) %5)
  switch i32 %8, label %.split.us.backedge [
    i32 -1, label %9
    i32 0, label %.split12.us
  ]

9:                                                ; preds = %.split.us
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.33)
  br label %.split.us.backedge

.split.us.backedge:                               ; preds = %9, %.split.us
  br label %.split.us

.split:                                           ; preds = %2, %15
  %10 = load ptr, ptr %4, align 8, !tbaa !22
  %11 = load ptr, ptr %10, align 8, !tbaa !23
  %12 = load ptr, ptr %11, align 8
  %13 = tail call noundef i32 %12(ptr noundef nonnull align 8 dereferenceable(8) %10)
  switch i32 %13, label %15 [
    i32 -1, label %14
    i32 0, label %.split12.us
  ]

14:                                               ; preds = %.split
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.33)
  br label %15

15:                                               ; preds = %14, %.split
  %16 = load ptr, ptr %1, align 8, !tbaa !23
  %17 = load ptr, ptr %16, align 8
  tail call void %17(ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %13)
  br label %.split

.split12.us:                                      ; preds = %.split, %.split.us
  %18 = load ptr, ptr %4, align 8, !tbaa !22
  %19 = load ptr, ptr %18, align 8, !tbaa !23
  %20 = load ptr, ptr %19, align 8
  %21 = tail call noundef i32 %20(ptr noundef nonnull align 8 dereferenceable(8) %18)
  %.not8 = icmp eq i32 %21, 0
  br i1 %.not8, label %23, label %22

22:                                               ; preds = %.split12.us
  tail call void @_ZN7libzpaq5errorEPKc(ptr noundef nonnull @.str.35)
  br label %23

23:                                               ; preds = %22, %.split12.us
  ret void
}

attributes #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, !20, i64 111072}
!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 = !{!6, !8, i64 192}
!23 = !{!24, !24, i64 0}
!24 = !{!"vtable pointer", !10, i64 0}


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