; 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 @_ZN11CLZInWindow13ReduceOffsetsEi(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef) #1 align 2

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

36:                                               ; preds = %92, %1
  %37 = load i32, ptr %6, align 4, !tbaa !21
  %38 = icmp ult i32 %37, 65536
  br i1 %38, label %40, label %39

39:                                               ; preds = %36
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %95

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %41 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %11, i32 0, i32 7
  %42 = load ptr, ptr %41, align 8, !tbaa !22
  %43 = load i32, ptr %6, align 4, !tbaa !21
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %42, i64 %44
  store ptr %45, ptr %8, align 8, !tbaa !5
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i32, ptr %46, align 4, !tbaa !23
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %70

49:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %50 = load i32, ptr %6, align 4, !tbaa !21
  %51 = shl i32 %50, 8
  store i32 %51, ptr %9, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !21
  br label %52

52:                                               ; preds = %66, %49
  %53 = load i32, ptr %10, align 4, !tbaa !21
  %54 = icmp ult i32 %53, 256
  br i1 %54, label %56, label %55

55:                                               ; preds = %52
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %69

56:                                               ; preds = %52
  %57 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %11, i32 0, i32 6
  %58 = load ptr, ptr %57, align 8, !tbaa !24
  %59 = load i32, ptr %9, align 4, !tbaa !21
  %60 = load i32, ptr %10, align 4, !tbaa !21
  %61 = add i32 %59, %60
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %58, i64 %62
  %64 = load i32, ptr %4, align 4, !tbaa !21
  %65 = load i32, ptr %3, align 4, !tbaa !21
  call void @_ZN6NPat2H9CPatricia32TestRemoveAndNormalizeDescendantERNS_11CDescendantEjj(ptr noundef nonnull align 8 dereferenceable(168) %11, ptr noundef nonnull align 4 dereferenceable(4) %63, i32 noundef %64, i32 noundef %65)
  br label %66

66:                                               ; preds = %56
  %67 = load i32, ptr %10, align 4, !tbaa !21
  %68 = add i32 %67, 1
  store i32 %68, ptr %10, align 4, !tbaa !21
  br label %52, !llvm.loop !25

69:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %70

70:                                               ; preds = %69, %40
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load i32, ptr %71, align 4, !tbaa !23
  %73 = icmp ult i32 %72, 2
  br i1 %73, label %74, label %75

74:                                               ; preds = %70
  store i32 4, ptr %7, align 4
  br label %89

75:                                               ; preds = %70
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load i32, ptr %76, align 4, !tbaa !23
  %78 = load i32, ptr %5, align 4, !tbaa !21
  %79 = icmp ult i32 %77, %78
  br i1 %79, label %80, label %82

80:                                               ; preds = %75
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 1, ptr %81, align 4, !tbaa !23
  br label %88

82:                                               ; preds = %75
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = load i32, ptr %83, align 4, !tbaa !23
  %85 = load i32, ptr %3, align 4, !tbaa !21
  %86 = sub i32 %84, %85
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %86, ptr %87, align 4, !tbaa !23
  br label %88

88:                                               ; preds = %82, %80
  store i32 0, ptr %7, align 4
  br label %89

89:                                               ; preds = %88, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %90 = load i32, ptr %7, align 4
  switch i32 %90, label %96 [
    i32 0, label %91
    i32 4, label %92
  ]

91:                                               ; preds = %89
  br label %92

92:                                               ; preds = %91, %89
  %93 = load i32, ptr %6, align 4, !tbaa !21
  %94 = add i32 %93, 1
  store i32 %94, ptr %6, align 4, !tbaa !21
  br label %36, !llvm.loop !27

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

96:                                               ; preds = %89
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6NPat2H9CPatricia32TestRemoveAndNormalizeDescendantERNS_11CDescendantEjj(ptr noundef nonnull align 8 dereferenceable(168), ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, 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 @_ZN11CLZInWindow13ReduceOffsetsEi(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6NPat2H9CPatricia27TestRemoveNodesAndNormalizeEv(ptr noundef nonnull align 8 dereferenceable(168) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = getelementptr inbounds i8, ptr %0, i64 76
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  %6 = load i32, ptr %5, align 8, !tbaa !12
  %7 = sub i32 %4, %6
  %8 = xor i32 %4, -2147483648
  %reass.sub = sub i32 %8, %6
  %9 = add i32 %reass.sub, 3
  tail call void @_ZN11CLZInWindow13ReduceOffsetsEi(ptr noundef nonnull align 8 dereferenceable(72) %2, i32 noundef %7)
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 8, !tbaa !12
  %12 = add i32 %10, 5
  %13 = sub i32 %12, %11
  %14 = getelementptr inbounds i8, ptr %0, i64 112
  %15 = getelementptr inbounds i8, ptr %0, i64 104
  br label %17

16:                                               ; preds = %.thread
  ret void

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

21:                                               ; preds = %17
  %.idx = shl nsw i64 %indvars.iv25, 10
  br label %22

22:                                               ; preds = %21, %22
  %indvars.iv = phi i64 [ 0, %21 ], [ %indvars.iv.next, %22 ]
  %23 = load ptr, ptr %15, align 8, !tbaa !22
  %24 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %23, i64 %indvars.iv
  %25 = getelementptr inbounds i8, ptr %24, i64 %.idx
  tail call void @_ZN6NPat2H9CPatricia32TestRemoveAndNormalizeDescendantERNS_11CDescendantEjj(ptr noundef nonnull align 8 dereferenceable(168) %0, ptr noundef nonnull align 4 dereferenceable(4) %25, i32 noundef %9, i32 noundef %7)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 256
  br i1 %exitcond.not, label %26, label %22, !llvm.loop !23

26:                                               ; preds = %22
  %.pr = load i32, ptr %19, align 4, !tbaa !21
  %27 = icmp ult i32 %.pr, 2
  br i1 %27, label %.thread, label %28

28:                                               ; preds = %26
  %29 = icmp ult i32 %.pr, %13
  %30 = sub i32 %.pr, %7
  %storemerge = select i1 %29, i32 1, i32 %30
  store i32 %storemerge, ptr %19, align 4, !tbaa !21
  br label %.thread

.thread:                                          ; preds = %17, %26, %28
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %exitcond28.not = icmp eq i64 %indvars.iv.next26, 65536
  br i1 %exitcond28.not, label %16, label %17, !llvm.loop !25
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6NPat2H9CPatricia32TestRemoveAndNormalizeDescendantERNS_11CDescendantEjj(ptr noundef nonnull align 8 dereferenceable(168), ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, 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,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass