; 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.NPat2R::CPatricia" = type { %struct.IMatchFinder, %struct.IMatchFinderSetCallback, %class.CMyUnknownImp, %class.CLZInWindow, i32, i32, ptr, ptr, i32, i32, i8, 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.CLZInWindow = type { ptr, ptr, ptr, i32, i8, ptr, ptr, i32, i32, i32, i32, i32, i32 }
%class.CMyComPtr = type { ptr }
%"struct.NPat2R::CNode" = type { i32, i32, %union.anon.3 }
%union.anon.3 = type { [4 x %"union.NPat2R::CDescendant"] }
%"union.NPat2R::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 noundef zeroext i1 @_ZNK6NPat2R11CDescendant7IsMatchEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6NPat2R9CPatricia19NormalizeDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call noundef zeroext i1 @_ZNK6NPat2R11CDescendant7IsEmptyEv(ptr noundef nonnull align 4 dereferenceable(4) %10)
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  br label %51

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call noundef zeroext i1 @_ZNK6NPat2R11CDescendant7IsMatchEv(ptr noundef nonnull align 4 dereferenceable(4) %14)
  br i1 %15, label %16, label %22

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = sub i32 %18, %19
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %20, ptr %21, align 4, !tbaa !11
  br label %51

22:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %23 = getelementptr inbounds %"class.NPat2R::CPatricia", ptr %9, i32 0, i32 7
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds %"struct.NPat2R::CNode", ptr %24, i64 %27
  store ptr %28, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.NPat2R::CNode", ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !22
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = sub i32 %31, %32
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.NPat2R::CNode", ptr %34, i32 0, i32 0
  store i32 %33, ptr %35, align 4, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %47, %22
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = icmp ult i32 %37, 4
  br i1 %38, label %40, label %39

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

40:                                               ; preds = %36
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.NPat2R::CNode", ptr %41, i32 0, i32 2
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds [4 x %"union.NPat2R::CDescendant"], ptr %42, i64 0, i64 %44
  %46 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN6NPat2R9CPatricia19NormalizeDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(152) %9, ptr noundef nonnull align 4 dereferenceable(4) %45, i32 noundef %46)
  br label %47

47:                                               ; preds = %40
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = add i32 %48, 1
  store i32 %49, ptr %8, align 4, !tbaa !9
  br label %36, !llvm.loop !24

50:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %51

51:                                               ; preds = %50, %16, %12
  ret void
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 112}
!13 = !{!"_ZTSN6NPat2R9CPatriciaE", !14, i64 0, !17, i64 8, !18, i64 16, !19, i64 24, !10, i64 96, !10, i64 100, !6, i64 104, !6, i64 112, !10, i64 120, !10, i64 124, !20, i64 128, !20, i64 129, !10, i64 132, !6, i64 136, !21, i64 144}
!14 = !{!"_ZTS12IMatchFinder", !15, i64 0}
!15 = !{!"_ZTS15IInWindowStream", !16, i64 0}
!16 = !{!"_ZTS8IUnknown"}
!17 = !{!"_ZTS23IMatchFinderSetCallback", !16, i64 0}
!18 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!19 = !{!"_ZTS11CLZInWindow", !6, i64 8, !6, i64 16, !10, i64 24, !20, i64 28, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68}
!20 = !{!"bool", !7, i64 0}
!21 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !6, i64 0}
!22 = !{!23, !10, i64 0}
!23 = !{!"_ZTSN6NPat2R5CNodeE", !10, i64 0, !10, i64 4, !7, i64 8}
!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"

%"struct.NPat2R::CNode" = type { i32, i32, %union.anon.3 }
%union.anon.3 = type { [4 x %"union.NPat2R::CDescendant"] }
%"union.NPat2R::CDescendant" = type { i32 }

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6NPat2R9CPatricia19NormalizeDescendantERNS_11CDescendantEj(ptr nocapture noundef nonnull readonly align 8 dereferenceable(152) %0, ptr noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %.loopexit.loopexit, %3
  %.tr16 = phi ptr [ %1, %3 ], [ %20, %.loopexit.loopexit ]
  %4 = tail call noundef zeroext i1 @_ZNK6NPat2R11CDescendant7IsEmptyEv(ptr noundef nonnull align 4 dereferenceable(4) %.tr16)
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %tailrecurse
  %6 = tail call noundef zeroext i1 @_ZNK6NPat2R11CDescendant7IsMatchEv(ptr noundef nonnull align 4 dereferenceable(4) %.tr16)
  br i1 %6, label %7, label %.loopexit.loopexit

7:                                                ; preds = %5
  %8 = load i32, ptr %.tr16, align 4, !tbaa !5
  %9 = sub i32 %8, %2
  store i32 %9, ptr %.tr16, align 4, !tbaa !5
  br label %.loopexit

.loopexit.loopexit:                               ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 112
  %11 = load ptr, ptr %10, align 8, !tbaa !8
  %12 = load i32, ptr %.tr16, align 4, !tbaa !5
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds %"struct.NPat2R::CNode", ptr %11, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !20
  %16 = sub i32 %15, %2
  store i32 %16, ptr %14, align 4, !tbaa !20
  %17 = getelementptr inbounds i8, ptr %14, i64 8
  tail call void @_ZN6NPat2R9CPatricia19NormalizeDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef nonnull align 4 dereferenceable(4) %17, i32 noundef %2)
  %18 = getelementptr inbounds i8, ptr %14, i64 12
  tail call void @_ZN6NPat2R9CPatricia19NormalizeDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef nonnull align 4 dereferenceable(4) %18, i32 noundef %2)
  %19 = getelementptr inbounds i8, ptr %14, i64 16
  tail call void @_ZN6NPat2R9CPatricia19NormalizeDescendantERNS_11CDescendantEj(ptr noundef nonnull align 8 dereferenceable(152) %0, ptr noundef nonnull align 4 dereferenceable(4) %19, i32 noundef %2)
  %20 = getelementptr inbounds i8, ptr %14, i64 20
  br label %tailrecurse

.loopexit:                                        ; preds = %tailrecurse, %7
  ret void
}

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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !17, i64 112}
!9 = !{!"_ZTSN6NPat2R9CPatriciaE", !10, i64 0, !13, i64 8, !14, i64 16, !16, i64 24, !15, i64 96, !15, i64 100, !17, i64 104, !17, i64 112, !15, i64 120, !15, i64 124, !18, i64 128, !18, i64 129, !15, i64 132, !17, i64 136, !19, i64 144}
!10 = !{!"_ZTS12IMatchFinder", !11, i64 0}
!11 = !{!"_ZTS15IInWindowStream", !12, i64 0}
!12 = !{!"_ZTS8IUnknown"}
!13 = !{!"_ZTS23IMatchFinderSetCallback", !12, i64 0}
!14 = !{!"_ZTS13CMyUnknownImp", !15, i64 0}
!15 = !{!"int", !6, i64 0}
!16 = !{!"_ZTS11CLZInWindow", !17, i64 8, !17, i64 16, !15, i64 24, !18, i64 28, !17, i64 32, !17, i64 40, !15, i64 48, !15, i64 52, !15, i64 56, !15, i64 60, !15, i64 64, !15, i64 68}
!17 = !{!"any pointer", !6, i64 0}
!18 = !{!"bool", !6, i64 0}
!19 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !17, i64 0}
!20 = !{!21, !15, i64 0}
!21 = !{!"_ZTSN6NPat2R5CNodeE", !15, i64 0, !15, i64 4, !6, i64 8}


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