; 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.CLZInWindow = type { ptr, ptr, ptr, i32, i8, ptr, ptr, i32, i32, i32, i32, i32, i32 }
%"class.NPat2::CPatricia" = type { %struct.IMatchFinder, %struct.IMatchFinderSetCallback, %class.CMyUnknownImp, %class.CLZInWindow, i32, i32, ptr, ptr, i32, i32, i32, i32, i8, i32, ptr, %class.CMyComPtr }
%struct.IMatchFinder = type { %struct.IInWindowStream }
%struct.IInWindowStream = type { %struct.IUnknown }
%struct.IUnknown = type { ptr }
%struct.IMatchFinderSetCallback = type { %struct.IUnknown }
%class.CMyUnknownImp = type { i32 }
%class.CMyComPtr = type { ptr }
%"union.NPat2::CDescendant" = 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 nounwind uwtable
declare dso_local void @_ZN11CLZInWindow13ReduceOffsetsEi(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5NPat29CPatricia27TestRemoveNodesAndNormalizeEv(ptr noundef nonnull align 8 dereferenceable(160) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  %8 = getelementptr inbounds %class.CLZInWindow, ptr %7, i32 0, i32 8
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %6, i32 0, i32 4
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = sub i32 %9, %11
  store i32 %12, ptr %3, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %13 = getelementptr inbounds i8, ptr %6, i64 24
  %14 = getelementptr inbounds %class.CLZInWindow, ptr %13, i32 0, i32 8
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = add i32 -2147483648, %15
  %17 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %6, i32 0, i32 4
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = sub i32 %16, %18
  %20 = add i32 %19, 2
  store i32 %20, ptr %4, align 4, !tbaa !21
  %21 = getelementptr inbounds i8, ptr %6, i64 24
  %22 = load i32, ptr %3, align 4, !tbaa !21
  call void @_ZN11CLZInWindow13ReduceOffsetsEi(ptr noundef nonnull align 8 dereferenceable(72) %21, i32 noundef %22)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !21
  br label %23

23:                                               ; preds = %35, %1
  %24 = load i32, ptr %5, align 4, !tbaa !21
  %25 = icmp ult i32 %24, 65536
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %38

27:                                               ; preds = %23
  %28 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %6, i32 0, i32 6
  %29 = load ptr, ptr %28, align 8, !tbaa !22
  %30 = load i32, ptr %5, align 4, !tbaa !21
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds %"union.NPat2::CDescendant", ptr %29, i64 %31
  %33 = load i32, ptr %4, align 4, !tbaa !21
  %34 = load i32, ptr %3, align 4, !tbaa !21
  call void @_ZN5NPat29CPatricia32TestRemoveAndNormalizeDescendantERNS_11CDescendantEjj(ptr noundef nonnull align 8 dereferenceable(160) %6, ptr noundef nonnull align 4 dereferenceable(4) %32, i32 noundef %33, i32 noundef %34)
  br label %35

35:                                               ; preds = %27
  %36 = load i32, ptr %5, align 4, !tbaa !21
  %37 = add i32 %36, 1
  store i32 %37, ptr %5, align 4, !tbaa !21
  br label %23, !llvm.loop !23

38:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !11, i64 52}
!10 = !{!"_ZTS11CLZInWindow", !6, i64 8, !6, i64 16, !11, i64 24, !12, i64 28, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !11, i64 96}
!14 = !{!"_ZTSN5NPat29CPatriciaE", !15, i64 0, !18, i64 8, !19, i64 16, !10, i64 24, !11, i64 96, !11, i64 100, !6, i64 104, !6, i64 112, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !12, i64 136, !11, i64 140, !6, i64 144, !20, i64 152}
!15 = !{!"_ZTS12IMatchFinder", !16, i64 0}
!16 = !{!"_ZTS15IInWindowStream", !17, i64 0}
!17 = !{!"_ZTS8IUnknown"}
!18 = !{!"_ZTS23IMatchFinderSetCallback", !17, i64 0}
!19 = !{!"_ZTS13CMyUnknownImp", !11, i64 0}
!20 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !6, i64 0}
!21 = !{!11, !11, i64 0}
!22 = !{!14, !6, i64 104}
!23 = distinct !{!23, !24}
!24 = !{!"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"

%"union.NPat2::CDescendant" = type { i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11CLZInWindow13ReduceOffsetsEi(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5NPat29CPatricia27TestRemoveNodesAndNormalizeEv(ptr noundef nonnull align 8 dereferenceable(160) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = getelementptr inbounds i8, ptr %0, i64 76
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  %6 = load i32, ptr %5, align 8, !tbaa !12
  %7 = sub i32 %4, %6
  %8 = xor i32 %4, -2147483648
  %reass.sub = sub i32 %8, %6
  %9 = add i32 %reass.sub, 2
  tail call void @_ZN11CLZInWindow13ReduceOffsetsEi(ptr noundef nonnull align 8 dereferenceable(72) %2, i32 noundef %7)
  %10 = getelementptr inbounds i8, ptr %0, i64 104
  br label %12

11:                                               ; preds = %12
  ret void

12:                                               ; preds = %1, %12
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %12 ]
  %13 = load ptr, ptr %10, align 8, !tbaa !20
  %14 = getelementptr inbounds %"union.NPat2::CDescendant", ptr %13, i64 %indvars.iv
  tail call void @_ZN5NPat29CPatricia32TestRemoveAndNormalizeDescendantERNS_11CDescendantEjj(ptr noundef nonnull align 8 dereferenceable(160) %0, ptr noundef nonnull align 4 dereferenceable(4) %14, i32 noundef %9, i32 noundef %7)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 65536
  br i1 %exitcond.not, label %11, label %12, !llvm.loop !21
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5NPat29CPatricia32TestRemoveAndNormalizeDescendantERNS_11CDescendantEjj(ptr noundef nonnull align 8 dereferenceable(160), ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) local_unnamed_addr #1 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" }
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, !10, i64 52}
!6 = !{!"_ZTS11CLZInWindow", !7, i64 8, !7, i64 16, !10, i64 24, !11, i64 28, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!13, !10, i64 96}
!13 = !{!"_ZTSN5NPat29CPatriciaE", !14, i64 0, !17, i64 8, !18, i64 16, !6, i64 24, !10, i64 96, !10, i64 100, !7, i64 104, !7, i64 112, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !11, i64 136, !10, i64 140, !7, i64 144, !19, i64 152}
!14 = !{!"_ZTS12IMatchFinder", !15, i64 0}
!15 = !{!"_ZTS15IInWindowStream", !16, i64 0}
!16 = !{!"_ZTS8IUnknown"}
!17 = !{!"_ZTS23IMatchFinderSetCallback", !16, i64 0}
!18 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!19 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !7, i64 0}
!20 = !{!13, !7, i64 104}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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