; 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.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.CLZInWindow = type { ptr, ptr, ptr, i32, i8, ptr, ptr, i32, i32, i32, i32, i32, i32 }
%class.CMyComPtr = type { ptr }
%"union.NPat2H::CDescendant" = type { i32 }
%"struct.NPat2H::CNode" = type { i32, i32, %union.anon.0 }
%union.anon.0 = type { [4 x %"union.NPat2H::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

declare noundef i32 @_ZN11CLZInWindow4InitEP19ISequentialInStream(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6NPat2H9CPatricia4InitEP19ISequentialInStream(ptr noundef nonnull align 8 dereferenceable(168) %0, ptr noundef %1) unnamed_addr #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %10 = getelementptr inbounds i8, ptr %9, i64 24
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call noundef i32 @_ZN11CLZInWindow4InitEP19ISequentialInStream(ptr noundef nonnull align 8 dereferenceable(72) %10, ptr noundef %11)
  store i32 %12, ptr %6, align 4, !tbaa !9
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %2
  %16 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %16, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %18

17:                                               ; preds = %2
  store i32 0, ptr %7, align 4
  br label %18

18:                                               ; preds = %17, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %19 = load i32, ptr %7, align 4
  switch i32 %19, label %45 [
    i32 0, label %20
    i32 1, label %43
  ]

20:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %31, %20
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = icmp ult i32 %22, 65536
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %34

25:                                               ; preds = %21
  %26 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %9, i32 0, i32 7
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %27, i64 %29
  store i32 0, ptr %30, align 4, !tbaa !21
  br label %31

31:                                               ; preds = %25
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = add i32 %32, 1
  store i32 %33, ptr %8, align 4, !tbaa !9
  br label %21, !llvm.loop !22

34:                                               ; preds = %24
  %35 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %9, i32 0, i32 8
  %36 = load ptr, ptr %35, align 8, !tbaa !24
  %37 = getelementptr inbounds %"struct.NPat2H::CNode", ptr %36, i64 0
  %38 = getelementptr inbounds %"struct.NPat2H::CNode", ptr %37, i32 0, i32 2
  store i32 1, ptr %38, align 4, !tbaa !21
  %39 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %9, i32 0, i32 9
  store i32 0, ptr %39, align 8, !tbaa !25
  %40 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %9, i32 0, i32 10
  store i32 0, ptr %40, align 4, !tbaa !26
  %41 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %9, i32 0, i32 11
  store i32 0, ptr %41, align 8, !tbaa !27
  %42 = getelementptr inbounds %"class.NPat2H::CPatricia", ptr %9, i32 0, i32 13
  store i8 0, ptr %42, align 8, !tbaa !28
  store i32 0, ptr %3, align 4
  br label %43

43:                                               ; preds = %34, %18
  %44 = load i32, ptr %3, align 4
  ret i32 %44

45:                                               ; preds = %18
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = !{!"_ZTSN6NPat2H9CPatriciaE", !13, i64 0, !16, i64 8, !17, i64 16, !18, i64 24, !10, i64 96, !10, i64 100, !6, i64 104, !6, i64 112, !6, i64 120, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !19, i64 144, !10, i64 148, !6, i64 152, !20, i64 160}
!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, !6, i64 120}
!25 = !{!12, !10, i64 128}
!26 = !{!12, !10, i64 132}
!27 = !{!12, !10, i64 136}
!28 = !{!12, !19, i64 144}


; 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 }

declare noundef i32 @_ZN11CLZInWindow4InitEP19ISequentialInStream(ptr noundef nonnull align 8 dereferenceable(72), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6NPat2H9CPatricia4InitEP19ISequentialInStream(ptr noundef nonnull align 8 dereferenceable(168) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = tail call noundef i32 @_ZN11CLZInWindow4InitEP19ISequentialInStream(ptr noundef nonnull align 8 dereferenceable(72) %3, ptr noundef %1)
  %.not.not = icmp eq i32 %4, 0
  br i1 %.not.not, label %.preheader, label %23

.preheader:                                       ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 112
  br label %14

6:                                                ; preds = %14
  %7 = getelementptr inbounds i8, ptr %0, i64 120
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  store i32 1, ptr %9, align 4, !tbaa !19
  %10 = getelementptr inbounds i8, ptr %0, i64 128
  store i32 0, ptr %10, align 8, !tbaa !20
  %11 = getelementptr inbounds i8, ptr %0, i64 132
  store i32 0, ptr %11, align 4, !tbaa !21
  %12 = getelementptr inbounds i8, ptr %0, i64 136
  store i32 0, ptr %12, align 8, !tbaa !22
  %13 = getelementptr inbounds i8, ptr %0, i64 144
  store i8 0, ptr %13, align 8, !tbaa !23
  br label %23

14:                                               ; preds = %14, %.preheader
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next.3, %14 ]
  %15 = load ptr, ptr %5, align 8, !tbaa !24
  %16 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %15, i64 %indvars.iv
  store i32 0, ptr %16, align 4, !tbaa !19
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = load ptr, ptr %5, align 8, !tbaa !24
  %18 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %17, i64 %indvars.iv.next
  store i32 0, ptr %18, align 4, !tbaa !19
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %19 = load ptr, ptr %5, align 8, !tbaa !24
  %20 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %19, i64 %indvars.iv.next.1
  store i32 0, ptr %20, align 4, !tbaa !19
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %21 = load ptr, ptr %5, align 8, !tbaa !24
  %22 = getelementptr inbounds %"union.NPat2H::CDescendant", ptr %21, i64 %indvars.iv.next.2
  store i32 0, ptr %22, align 4, !tbaa !19
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 65536
  br i1 %exitcond.not.3, label %6, label %14, !llvm.loop !25

23:                                               ; preds = %2, %6
  %.1 = phi i32 [ %4, %2 ], [ 0, %6 ]
  ret i32 %.1
}

attributes #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, !16, i64 120}
!6 = !{!"_ZTSN6NPat2H9CPatriciaE", !7, i64 0, !10, i64 8, !11, i64 16, !15, i64 24, !12, i64 96, !12, i64 100, !16, i64 104, !16, i64 112, !16, i64 120, !12, i64 128, !12, i64 132, !12, i64 136, !12, i64 140, !17, i64 144, !12, i64 148, !16, i64 152, !18, i64 160}
!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 128}
!21 = !{!6, !12, i64 132}
!22 = !{!6, !12, i64 136}
!23 = !{!6, !17, i64 144}
!24 = !{!6, !16, i64 112}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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