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

; 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 uwtable
define dso_local void @_ZN5NPat29CPatricia15ChangeLastMatchEj(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %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 i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %13 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %14 = getelementptr inbounds i8, ptr %13, i64 24
  %15 = getelementptr inbounds %class.CLZInWindow, ptr %14, i32 0, i32 8
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = add i32 %16, 2
  %18 = sub i32 %17, 1
  store i32 %18, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %19 = getelementptr inbounds i8, ptr %13, i64 24
  %20 = getelementptr inbounds %class.CLZInWindow, ptr %19, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  store ptr %24, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  store i8 0, ptr %9, align 1, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %25 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %13, i32 0, i32 7
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %13, i32 0, i32 6
  %28 = load ptr, ptr %27, align 8, !tbaa !24
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds %"union.NPat2::CDescendant", ptr %28, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !15
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds %"struct.NPat2::CNode", ptr %26, i64 %33
  store ptr %34, ptr %10, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %110, %2
  br label %36

36:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.NPat2::CNode", ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !25
  store i32 %39, ptr %11, align 4, !tbaa !9
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = icmp ugt i32 %40, 0
  br i1 %41, label %42, label %69

42:                                               ; preds = %36
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = icmp ult i32 %43, %44
  br i1 %45, label %46, label %60

46:                                               ; preds = %42
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = sub i32 %48, %47
  store i32 %49, ptr %11, align 4, !tbaa !9
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = udiv i32 %50, 8
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = zext i32 %51 to i64
  %54 = getelementptr inbounds i8, ptr %52, i64 %53
  store ptr %54, ptr %7, align 8, !tbaa !5
  %55 = load i32, ptr %11, align 4, !tbaa !9
  %56 = urem i32 %55, 8
  store i32 %56, ptr %11, align 4, !tbaa !9
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i32 1
  store ptr %58, ptr %7, align 8, !tbaa !5
  %59 = load i8, ptr %57, align 1, !tbaa !15
  store i8 %59, ptr %9, align 1, !tbaa !15
  store i32 8, ptr %8, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %46, %42
  %61 = load i32, ptr %11, align 4, !tbaa !9
  %62 = load i8, ptr %9, align 1, !tbaa !15
  %63 = zext i8 %62 to i32
  %64 = ashr i32 %63, %61
  %65 = trunc i32 %64 to i8
  store i8 %65, ptr %9, align 1, !tbaa !15
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = sub i32 %67, %66
  store i32 %68, ptr %8, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %60, %36
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = icmp eq i32 %70, 0
  br i1 %71, label %72, label %76

72:                                               ; preds = %69
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds i8, ptr %73, i32 1
  store ptr %74, ptr %7, align 8, !tbaa !5
  %75 = load i8, ptr %73, align 1, !tbaa !15
  store i8 %75, ptr %9, align 1, !tbaa !15
  store i32 8, ptr %8, align 4, !tbaa !9
  br label %76

76:                                               ; preds = %72, %69
  %77 = load i8, ptr %9, align 1, !tbaa !15
  %78 = zext i8 %77 to i32
  %79 = and i32 %78, 3
  store i32 %79, ptr %6, align 4, !tbaa !9
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = getelementptr inbounds %"struct.NPat2::CNode", ptr %81, i32 0, i32 0
  store i32 %80, ptr %82, align 4, !tbaa !27
  %83 = load i32, ptr %8, align 4, !tbaa !9
  %84 = sub i32 %83, 2
  store i32 %84, ptr %8, align 4, !tbaa !9
  %85 = load i8, ptr %9, align 1, !tbaa !15
  %86 = zext i8 %85 to i32
  %87 = ashr i32 %86, 2
  %88 = trunc i32 %87 to i8
  store i8 %88, ptr %9, align 1, !tbaa !15
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  %90 = getelementptr inbounds %"struct.NPat2::CNode", ptr %89, i32 0, i32 2
  %91 = load i32, ptr %6, align 4, !tbaa !9
  %92 = zext i32 %91 to i64
  %93 = getelementptr inbounds [4 x %"union.NPat2::CDescendant"], ptr %90, i64 0, i64 %92
  %94 = call noundef zeroext i1 @_ZNK5NPat211CDescendant6IsNodeEv(ptr noundef nonnull align 4 dereferenceable(4) %93)
  br i1 %94, label %95, label %106

95:                                               ; preds = %76
  %96 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %13, i32 0, i32 7
  %97 = load ptr, ptr %96, align 8, !tbaa !16
  %98 = load ptr, ptr %10, align 8, !tbaa !5
  %99 = getelementptr inbounds %"struct.NPat2::CNode", ptr %98, i32 0, i32 2
  %100 = load i32, ptr %6, align 4, !tbaa !9
  %101 = zext i32 %100 to i64
  %102 = getelementptr inbounds [4 x %"union.NPat2::CDescendant"], ptr %99, i64 0, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !15
  %104 = zext i32 %103 to i64
  %105 = getelementptr inbounds %"struct.NPat2::CNode", ptr %97, i64 %104
  store ptr %105, ptr %10, align 8, !tbaa !5
  br label %107

106:                                              ; preds = %76
  store i32 3, ptr %12, align 4
  br label %108

107:                                              ; preds = %95
  store i32 0, ptr %12, align 4
  br label %108

108:                                              ; preds = %107, %106
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %109 = load i32, ptr %12, align 4
  switch i32 %109, label %119 [
    i32 0, label %110
    i32 3, label %111
  ]

110:                                              ; preds = %108
  br label %35, !llvm.loop !28

111:                                              ; preds = %108
  %112 = load i32, ptr %5, align 4, !tbaa !9
  %113 = add i32 %112, -2147483648
  %114 = load ptr, ptr %10, align 8, !tbaa !5
  %115 = getelementptr inbounds %"struct.NPat2::CNode", ptr %114, i32 0, i32 2
  %116 = load i32, ptr %6, align 4, !tbaa !9
  %117 = zext i32 %116 to i64
  %118 = getelementptr inbounds [4 x %"union.NPat2::CDescendant"], ptr %115, i64 0, i64 %117
  store i32 %113, ptr %118, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void

119:                                              ; preds = %108
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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, !10, i64 52}
!12 = !{!"_ZTS11CLZInWindow", !6, i64 8, !6, i64 16, !10, i64 24, !13, 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}
!13 = !{!"bool", !7, i64 0}
!14 = !{!12, !6, i64 40}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !6, i64 112}
!17 = !{!"_ZTSN5NPat29CPatriciaE", !18, i64 0, !21, i64 8, !22, i64 16, !12, 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, !13, i64 136, !10, i64 140, !6, i64 144, !23, i64 152}
!18 = !{!"_ZTS12IMatchFinder", !19, i64 0}
!19 = !{!"_ZTS15IInWindowStream", !20, i64 0}
!20 = !{!"_ZTS8IUnknown"}
!21 = !{!"_ZTS23IMatchFinderSetCallback", !20, i64 0}
!22 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!23 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !6, i64 0}
!24 = !{!17, !6, i64 104}
!25 = !{!26, !10, i64 4}
!26 = !{!"_ZTSN5NPat25CNodeE", !10, i64 0, !10, i64 4, !7, i64 8}
!27 = !{!26, !10, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"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 }
%"struct.NPat2::CNode" = type { i32, i32, %union.anon }
%union.anon = type { [4 x %"union.NPat2::CDescendant"] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5NPat29CPatricia15ChangeLastMatchEj(ptr nocapture noundef nonnull readonly align 8 dereferenceable(160) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 76
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = add i32 %4, 1
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = zext i32 %5 to i64
  %9 = getelementptr inbounds i8, ptr %7, i64 %8
  %10 = getelementptr inbounds i8, ptr %0, i64 112
  %11 = getelementptr inbounds i8, ptr %0, i64 104
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = zext i32 %1 to i64
  %14 = getelementptr inbounds %"union.NPat2::CDescendant", ptr %12, i64 %13
  br label %15

15:                                               ; preds = %47, %2
  %.sink50 = phi ptr [ %45, %47 ], [ %14, %2 ]
  %.039 = phi ptr [ %.342, %47 ], [ %9, %2 ]
  %.035 = phi i32 [ %49, %47 ], [ 0, %2 ]
  %.033 = phi i8 [ %48, %47 ], [ 0, %2 ]
  %.sink = load ptr, ptr %10, align 8, !tbaa !21
  %16 = load i32, ptr %.sink50, align 4, !tbaa !22
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds %"struct.NPat2::CNode", ptr %.sink, i64 %17
  %19 = getelementptr inbounds i8, ptr %18, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !23
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %36, label %21

21:                                               ; preds = %15
  %22 = icmp ult i32 %.035, %20
  br i1 %22, label %23, label %31

23:                                               ; preds = %21
  %24 = sub i32 %20, %.035
  %25 = lshr i32 %24, 3
  %26 = zext nneg i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %.039, i64 %26
  %28 = and i32 %24, 7
  %29 = getelementptr inbounds i8, ptr %27, i64 1
  %30 = load i8, ptr %27, align 1, !tbaa !22
  br label %31

31:                                               ; preds = %23, %21
  %.140 = phi ptr [ %29, %23 ], [ %.039, %21 ]
  %.136 = phi i32 [ 8, %23 ], [ %.035, %21 ]
  %.134 = phi i8 [ %30, %23 ], [ %.033, %21 ]
  %.031 = phi i32 [ %28, %23 ], [ %20, %21 ]
  %32 = zext i8 %.134 to i32
  %33 = lshr i32 %32, %.031
  %34 = trunc nuw i32 %33 to i8
  %35 = sub i32 %.136, %.031
  br label %36

36:                                               ; preds = %31, %15
  %.241 = phi ptr [ %.140, %31 ], [ %.039, %15 ]
  %.237 = phi i32 [ %35, %31 ], [ %.035, %15 ]
  %.2 = phi i8 [ %34, %31 ], [ %.033, %15 ]
  %37 = icmp eq i32 %.237, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %36
  %39 = getelementptr inbounds i8, ptr %.241, i64 1
  %40 = load i8, ptr %.241, align 1, !tbaa !22
  br label %41

41:                                               ; preds = %38, %36
  %.342 = phi ptr [ %39, %38 ], [ %.241, %36 ]
  %.338 = phi i32 [ 8, %38 ], [ %.237, %36 ]
  %.3 = phi i8 [ %40, %38 ], [ %.2, %36 ]
  %42 = and i8 %.3, 3
  store i32 %5, ptr %18, align 4, !tbaa !25
  %43 = getelementptr inbounds i8, ptr %18, i64 8
  %44 = zext nneg i8 %42 to i64
  %45 = getelementptr inbounds [4 x %"union.NPat2::CDescendant"], ptr %43, i64 0, i64 %44
  %46 = tail call noundef zeroext i1 @_ZNK5NPat211CDescendant6IsNodeEv(ptr noundef nonnull align 4 dereferenceable(4) %45)
  br i1 %46, label %47, label %50

47:                                               ; preds = %41
  %48 = lshr i8 %.3, 2
  %49 = add i32 %.338, -2
  br label %15

50:                                               ; preds = %41
  %51 = add i32 %4, -2147483647
  store i32 %51, ptr %45, align 4, !tbaa !22
  ret void
}

; 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

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, !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 = !{!6, !7, i64 40}
!13 = !{!14, !7, i64 104}
!14 = !{!"_ZTSN5NPat29CPatriciaE", !15, i64 0, !18, i64 8, !19, 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, !20, i64 152}
!15 = !{!"_ZTS12IMatchFinder", !16, i64 0}
!16 = !{!"_ZTS15IInWindowStream", !17, i64 0}
!17 = !{!"_ZTS8IUnknown"}
!18 = !{!"_ZTS23IMatchFinderSetCallback", !17, i64 0}
!19 = !{!"_ZTS13CMyUnknownImp", !10, i64 0}
!20 = !{!"_ZTS9CMyComPtrI20IMatchFinderCallbackE", !7, i64 0}
!21 = !{!14, !7, i64 112}
!22 = !{!8, !8, i64 0}
!23 = !{!24, !10, i64 4}
!24 = !{!"_ZTSN5NPat25CNodeE", !10, i64 0, !10, i64 4, !8, i64 8}
!25 = !{!24, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass