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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5NPat29CPatricia10RemoveNodeEj(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %9 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %8, i32 0, i32 7
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds %"struct.NPat2::CNode", ptr %10, i64 %12
  store ptr %13, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %30, %2
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp ult i32 %15, 4
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %33

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.NPat2::CNode", ptr %19, i32 0, i32 2
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds [4 x %"union.NPat2::CDescendant"], ptr %20, i64 0, i64 %22
  store ptr %23, ptr %7, align 8, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = call noundef zeroext i1 @_ZNK5NPat211CDescendant6IsNodeEv(ptr noundef nonnull align 4 dereferenceable(4) %24)
  br i1 %25, label %26, label %29

26:                                               ; preds = %18
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = load i32, ptr %27, align 4, !tbaa !21
  call void @_ZN5NPat29CPatricia10RemoveNodeEj(ptr noundef nonnull align 8 dereferenceable(160) %8, i32 noundef %28)
  br label %29

29:                                               ; preds = %26, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = add i32 %31, 1
  store i32 %32, ptr %6, align 4, !tbaa !9
  br label %14, !llvm.loop !22

33:                                               ; preds = %17
  %34 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %8, i32 0, i32 8
  %35 = load i32, ptr %34, align 8, !tbaa !24
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.NPat2::CNode", ptr %36, i32 0, i32 2
  store i32 %35, ptr %37, align 4, !tbaa !21
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %8, i32 0, i32 8
  store i32 %38, ptr %39, align 8, !tbaa !24
  %40 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %8, i32 0, i32 10
  %41 = load i32, ptr %40, align 8, !tbaa !25
  %42 = add i32 %41, -1
  store i32 %42, ptr %40, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  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 = !{!12, !6, i64 112}
!12 = !{!"_ZTSN5NPat29CPatriciaE", !13, i64 0, !16, i64 8, !17, i64 16, !18, i64 24, !10, i64 96, !10, i64 100, !6, i64 104, !6, i64 112, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !19, i64 136, !10, i64 140, !6, i64 144, !20, i64 152}
!13 = !{!"_ZTS12IMatchFinder", !14, i64 0}
!14 = !{!"_ZTS15IInWindowStream", !15, i64 0}
!15 = !{!"_ZTS8IUnknown"}
!16 = !{!"_ZTS23IMatchFinderSetCallback", !15, i64 0}
!17 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!18 = !{!"_ZTS11CLZInWindow", !6, i64 8, !6, i64 16, !10, i64 24, !19, 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}
!19 = !{!"bool", !7, i64 0}
!20 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !6, i64 0}
!21 = !{!7, !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!12, !10, i64 120}
!25 = !{!12, !10, i64 128}


; 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.NPat2::CNode" = type { i32, i32, %union.anon }
%union.anon = type { [4 x %"union.NPat2::CDescendant"] }
%"union.NPat2::CDescendant" = type { i32 }

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5NPat29CPatricia10RemoveNodeEj(ptr nocapture noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 112
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = zext i32 %1 to i64
  %6 = getelementptr inbounds %"struct.NPat2::CNode", ptr %4, i64 %5, i32 2
  %7 = tail call noundef zeroext i1 @_ZNK5NPat211CDescendant6IsNodeEv(ptr noundef nonnull align 4 dereferenceable(4) %6)
  br i1 %7, label %8, label %10

8:                                                ; preds = %2
  %9 = load i32, ptr %6, align 4, !tbaa !19
  tail call void @_ZN5NPat29CPatricia10RemoveNodeEj(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %9)
  br label %10

10:                                               ; preds = %8, %2
  %11 = getelementptr inbounds i8, ptr %6, i64 4
  %12 = tail call noundef zeroext i1 @_ZNK5NPat211CDescendant6IsNodeEv(ptr noundef nonnull align 4 dereferenceable(4) %11)
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  %14 = load i32, ptr %11, align 4, !tbaa !19
  tail call void @_ZN5NPat29CPatricia10RemoveNodeEj(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %14)
  br label %15

15:                                               ; preds = %13, %10
  %16 = getelementptr inbounds i8, ptr %6, i64 8
  %17 = tail call noundef zeroext i1 @_ZNK5NPat211CDescendant6IsNodeEv(ptr noundef nonnull align 4 dereferenceable(4) %16)
  br i1 %17, label %18, label %20

18:                                               ; preds = %15
  %19 = load i32, ptr %16, align 4, !tbaa !19
  tail call void @_ZN5NPat29CPatricia10RemoveNodeEj(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %19)
  br label %20

20:                                               ; preds = %18, %15
  %21 = getelementptr inbounds i8, ptr %6, i64 12
  %22 = tail call noundef zeroext i1 @_ZNK5NPat211CDescendant6IsNodeEv(ptr noundef nonnull align 4 dereferenceable(4) %21)
  br i1 %22, label %23, label %25

23:                                               ; preds = %20
  %24 = load i32, ptr %21, align 4, !tbaa !19
  tail call void @_ZN5NPat29CPatricia10RemoveNodeEj(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %24)
  br label %25

25:                                               ; preds = %23, %20
  %26 = getelementptr inbounds i8, ptr %0, i64 120
  %27 = load i32, ptr %26, align 8, !tbaa !20
  store i32 %27, ptr %6, align 4, !tbaa !19
  store i32 %1, ptr %26, align 8, !tbaa !20
  %28 = getelementptr inbounds i8, ptr %0, i64 128
  %29 = load i32, ptr %28, align 8, !tbaa !21
  %30 = add i32 %29, -1
  store i32 %30, ptr %28, align 8, !tbaa !21
  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, !16, i64 112}
!6 = !{!"_ZTSN5NPat29CPatriciaE", !7, i64 0, !10, i64 8, !11, i64 16, !15, i64 24, !12, i64 96, !12, i64 100, !16, i64 104, !16, i64 112, !12, i64 120, !12, i64 124, !12, i64 128, !12, i64 132, !17, i64 136, !12, i64 140, !16, i64 144, !18, i64 152}
!7 = !{!"_ZTS12IMatchFinder", !8, i64 0}
!8 = !{!"_ZTS15IInWindowStream", !9, i64 0}
!9 = !{!"_ZTS8IUnknown"}
!10 = !{!"_ZTS23IMatchFinderSetCallback", !9, i64 0}
!11 = !{!"_ZTS13CMyUnknownImp", !12, i64 0}
!12 = !{!"int", !13, i64 0}
!13 = !{!"omnipotent char", !14, i64 0}
!14 = !{!"Simple C++ TBAA"}
!15 = !{!"_ZTS11CLZInWindow", !16, i64 8, !16, i64 16, !12, i64 24, !17, i64 28, !16, i64 32, !16, i64 40, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68}
!16 = !{!"any pointer", !13, i64 0}
!17 = !{!"bool", !13, i64 0}
!18 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !16, i64 0}
!19 = !{!13, !13, i64 0}
!20 = !{!6, !12, i64 120}
!21 = !{!6, !12, i64 128}


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