; 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.NPat2H::CPatricia" = type { %struct.IMatchFinder, %struct.IMatchFinderSetCallback, %class.CMyUnknownImp, %class.CLZInWindow, i32, i32, ptr, 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.NPat2H::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 @_ZN6NPat2H11CDescendant9MakeEmptyEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6NPat2H9CPatricia15TestRemoveNodesEv(ptr noundef nonnull align 8 dereferenceable(168) %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 i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %12 = getelementptr inbounds i8, ptr %11, i64 24
  %13 = getelementptr inbounds %class.CLZInWindow, ptr %12, i32 0, i32 8
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = add i32 -2147483648, %14
  %16 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %11, i32 0, i32 4
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = sub i32 %15, %17
  %19 = add i32 %18, 3
  store i32 %19, ptr %3, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %20 = getelementptr inbounds i8, ptr %11, i64 24
  %21 = getelementptr inbounds %class.CLZInWindow, ptr %20, i32 0, i32 8
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = add i32 2, %22
  %24 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %11, i32 0, i32 4
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = sub i32 %23, %25
  %27 = add i32 %26, 3
  store i32 %27, ptr %4, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !21
  br label %28

28:                                               ; preds = %97, %1
  %29 = load i32, ptr %5, align 4, !tbaa !21
  %30 = icmp ult i32 %29, 65536
  br i1 %30, label %32, label %31

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

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %33 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %11, i32 0, i32 7
  %34 = load ptr, ptr %33, align 8, !tbaa !22
  %35 = load i32, ptr %5, align 4, !tbaa !21
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %34, i64 %36
  store ptr %37, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load i32, ptr %38, align 4, !tbaa !23
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %81

41:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %42 = load i32, ptr %5, align 4, !tbaa !21
  %43 = shl i32 %42, 8
  store i32 %43, ptr %8, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !21
  br label %44

44:                                               ; preds = %77, %41
  %45 = load i32, ptr %9, align 4, !tbaa !21
  %46 = icmp ult i32 %45, 256
  br i1 %46, label %48, label %47

47:                                               ; preds = %44
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %80

48:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %49 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %11, i32 0, i32 6
  %50 = load ptr, ptr %49, align 8, !tbaa !24
  %51 = load i32, ptr %8, align 4, !tbaa !21
  %52 = load i32, ptr %9, align 4, !tbaa !21
  %53 = add i32 %51, %52
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %50, i64 %54
  store ptr %55, ptr %10, align 8, !tbaa !5
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = call noundef zeroext i1 @_ZNK6NPat2H11CDescendant7IsEmptyEv(ptr noundef nonnull align 4 dereferenceable(4) %56)
  br i1 %57, label %58, label %59

58:                                               ; preds = %48
  store i32 7, ptr %6, align 4
  br label %74

59:                                               ; preds = %48
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = call noundef zeroext i1 @_ZNK6NPat2H11CDescendant7IsMatchEv(ptr noundef nonnull align 4 dereferenceable(4) %60)
  br i1 %61, label %62, label %70

62:                                               ; preds = %59
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = load i32, ptr %63, align 4, !tbaa !23
  %65 = load i32, ptr %3, align 4, !tbaa !21
  %66 = icmp ult i32 %64, %65
  br i1 %66, label %67, label %69

67:                                               ; preds = %62
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZN6NPat2H11CDescendant9MakeEmptyEv(ptr noundef nonnull align 4 dereferenceable(4) %68)
  br label %69

69:                                               ; preds = %67, %62
  br label %73

70:                                               ; preds = %59
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = load i32, ptr %3, align 4, !tbaa !21
  call void @_ZN6NPat2H9CPatricia20TestRemoveDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(168) %11, ptr noundef nonnull align 4 dereferenceable(4) %71, i32 noundef %72)
  br label %73

73:                                               ; preds = %70, %69
  store i32 0, ptr %6, align 4
  br label %74

74:                                               ; preds = %73, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %75 = load i32, ptr %6, align 4
  switch i32 %75, label %101 [
    i32 0, label %76
    i32 7, label %77
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76, %74
  %78 = load i32, ptr %9, align 4, !tbaa !21
  %79 = add i32 %78, 1
  store i32 %79, ptr %9, align 4, !tbaa !21
  br label %44, !llvm.loop !25

80:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %81

81:                                               ; preds = %80, %32
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load i32, ptr %82, align 4, !tbaa !23
  %84 = icmp ult i32 %83, 2
  br i1 %84, label %85, label %86

85:                                               ; preds = %81
  store i32 4, ptr %6, align 4
  br label %94

86:                                               ; preds = %81
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = load i32, ptr %87, align 4, !tbaa !23
  %89 = load i32, ptr %4, align 4, !tbaa !21
  %90 = icmp ult i32 %88, %89
  br i1 %90, label %91, label %93

91:                                               ; preds = %86
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 1, ptr %92, align 4, !tbaa !23
  br label %93

93:                                               ; preds = %91, %86
  store i32 0, ptr %6, align 4
  br label %94

94:                                               ; preds = %93, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %95 = load i32, ptr %6, align 4
  switch i32 %95, label %101 [
    i32 0, label %96
    i32 4, label %97
  ]

96:                                               ; preds = %94
  br label %97

97:                                               ; preds = %96, %94
  %98 = load i32, ptr %5, align 4, !tbaa !21
  %99 = add i32 %98, 1
  store i32 %99, ptr %5, align 4, !tbaa !21
  br label %28, !llvm.loop !27

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

101:                                              ; preds = %94, %74
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6NPat2H9CPatricia20TestRemoveDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(168), 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 = !{!"_ZTSN6NPat2H9CPatriciaE", !15, i64 0, !18, i64 8, !19, i64 16, !10, i64 24, !11, i64 96, !11, i64 100, !6, i64 104, !6, i64 112, !6, i64 120, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !12, i64 144, !11, i64 148, !6, i64 152, !20, i64 160}
!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 112}
!23 = !{!7, !7, i64 0}
!24 = !{!14, !6, i64 104}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}


; 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.NPat2H::CDescendant" = type { i32 }

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6NPat2H9CPatricia15TestRemoveNodesEv(ptr noundef nonnull align 8 dereferenceable(168) %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, 3
  %9 = add i32 %3, 5
  %10 = sub i32 %9, %6
  %11 = getelementptr inbounds i8, ptr %0, i64 112
  %12 = getelementptr inbounds i8, ptr %0, i64 104
  br label %14

13:                                               ; preds = %.loopexit.thread
  ret void

14:                                               ; preds = %1, %.loopexit.thread
  %indvars.iv25 = phi i64 [ 0, %1 ], [ %indvars.iv.next26, %.loopexit.thread ]
  %15 = load ptr, ptr %11, align 8, !tbaa !20
  %16 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %15, i64 %indvars.iv25
  %17 = load i32, ptr %16, align 4, !tbaa !21
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %.loopexit.thread, label %18

18:                                               ; preds = %14
  %.idx = shl nsw i64 %indvars.iv25, 10
  br label %19

19:                                               ; preds = %18, %31
  %indvars.iv = phi i64 [ 0, %18 ], [ %indvars.iv.next, %31 ]
  %20 = load ptr, ptr %12, align 8, !tbaa !22
  %21 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %20, i64 %indvars.iv
  %22 = getelementptr inbounds i8, ptr %21, i64 %.idx
  %23 = tail call noundef zeroext i1 @_ZNK6NPat2H11CDescendant7IsEmptyEv(ptr noundef nonnull align 4 dereferenceable(4) %22)
  br i1 %23, label %31, label %24

24:                                               ; preds = %19
  %25 = tail call noundef zeroext i1 @_ZNK6NPat2H11CDescendant7IsMatchEv(ptr noundef nonnull align 4 dereferenceable(4) %22)
  br i1 %25, label %26, label %30

26:                                               ; preds = %24
  %27 = load i32, ptr %22, align 4, !tbaa !21
  %28 = icmp ult i32 %27, %8
  br i1 %28, label %29, label %31

29:                                               ; preds = %26
  tail call void @_ZN6NPat2H11CDescendant9MakeEmptyEv(ptr noundef nonnull align 4 dereferenceable(4) %22)
  br label %31

30:                                               ; preds = %24
  tail call void @_ZN6NPat2H9CPatricia20TestRemoveDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(168) %0, ptr noundef nonnull align 4 dereferenceable(4) %22, i32 noundef %8)
  br label %31

31:                                               ; preds = %30, %29, %26, %19
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 256
  br i1 %exitcond.not, label %.loopexit, label %19, !llvm.loop !23

.loopexit:                                        ; preds = %31
  %.pre = load i32, ptr %16, align 4, !tbaa !21
  %32 = icmp ugt i32 %.pre, 1
  %33 = icmp ult i32 %.pre, %10
  %or.cond = select i1 %32, i1 %33, i1 false
  br i1 %or.cond, label %34, label %.loopexit.thread

34:                                               ; preds = %.loopexit
  store i32 1, ptr %16, align 4, !tbaa !21
  br label %.loopexit.thread

.loopexit.thread:                                 ; preds = %14, %34, %.loopexit
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %exitcond28.not = icmp eq i64 %indvars.iv.next26, 65536
  br i1 %exitcond28.not, label %13, label %14, !llvm.loop !25
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6NPat2H9CPatricia20TestRemoveDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(168), 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 = !{!"_ZTSN6NPat2H9CPatriciaE", !14, i64 0, !17, i64 8, !18, i64 16, !6, i64 24, !10, i64 96, !10, i64 100, !7, i64 104, !7, i64 112, !7, i64 120, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !11, i64 144, !10, i64 148, !7, i64 152, !19, i64 160}
!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 112}
!21 = !{!8, !8, i64 0}
!22 = !{!13, !7, i64 104}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


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