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

; 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: mustprogress uwtable
define dso_local void @_ZN7libzpaq10Compressor12startSegmentEPKcS2_(ptr noundef nonnull align 8 dereferenceable(110868) %0, ptr noundef %1, ptr noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8
  %8 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %7, i32 0, i32 1
  %9 = getelementptr inbounds %"class.libzpaq::Encoder", ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = load ptr, ptr %10, align 8, !tbaa !21
  %12 = getelementptr inbounds ptr, ptr %11, i64 0
  %13 = load ptr, ptr %12, align 8
  call void %13(ptr noundef nonnull align 8 dereferenceable(8) %10, i32 noundef 1)
  br label %14

14:                                               ; preds = %23, %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %21

17:                                               ; preds = %14
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !23
  %20 = icmp ne i8 %19, 0
  br label %21

21:                                               ; preds = %17, %14
  %22 = phi i1 [ false, %14 ], [ %20, %17 ]
  br i1 %22, label %23, label %34

23:                                               ; preds = %21
  %24 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %7, i32 0, i32 1
  %25 = getelementptr inbounds %"class.libzpaq::Encoder", ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i32 1
  store ptr %28, ptr %5, align 8, !tbaa !5
  %29 = load i8, ptr %27, align 1, !tbaa !23
  %30 = sext i8 %29 to i32
  %31 = load ptr, ptr %26, align 8, !tbaa !21
  %32 = getelementptr inbounds ptr, ptr %31, i64 0
  %33 = load ptr, ptr %32, align 8
  call void %33(ptr noundef nonnull align 8 dereferenceable(8) %26, i32 noundef %30)
  br label %14, !llvm.loop !24

34:                                               ; preds = %21
  %35 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %7, i32 0, i32 1
  %36 = getelementptr inbounds %"class.libzpaq::Encoder", ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = load ptr, ptr %37, align 8, !tbaa !21
  %39 = getelementptr inbounds ptr, ptr %38, i64 0
  %40 = load ptr, ptr %39, align 8
  call void %40(ptr noundef nonnull align 8 dereferenceable(8) %37, i32 noundef 0)
  br label %41

41:                                               ; preds = %50, %34
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %48

44:                                               ; preds = %41
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = load i8, ptr %45, align 1, !tbaa !23
  %47 = icmp ne i8 %46, 0
  br label %48

48:                                               ; preds = %44, %41
  %49 = phi i1 [ false, %41 ], [ %47, %44 ]
  br i1 %49, label %50, label %61

50:                                               ; preds = %48
  %51 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %7, i32 0, i32 1
  %52 = getelementptr inbounds %"class.libzpaq::Encoder", ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %6, align 8, !tbaa !5
  %56 = load i8, ptr %54, align 1, !tbaa !23
  %57 = sext i8 %56 to i32
  %58 = load ptr, ptr %53, align 8, !tbaa !21
  %59 = getelementptr inbounds ptr, ptr %58, i64 0
  %60 = load ptr, ptr %59, align 8
  call void %60(ptr noundef nonnull align 8 dereferenceable(8) %53, i32 noundef %57)
  br label %41, !llvm.loop !26

61:                                               ; preds = %48
  %62 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %7, i32 0, i32 1
  %63 = getelementptr inbounds %"class.libzpaq::Encoder", ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !9
  %65 = load ptr, ptr %64, align 8, !tbaa !21
  %66 = getelementptr inbounds ptr, ptr %65, i64 0
  %67 = load ptr, ptr %66, align 8
  call void %67(ptr noundef nonnull align 8 dereferenceable(8) %64, i32 noundef 0)
  %68 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %7, i32 0, i32 1
  %69 = getelementptr inbounds %"class.libzpaq::Encoder", ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !9
  %71 = load ptr, ptr %70, align 8, !tbaa !21
  %72 = getelementptr inbounds ptr, ptr %71, i64 0
  %73 = load ptr, ptr %72, align 8
  call void %73(ptr noundef nonnull align 8 dereferenceable(8) %70, i32 noundef 0)
  %74 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %7, i32 0, i32 3
  %75 = load i32, ptr %74, align 8, !tbaa !27
  %76 = icmp eq i32 %75, 1
  br i1 %76, label %77, label %79

77:                                               ; preds = %61
  %78 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %7, i32 0, i32 3
  store i32 2, ptr %78, align 8, !tbaa !27
  br label %79

79:                                               ; preds = %77, %61
  %80 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %7, i32 0, i32 3
  %81 = load i32, ptr %80, align 8, !tbaa !27
  %82 = icmp eq i32 %81, 3
  br i1 %82, label %83, label %85

83:                                               ; preds = %79
  %84 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %7, i32 0, i32 3
  store i32 4, ptr %84, align 8, !tbaa !27
  br label %85

85:                                               ; preds = %83, %79
  ret void
}

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 192}
!10 = !{!"_ZTSN7libzpaq10CompressorE", !11, i64 0, !17, i64 192, !6, i64 110856, !20, i64 110864}
!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 = !{!"_ZTSN7libzpaq7EncoderE", !6, i64 0, !14, i64 8, !14, i64 12, !18, i64 16, !16, i64 110640}
!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 = !{!"_ZTSN7libzpaq10CompressorUt_E", !7, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"vtable pointer", !8, i64 0}
!23 = !{!7, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}
!27 = !{!10, !20, i64 110864}


; 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
define dso_local void @_ZN7libzpaq10Compressor12startSegmentEPKcS2_(ptr nocapture noundef nonnull align 8 dereferenceable(110868) %0, ptr noundef readonly %1, ptr noundef readonly %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 192
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !20
  %7 = load ptr, ptr %6, align 8
  tail call void %7(ptr noundef nonnull align 8 dereferenceable(8) %5, i32 noundef 1)
  %.not15 = icmp eq ptr %1, null
  br i1 %.not15, label %.critedge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %8 = load i8, ptr %1, align 1, !tbaa !22
  %.not1222 = icmp eq i8 %8, 0
  br i1 %.not1222, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %9 = phi i8 [ %15, %.lr.ph ], [ %8, %.lr.ph.preheader ]
  %.091623 = phi ptr [ %11, %.lr.ph ], [ %1, %.lr.ph.preheader ]
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %.091623, i64 1
  %12 = sext i8 %9 to i32
  %13 = load ptr, ptr %10, align 8, !tbaa !20
  %14 = load ptr, ptr %13, align 8
  tail call void %14(ptr noundef nonnull align 8 dereferenceable(8) %10, i32 noundef %12)
  %15 = load i8, ptr %11, align 1, !tbaa !22
  %.not12 = icmp eq i8 %15, 0
  br i1 %.not12, label %.critedge, label %.lr.ph

.critedge:                                        ; preds = %.lr.ph, %.lr.ph.preheader, %3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load ptr, ptr %16, align 8, !tbaa !20
  %18 = load ptr, ptr %17, align 8
  tail call void %18(ptr noundef nonnull align 8 dereferenceable(8) %16, i32 noundef 0)
  %.not1318 = icmp eq ptr %2, null
  br i1 %.not1318, label %.critedge2, label %.lr.ph20.preheader

.lr.ph20.preheader:                               ; preds = %.critedge
  %19 = load i8, ptr %2, align 1, !tbaa !22
  %.not1425 = icmp eq i8 %19, 0
  br i1 %.not1425, label %.critedge2, label %.lr.ph20

.lr.ph20:                                         ; preds = %.lr.ph20.preheader, %.lr.ph20
  %20 = phi i8 [ %26, %.lr.ph20 ], [ %19, %.lr.ph20.preheader ]
  %.01926 = phi ptr [ %22, %.lr.ph20 ], [ %2, %.lr.ph20.preheader ]
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.01926, i64 1
  %23 = sext i8 %20 to i32
  %24 = load ptr, ptr %21, align 8, !tbaa !20
  %25 = load ptr, ptr %24, align 8
  tail call void %25(ptr noundef nonnull align 8 dereferenceable(8) %21, i32 noundef %23)
  %26 = load i8, ptr %22, align 1, !tbaa !22
  %.not14 = icmp eq i8 %26, 0
  br i1 %.not14, label %.critedge2, label %.lr.ph20

.critedge2:                                       ; preds = %.lr.ph20, %.lr.ph20.preheader, %.critedge
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load ptr, ptr %27, align 8, !tbaa !20
  %29 = load ptr, ptr %28, align 8
  tail call void %29(ptr noundef nonnull align 8 dereferenceable(8) %27, i32 noundef 0)
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %30, align 8, !tbaa !20
  %32 = load ptr, ptr %31, align 8
  tail call void %32(ptr noundef nonnull align 8 dereferenceable(8) %30, i32 noundef 0)
  %33 = getelementptr inbounds i8, ptr %0, i64 110864
  %34 = load i32, ptr %33, align 8, !tbaa !23
  switch i32 %34, label %36 [
    i32 1, label %.sink.split
    i32 3, label %35
  ]

35:                                               ; preds = %.critedge2
  br label %.sink.split

.sink.split:                                      ; preds = %.critedge2, %35
  %.sink = phi i32 [ 4, %35 ], [ 2, %.critedge2 ]
  store i32 %.sink, ptr %33, align 8, !tbaa !23
  br label %36

36:                                               ; preds = %.sink.split, %.critedge2
  ret void
}

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 192}
!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}
!22 = !{!9, !9, i64 0}
!23 = !{!6, !19, i64 110864}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass