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

; 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 nounwind uwtable
declare dso_local noundef i32 @_ZN7libzpaq5toU16EPKc(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7libzpaq10Compressor11postProcessEPKci(ptr noundef nonnull align 8 dereferenceable(110868) %0, ptr noundef %1, i32 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %8, i32 0, i32 1
  call void @_ZN7libzpaq7Encoder4initEv(ptr noundef nonnull align 8 dereferenceable(110664) %9)
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %47

12:                                               ; preds = %3
  %13 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %8, i32 0, i32 1
  call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %13, i32 noundef 1)
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = icmp sle i32 %14, 0
  br i1 %15, label %16, label %21

16:                                               ; preds = %12
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call noundef i32 @_ZN7libzpaq5toU16EPKc(ptr noundef %17)
  store i32 %18, ptr %6, align 4, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 2
  store ptr %20, ptr %5, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %16, %12
  %22 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %8, i32 0, i32 1
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = and i32 %23, 255
  call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %22, i32 noundef %24)
  %25 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %8, i32 0, i32 1
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = ashr i32 %26, 8
  %28 = and i32 %27, 255
  call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %25, i32 noundef %28)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %43, %21
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %46

34:                                               ; preds = %29
  %35 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %8, i32 0, i32 1
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = sext i8 %40 to i32
  %42 = and i32 %41, 255
  call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %35, i32 noundef %42)
  br label %43

43:                                               ; preds = %34
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %7, align 4, !tbaa !9
  br label %29, !llvm.loop !12

46:                                               ; preds = %33
  br label %49

47:                                               ; preds = %3
  %48 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %8, i32 0, i32 1
  call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %48, i32 noundef 0)
  br label %49

49:                                               ; preds = %47, %46
  %50 = getelementptr inbounds %"class.libzpaq::Compressor", ptr %8, i32 0, i32 3
  store i32 4, ptr %50, align 8, !tbaa !14
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !24, i64 110864}
!15 = !{!"_ZTSN7libzpaq10CompressorE", !16, i64 0, !21, i64 192, !6, i64 110856, !24, i64 110864}
!16 = !{!"_ZTSN7libzpaq5ZPAQLE", !6, i64 0, !6, i64 8, !17, i64 16, !10, i64 40, !10, i64 44, !10, i64 48, !17, i64 56, !19, i64 80, !19, i64 104, !20, 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}
!17 = !{!"_ZTSN7libzpaq5ArrayIhEE", !6, i64 0, !18, i64 8, !10, i64 16}
!18 = !{!"long", !7, i64 0}
!19 = !{!"_ZTSN7libzpaq5ArrayIjEE", !6, i64 0, !18, i64 8, !10, i64 16}
!20 = !{!"_ZTSN7libzpaq5ArrayIcEE", !6, i64 0, !18, i64 8, !10, i64 16}
!21 = !{!"_ZTSN7libzpaq7EncoderE", !6, i64 0, !10, i64 8, !10, i64 12, !22, i64 16, !20, i64 110640}
!22 = !{!"_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, !23, i64 109584, !6, i64 110608, !10, i64 110616}
!23 = !{!"_ZTSN7libzpaq10StateTableE", !7, i64 0}
!24 = !{!"_ZTSN7libzpaq10CompressorUt_E", !7, i64 0}


; 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 i32 @_ZN7libzpaq5toU16EPKc(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7libzpaq10Compressor11postProcessEPKci(ptr noundef nonnull align 8 dereferenceable(110868) %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 192
  tail call void @_ZN7libzpaq7Encoder4initEv(ptr noundef nonnull align 8 dereferenceable(110664) %4)
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %18, label %5

5:                                                ; preds = %3
  tail call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %4, i32 noundef 1)
  %6 = icmp slt i32 %2, 1
  br i1 %6, label %7, label %10

7:                                                ; preds = %5
  %8 = tail call noundef i32 @_ZN7libzpaq5toU16EPKc(ptr noundef nonnull %1)
  %9 = getelementptr inbounds i8, ptr %1, i64 2
  br label %10

10:                                               ; preds = %7, %5
  %.012 = phi ptr [ %9, %7 ], [ %1, %5 ]
  %.011 = phi i32 [ %8, %7 ], [ %2, %5 ]
  %11 = and i32 %.011, 255
  tail call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %4, i32 noundef %11)
  %12 = lshr i32 %.011, 8
  %13 = and i32 %12, 255
  tail call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %4, i32 noundef %13)
  %14 = icmp sgt i32 %.011, 0
  br i1 %14, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %10
  %wide.trip.count = zext nneg i32 %.011 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %15 = getelementptr inbounds i8, ptr %.012, i64 %indvars.iv
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = zext i8 %16 to i32
  tail call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %4, i32 noundef %17)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !8

18:                                               ; preds = %3
  tail call void @_ZN7libzpaq7Encoder8compressEi(ptr noundef nonnull align 8 dereferenceable(110664) %4, i32 noundef 0)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %10, %18
  %19 = getelementptr inbounds i8, ptr %0, i64 110864
  store i32 4, ptr %19, align 8, !tbaa !10
  ret void
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass