; 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::CLiteralEncoder2" = type { [768 x %"class.NCompress::NRangeCoder::CBitEncoder"] }
%"class.NCompress::NRangeCoder::CBitEncoder" = type { %"class.NCompress::NRangeCoder::CBitModel" }
%"class.NCompress::NRangeCoder::CBitModel" = type { i32 }

; 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 void @_ZN9NCompress5NLZMA16CLiteralEncoder26EncodeEPNS_11NRangeCoder8CEncoderEh(ptr noundef nonnull align 4 dereferenceable(3072) %0, ptr noundef %1, i8 noundef zeroext %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i8 %2, ptr %6, align 1, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 1, ptr %7, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 8, ptr %8, align 4, !tbaa !10
  br label %11

11:                                               ; preds = %29, %3
  %12 = load i32, ptr %8, align 4, !tbaa !10
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %14 = load i8, ptr %6, align 1, !tbaa !9
  %15 = zext i8 %14 to i32
  %16 = load i32, ptr %8, align 4, !tbaa !10
  %17 = ashr i32 %15, %16
  %18 = and i32 %17, 1
  store i32 %18, ptr %9, align 4, !tbaa !10
  %19 = getelementptr inbounds %"class.NCompress::NLZMA::CLiteralEncoder2", ptr %10, i32 0, i32 0
  %20 = load i32, ptr %7, align 4, !tbaa !10
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds [768 x %"class.NCompress::NRangeCoder::CBitEncoder"], ptr %19, i64 0, i64 %21
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %9, align 4, !tbaa !10
  call void @_ZN9NCompress11NRangeCoder11CBitEncoderILi5EE6EncodeEPNS0_8CEncoderEj(ptr noundef nonnull align 4 dereferenceable(4) %22, ptr noundef %23, i32 noundef %24)
  %25 = load i32, ptr %7, align 4, !tbaa !10
  %26 = shl i32 %25, 1
  %27 = load i32, ptr %9, align 4, !tbaa !10
  %28 = or i32 %26, %27
  store i32 %28, ptr %7, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %29

29:                                               ; preds = %11
  %30 = load i32, ptr %8, align 4, !tbaa !10
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %11, label %32, !llvm.loop !12

32:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN9NCompress11NRangeCoder11CBitEncoderILi5EE6EncodeEPNS0_8CEncoderEj(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef, i32 noundef) #1 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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%"class.NCompress::NRangeCoder::CBitEncoder" = type { %"class.NCompress::NRangeCoder::CBitModel" }
%"class.NCompress::NRangeCoder::CBitModel" = type { i32 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN9NCompress5NLZMA16CLiteralEncoder26EncodeEPNS_11NRangeCoder8CEncoderEh(ptr noundef nonnull align 4 dereferenceable(3072) %0, ptr noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 align 2 {
  %4 = zext i8 %2 to i32
  %5 = lshr i32 %4, 7
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  tail call void @_ZN9NCompress11NRangeCoder11CBitEncoderILi5EE6EncodeEPNS0_8CEncoderEj(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef %1, i32 noundef %5)
  %7 = or disjoint i32 %5, 2
  %8 = lshr i32 %4, 6
  %9 = and i32 %8, 1
  %10 = zext nneg i32 %7 to i64
  %11 = getelementptr inbounds [768 x %"class.NCompress::NRangeCoder::CBitEncoder"], ptr %0, i64 0, i64 %10
  tail call void @_ZN9NCompress11NRangeCoder11CBitEncoderILi5EE6EncodeEPNS0_8CEncoderEj(ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef %1, i32 noundef %9)
  %12 = shl nuw nsw i32 %7, 1
  %13 = or disjoint i32 %9, %12
  %14 = lshr i32 %4, 5
  %15 = and i32 %14, 1
  %16 = zext nneg i32 %13 to i64
  %17 = getelementptr inbounds [768 x %"class.NCompress::NRangeCoder::CBitEncoder"], ptr %0, i64 0, i64 %16
  tail call void @_ZN9NCompress11NRangeCoder11CBitEncoderILi5EE6EncodeEPNS0_8CEncoderEj(ptr noundef nonnull align 4 dereferenceable(4) %17, ptr noundef %1, i32 noundef %15)
  %18 = shl nuw nsw i32 %13, 1
  %19 = or disjoint i32 %15, %18
  %20 = lshr i32 %4, 4
  %21 = and i32 %20, 1
  %22 = zext nneg i32 %19 to i64
  %23 = getelementptr inbounds [768 x %"class.NCompress::NRangeCoder::CBitEncoder"], ptr %0, i64 0, i64 %22
  tail call void @_ZN9NCompress11NRangeCoder11CBitEncoderILi5EE6EncodeEPNS0_8CEncoderEj(ptr noundef nonnull align 4 dereferenceable(4) %23, ptr noundef %1, i32 noundef %21)
  %24 = shl nuw nsw i32 %19, 1
  %25 = or disjoint i32 %21, %24
  %26 = lshr i32 %4, 3
  %27 = and i32 %26, 1
  %28 = zext nneg i32 %25 to i64
  %29 = getelementptr inbounds [768 x %"class.NCompress::NRangeCoder::CBitEncoder"], ptr %0, i64 0, i64 %28
  tail call void @_ZN9NCompress11NRangeCoder11CBitEncoderILi5EE6EncodeEPNS0_8CEncoderEj(ptr noundef nonnull align 4 dereferenceable(4) %29, ptr noundef %1, i32 noundef %27)
  %30 = shl nuw nsw i32 %25, 1
  %31 = or disjoint i32 %27, %30
  %32 = lshr i32 %4, 2
  %33 = and i32 %32, 1
  %34 = zext nneg i32 %31 to i64
  %35 = getelementptr inbounds [768 x %"class.NCompress::NRangeCoder::CBitEncoder"], ptr %0, i64 0, i64 %34
  tail call void @_ZN9NCompress11NRangeCoder11CBitEncoderILi5EE6EncodeEPNS0_8CEncoderEj(ptr noundef nonnull align 4 dereferenceable(4) %35, ptr noundef %1, i32 noundef %33)
  %36 = shl nuw nsw i32 %31, 1
  %37 = or disjoint i32 %33, %36
  %38 = lshr i32 %4, 1
  %39 = and i32 %38, 1
  %40 = zext nneg i32 %37 to i64
  %41 = getelementptr inbounds [768 x %"class.NCompress::NRangeCoder::CBitEncoder"], ptr %0, i64 0, i64 %40
  tail call void @_ZN9NCompress11NRangeCoder11CBitEncoderILi5EE6EncodeEPNS0_8CEncoderEj(ptr noundef nonnull align 4 dereferenceable(4) %41, ptr noundef %1, i32 noundef %39)
  %42 = shl nuw nsw i32 %37, 1
  %43 = or disjoint i32 %39, %42
  %44 = and i32 %4, 1
  %45 = zext nneg i32 %43 to i64
  %46 = getelementptr inbounds [768 x %"class.NCompress::NRangeCoder::CBitEncoder"], ptr %0, i64 0, i64 %45
  tail call void @_ZN9NCompress11NRangeCoder11CBitEncoderILi5EE6EncodeEPNS0_8CEncoderEj(ptr noundef nonnull align 4 dereferenceable(4) %46, ptr noundef %1, i32 noundef %44)
  ret void
}

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass