; LLVM IR from mncoppola/rpef :: utilities_src/squashfs2.1/lzma/C/7zip/Compress/LZMA (LZMAEncoder)

; 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.NCompress::NLZMA::NLength::CEncoder" = type { %"class.NCompress::NRangeCoder::CBitEncoder", %"class.NCompress::NRangeCoder::CBitEncoder", [16 x %"class.NCompress::NRangeCoder::CBitTreeEncoder"], [16 x %"class.NCompress::NRangeCoder::CBitTreeEncoder"], %"class.NCompress::NRangeCoder::CBitTreeEncoder.4" }
%"class.NCompress::NRangeCoder::CBitEncoder" = type { %"class.NCompress::NRangeCoder::CBitModel" }
%"class.NCompress::NRangeCoder::CBitModel" = type { i32 }
%"class.NCompress::NRangeCoder::CBitTreeEncoder" = type { [8 x %"class.NCompress::NRangeCoder::CBitEncoder"] }
%"class.NCompress::NRangeCoder::CBitTreeEncoder.4" = type { [256 x %"class.NCompress::NRangeCoder::CBitEncoder"] }

; 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
define dso_local noundef i32 @_ZNK9NCompress5NLZMA7NLength8CEncoder8GetPriceEjj(ptr noundef nonnull align 4 dereferenceable(2056) %0, i32 noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %9 = load ptr, ptr %5, align 8
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp ult i32 %10, 8
  br i1 %11, label %12, label %22

12:                                               ; preds = %3
  %13 = getelementptr inbounds %"class.NCompress::NLZMA::NLength::CEncoder", ptr %9, i32 0, i32 0
  %14 = call noundef i32 @_ZNK9NCompress11NRangeCoder11CBitEncoderILi5EE9GetPrice0Ev(ptr noundef nonnull align 4 dereferenceable(4) %13)
  %15 = getelementptr inbounds %"class.NCompress::NLZMA::NLength::CEncoder", ptr %9, i32 0, i32 2
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds [16 x %"class.NCompress::NRangeCoder::CBitTreeEncoder"], ptr %15, i64 0, i64 %17
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = call noundef i32 @_ZNK9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi3EE8GetPriceEj(ptr noundef nonnull align 4 dereferenceable(32) %18, i32 noundef %19)
  %21 = add i32 %14, %20
  store i32 %21, ptr %4, align 4
  br label %55

22:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %23 = getelementptr inbounds %"class.NCompress::NLZMA::NLength::CEncoder", ptr %9, i32 0, i32 0
  %24 = call noundef i32 @_ZNK9NCompress11NRangeCoder11CBitEncoderILi5EE9GetPrice1Ev(ptr noundef nonnull align 4 dereferenceable(4) %23)
  store i32 %24, ptr %8, align 4, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp ult i32 %25, 16
  br i1 %26, label %27, label %41

27:                                               ; preds = %22
  %28 = getelementptr inbounds %"class.NCompress::NLZMA::NLength::CEncoder", ptr %9, i32 0, i32 1
  %29 = call noundef i32 @_ZNK9NCompress11NRangeCoder11CBitEncoderILi5EE9GetPrice0Ev(ptr noundef nonnull align 4 dereferenceable(4) %28)
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = add i32 %30, %29
  store i32 %31, ptr %8, align 4, !tbaa !9
  %32 = getelementptr inbounds %"class.NCompress::NLZMA::NLength::CEncoder", ptr %9, i32 0, i32 3
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds [16 x %"class.NCompress::NRangeCoder::CBitTreeEncoder"], ptr %32, i64 0, i64 %34
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = sub i32 %36, 8
  %38 = call noundef i32 @_ZNK9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi3EE8GetPriceEj(ptr noundef nonnull align 4 dereferenceable(32) %35, i32 noundef %37)
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = add i32 %39, %38
  store i32 %40, ptr %8, align 4, !tbaa !9
  br label %53

41:                                               ; preds = %22
  %42 = getelementptr inbounds %"class.NCompress::NLZMA::NLength::CEncoder", ptr %9, i32 0, i32 1
  %43 = call noundef i32 @_ZNK9NCompress11NRangeCoder11CBitEncoderILi5EE9GetPrice1Ev(ptr noundef nonnull align 4 dereferenceable(4) %42)
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = add i32 %44, %43
  store i32 %45, ptr %8, align 4, !tbaa !9
  %46 = getelementptr inbounds %"class.NCompress::NLZMA::NLength::CEncoder", ptr %9, i32 0, i32 4
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = sub i32 %47, 8
  %49 = sub i32 %48, 8
  %50 = call noundef i32 @_ZNK9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi8EE8GetPriceEj(ptr noundef nonnull align 4 dereferenceable(1024) %46, i32 noundef %49)
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = add i32 %51, %50
  store i32 %52, ptr %8, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %41, %27
  %54 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %54, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %55

55:                                               ; preds = %53, %12
  %56 = load i32, ptr %4, align 4
  ret i32 %56
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9NCompress11NRangeCoder11CBitEncoderILi5EE9GetPrice0Ev(ptr noundef nonnull align 4 dereferenceable(4)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi3EE8GetPriceEj(ptr noundef nonnull align 4 dereferenceable(32), i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9NCompress11NRangeCoder11CBitEncoderILi5EE9GetPrice1Ev(ptr noundef nonnull align 4 dereferenceable(4)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi8EE8GetPriceEj(ptr noundef nonnull align 4 dereferenceable(1024), i32 noundef) #2 align 2

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


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

%"class.NCompress::NRangeCoder::CBitTreeEncoder" = type { [8 x %"class.NCompress::NRangeCoder::CBitEncoder"] }
%"class.NCompress::NRangeCoder::CBitEncoder" = type { %"class.NCompress::NRangeCoder::CBitModel" }
%"class.NCompress::NRangeCoder::CBitModel" = type { i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZNK9NCompress5NLZMA7NLength8CEncoder8GetPriceEjj(ptr noundef nonnull align 4 dereferenceable(2056) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = icmp ult i32 %1, 8
  br i1 %4, label %5, label %12

5:                                                ; preds = %3
  %6 = tail call noundef i32 @_ZNK9NCompress11NRangeCoder11CBitEncoderILi5EE9GetPrice0Ev(ptr noundef nonnull align 4 dereferenceable(4) %0)
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = zext i32 %2 to i64
  %9 = getelementptr inbounds [16 x %"class.NCompress::NRangeCoder::CBitTreeEncoder"], ptr %7, i64 0, i64 %8
  %10 = tail call noundef i32 @_ZNK9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi3EE8GetPriceEj(ptr noundef nonnull align 4 dereferenceable(32) %9, i32 noundef %1)
  %11 = add i32 %10, %6
  br label %32

12:                                               ; preds = %3
  %13 = tail call noundef i32 @_ZNK9NCompress11NRangeCoder11CBitEncoderILi5EE9GetPrice1Ev(ptr noundef nonnull align 4 dereferenceable(4) %0)
  %14 = icmp ult i32 %1, 16
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  br i1 %14, label %16, label %25

16:                                               ; preds = %12
  %17 = tail call noundef i32 @_ZNK9NCompress11NRangeCoder11CBitEncoderILi5EE9GetPrice0Ev(ptr noundef nonnull align 4 dereferenceable(4) %15)
  %18 = add i32 %17, %13
  %19 = getelementptr inbounds i8, ptr %0, i64 520
  %20 = zext i32 %2 to i64
  %21 = getelementptr inbounds [16 x %"class.NCompress::NRangeCoder::CBitTreeEncoder"], ptr %19, i64 0, i64 %20
  %22 = add nsw i32 %1, -8
  %23 = tail call noundef i32 @_ZNK9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi3EE8GetPriceEj(ptr noundef nonnull align 4 dereferenceable(32) %21, i32 noundef %22)
  %24 = add i32 %18, %23
  br label %32

25:                                               ; preds = %12
  %26 = tail call noundef i32 @_ZNK9NCompress11NRangeCoder11CBitEncoderILi5EE9GetPrice1Ev(ptr noundef nonnull align 4 dereferenceable(4) %15)
  %27 = add i32 %26, %13
  %28 = getelementptr inbounds i8, ptr %0, i64 1032
  %29 = add i32 %1, -16
  %30 = tail call noundef i32 @_ZNK9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi8EE8GetPriceEj(ptr noundef nonnull align 4 dereferenceable(1024) %28, i32 noundef %29)
  %31 = add i32 %27, %30
  br label %32

32:                                               ; preds = %16, %25, %5
  %.013 = phi i32 [ %11, %5 ], [ %24, %16 ], [ %31, %25 ]
  ret i32 %.013
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi3EE8GetPriceEj(ptr noundef nonnull align 4 dereferenceable(32), i32 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK9NCompress11NRangeCoder15CBitTreeEncoderILi5ELi8EE8GetPriceEj(ptr noundef nonnull align 4 dereferenceable(1024), i32 noundef) 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" }

!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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass