; 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 @_ZN5NPat211CDescendant9MakeEmptyEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5NPat211CDescendant7IsMatchEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5NPat211CDescendant7IsEmptyEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5NPat29CPatricia15TestRemoveNodesEv(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
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %8 = getelementptr inbounds i8, ptr %7, i64 24
  %9 = getelementptr inbounds %class.CLZInWindow, ptr %8, i32 0, i32 8
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = add i32 -2147483648, %10
  %12 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %7, i32 0, i32 4
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = sub i32 %11, %13
  %15 = add i32 %14, 2
  store i32 %15, ptr %3, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !21
  br label %16

16:                                               ; preds = %47, %1
  %17 = load i32, ptr %4, align 4, !tbaa !21
  %18 = icmp ult i32 %17, 65536
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %50

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %21 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %7, i32 0, i32 6
  %22 = load ptr, ptr %21, align 8, !tbaa !22
  %23 = load i32, ptr %4, align 4, !tbaa !21
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds %"union.NPat2::CDescendant", ptr %22, i64 %24
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = call noundef zeroext i1 @_ZNK5NPat211CDescendant7IsEmptyEv(ptr noundef nonnull align 4 dereferenceable(4) %26)
  br i1 %27, label %28, label %29

28:                                               ; preds = %20
  store i32 4, ptr %5, align 4
  br label %44

29:                                               ; preds = %20
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = call noundef zeroext i1 @_ZNK5NPat211CDescendant7IsMatchEv(ptr noundef nonnull align 4 dereferenceable(4) %30)
  br i1 %31, label %32, label %40

32:                                               ; preds = %29
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i32, ptr %33, align 4, !tbaa !23
  %35 = load i32, ptr %3, align 4, !tbaa !21
  %36 = icmp ult i32 %34, %35
  br i1 %36, label %37, label %39

37:                                               ; preds = %32
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN5NPat211CDescendant9MakeEmptyEv(ptr noundef nonnull align 4 dereferenceable(4) %38)
  br label %39

39:                                               ; preds = %37, %32
  br label %43

40:                                               ; preds = %29
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %3, align 4, !tbaa !21
  call void @_ZN5NPat29CPatricia20TestRemoveDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(160) %7, ptr noundef nonnull align 4 dereferenceable(4) %41, i32 noundef %42)
  br label %43

43:                                               ; preds = %40, %39
  store i32 0, ptr %5, align 4
  br label %44

44:                                               ; preds = %43, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %45 = load i32, ptr %5, align 4
  switch i32 %45, label %51 [
    i32 0, label %46
    i32 4, label %47
  ]

46:                                               ; preds = %44
  br label %47

47:                                               ; preds = %46, %44
  %48 = load i32, ptr %4, align 4, !tbaa !21
  %49 = add i32 %48, 1
  store i32 %49, ptr %4, align 4, !tbaa !21
  br label %16, !llvm.loop !24

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

51:                                               ; preds = %44
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5NPat29CPatricia20TestRemoveDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(160), ptr noundef nonnull align 4 dereferenceable(4), 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 = !{!7, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"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 @_ZN5NPat211CDescendant9MakeEmptyEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

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

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

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

10:                                               ; preds = %22
  ret void

11:                                               ; preds = %1, %22
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %22 ]
  %12 = load ptr, ptr %9, align 8, !tbaa !20
  %13 = getelementptr inbounds %"union.NPat2::CDescendant", ptr %12, i64 %indvars.iv
  %14 = tail call noundef zeroext i1 @_ZNK5NPat211CDescendant7IsEmptyEv(ptr noundef nonnull align 4 dereferenceable(4) %13)
  br i1 %14, label %22, label %15

15:                                               ; preds = %11
  %16 = tail call noundef zeroext i1 @_ZNK5NPat211CDescendant7IsMatchEv(ptr noundef nonnull align 4 dereferenceable(4) %13)
  br i1 %16, label %17, label %21

17:                                               ; preds = %15
  %18 = load i32, ptr %13, align 4, !tbaa !21
  %19 = icmp ult i32 %18, %8
  br i1 %19, label %20, label %22

20:                                               ; preds = %17
  tail call void @_ZN5NPat211CDescendant9MakeEmptyEv(ptr noundef nonnull align 4 dereferenceable(4) %13)
  br label %22

21:                                               ; preds = %15
  tail call void @_ZN5NPat29CPatricia20TestRemoveDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(160) %0, ptr noundef nonnull align 4 dereferenceable(4) %13, i32 noundef %8)
  br label %22

22:                                               ; preds = %21, %20, %17, %11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 65536
  br i1 %exitcond.not, label %10, label %11, !llvm.loop !22
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5NPat29CPatricia20TestRemoveDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(160), ptr noundef nonnull align 4 dereferenceable(4), 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 = !{!8, !8, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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