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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare noundef zeroext i1 @_ZN11CLZInWindow6CreateEjjj(ptr noundef nonnull align 8 dereferenceable(72), i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind
declare noundef ptr @_Z7MyAllocm(i64 noundef) #2

; 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 @_ZN5NPat29CPatricia10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(160)) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5NPat29CPatricia6CreateEjjjj(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) unnamed_addr #4 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  %18 = load ptr, ptr %7, align 8
  call void @_ZN5NPat29CPatricia10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(160) %18)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 32, ptr %12, align 4, !tbaa !9
  %19 = load i32, ptr %12, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 32
  br i1 %20, label %21, label %28

21:                                               ; preds = %5
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = mul i32 %22, 8
  %24 = load i32, ptr %12, align 4, !tbaa !9
  %25 = shl i32 1, %24
  %26 = icmp ugt i32 %23, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  store i32 -2147024809, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %102

28:                                               ; preds = %21, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 65535, ptr %14, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %29 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %29, ptr %15, align 4, !tbaa !9
  %30 = load i32, ptr %15, align 4, !tbaa !9
  %31 = add i32 %30, 65535
  store i32 %31, ptr %15, align 4, !tbaa !9
  %32 = load i32, ptr %15, align 4, !tbaa !9
  %33 = and i32 %32, -65536
  store i32 %33, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  store i32 524288, ptr %16, align 4, !tbaa !9
  %34 = load i32, ptr %15, align 4, !tbaa !9
  %35 = icmp ult i32 %34, 524288
  br i1 %35, label %36, label %37

36:                                               ; preds = %28
  store i32 524288, ptr %15, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %36, %28
  %38 = load i32, ptr %15, align 4, !tbaa !9
  %39 = add i32 %38, 256
  store i32 %39, ptr %15, align 4, !tbaa !9
  %40 = getelementptr inbounds i8, ptr %18, i64 24
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = add i32 %41, %42
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = add i32 %44, %45
  %47 = load i32, ptr %15, align 4, !tbaa !9
  %48 = call noundef zeroext i1 @_ZN11CLZInWindow6CreateEjjj(ptr noundef nonnull align 8 dereferenceable(72) %40, i32 noundef %43, i32 noundef %46, i32 noundef %47)
  br i1 %48, label %50, label %49

49:                                               ; preds = %37
  store i32 -2147024882, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %101

50:                                               ; preds = %37
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 4
  store i32 %51, ptr %52, align 8, !tbaa !11
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 5
  store i32 %53, ptr %54, align 4, !tbaa !21
  %55 = call noundef ptr @_Z7MyAllocm(i64 noundef 262144) #5
  %56 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 6
  store ptr %55, ptr %56, align 8, !tbaa !22
  %57 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 6
  %58 = load ptr, ptr %57, align 8, !tbaa !22
  %59 = icmp eq ptr %58, null
  br i1 %59, label %60, label %61

60:                                               ; preds = %50
  call void @_ZN5NPat29CPatricia10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(160) %18)
  store i32 -2147024882, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %101

61:                                               ; preds = %50
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 4
  %64 = load i32, ptr %63, align 8, !tbaa !11
  %65 = mul i32 %64, 4
  %66 = udiv i32 %65, 8
  %67 = add i32 %62, %66
  %68 = add i32 %67, 1024
  %69 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 11
  store i32 %68, ptr %69, align 4, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  store i32 -2147483648, ptr %17, align 4, !tbaa !9
  %70 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 11
  %71 = load i32, ptr %70, align 4, !tbaa !23
  %72 = add i32 %71, 32
  %73 = icmp ugt i32 %72, -2147483648
  br i1 %73, label %74, label %75

74:                                               ; preds = %61
  store i32 -2147024809, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %100

75:                                               ; preds = %61
  %76 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 11
  %77 = load i32, ptr %76, align 4, !tbaa !23
  %78 = add i32 %77, 12
  %79 = zext i32 %78 to i64
  %80 = mul i64 %79, 24
  %81 = call noundef ptr @_Z7MyAllocm(i64 noundef %80) #5
  %82 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 7
  store ptr %81, ptr %82, align 8, !tbaa !24
  %83 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 7
  %84 = load ptr, ptr %83, align 8, !tbaa !24
  %85 = icmp eq ptr %84, null
  br i1 %85, label %86, label %87

86:                                               ; preds = %75
  call void @_ZN5NPat29CPatricia10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(160) %18)
  store i32 -2147024882, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %100

87:                                               ; preds = %75
  %88 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 5
  %89 = load i32, ptr %88, align 4, !tbaa !21
  %90 = add i32 %89, 1
  %91 = zext i32 %90 to i64
  %92 = mul i64 %91, 4
  %93 = call noundef ptr @_Z7MyAllocm(i64 noundef %92) #5
  %94 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 14
  store ptr %93, ptr %94, align 8, !tbaa !25
  %95 = getelementptr inbounds %"class.NPat2::CPatricia", ptr %18, i32 0, i32 14
  %96 = load ptr, ptr %95, align 8, !tbaa !25
  %97 = icmp eq ptr %96, null
  br i1 %97, label %98, label %99

98:                                               ; preds = %87
  call void @_ZN5NPat29CPatricia10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(160) %18)
  store i32 -2147024882, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %100

99:                                               ; preds = %87
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %100

100:                                              ; preds = %99, %98, %86, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  br label %101

101:                                              ; preds = %100, %60, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %102

102:                                              ; preds = %101, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  %103 = load i32, ptr %6, align 4
  ret i32 %103
}

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 = { nounwind "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 = { 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 #4 = { 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 #5 = { 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 96}
!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 = !{!12, !10, i64 100}
!22 = !{!12, !6, i64 104}
!23 = !{!12, !10, i64 132}
!24 = !{!12, !6, i64 112}
!25 = !{!12, !6, 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"

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

; Function Attrs: nounwind
declare noundef ptr @_Z7MyAllocm(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5NPat29CPatricia10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(160)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -2147024882, 1) i32 @_ZN5NPat29CPatricia6CreateEjjjj(ptr noundef nonnull align 8 dereferenceable(160) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) unnamed_addr #3 align 2 {
  tail call void @_ZN5NPat29CPatricia10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(160) %0)
  %6 = add i32 %1, 65535
  %7 = and i32 %6, -65536
  %8 = icmp ult i32 %6, 524288
  %9 = or disjoint i32 %7, 256
  %10 = select i1 %8, i32 524544, i32 %9
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = add i32 %2, %1
  %13 = add i32 %4, %3
  %14 = tail call noundef zeroext i1 @_ZN11CLZInWindow6CreateEjjj(ptr noundef nonnull align 8 dereferenceable(72) %11, i32 noundef %12, i32 noundef %13, i32 noundef %10)
  br i1 %14, label %15, label %45

15:                                               ; preds = %5
  %16 = getelementptr inbounds i8, ptr %0, i64 96
  store i32 %1, ptr %16, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 100
  store i32 %3, ptr %17, align 4, !tbaa !19
  %18 = tail call noundef ptr @_Z7MyAllocm(i64 noundef 262144) #4
  %19 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr %18, ptr %19, align 8, !tbaa !20
  %20 = icmp eq ptr %18, null
  br i1 %20, label %.sink.split, label %21

21:                                               ; preds = %15
  %22 = load i32, ptr %16, align 8, !tbaa !5
  %23 = lshr i32 %22, 1
  %24 = and i32 %23, 536870911
  %25 = add i32 %24, %1
  %26 = add i32 %25, 1024
  %27 = getelementptr inbounds i8, ptr %0, i64 132
  store i32 %26, ptr %27, align 4, !tbaa !21
  %28 = add i32 %25, -2147482593
  %29 = icmp ult i32 %28, 2147483647
  br i1 %29, label %45, label %30

30:                                               ; preds = %21
  %31 = add nsw i32 %25, 1036
  %32 = zext i32 %31 to i64
  %33 = mul nuw nsw i64 %32, 24
  %34 = tail call noundef ptr @_Z7MyAllocm(i64 noundef %33) #4
  %35 = getelementptr inbounds i8, ptr %0, i64 112
  store ptr %34, ptr %35, align 8, !tbaa !22
  %36 = icmp eq ptr %34, null
  br i1 %36, label %.sink.split, label %37

37:                                               ; preds = %30
  %38 = load i32, ptr %17, align 4, !tbaa !19
  %39 = add i32 %38, 1
  %40 = zext i32 %39 to i64
  %41 = shl nuw nsw i64 %40, 2
  %42 = tail call noundef ptr @_Z7MyAllocm(i64 noundef %41) #4
  %43 = getelementptr inbounds i8, ptr %0, i64 144
  store ptr %42, ptr %43, align 8, !tbaa !23
  %44 = icmp eq ptr %42, null
  br i1 %44, label %.sink.split, label %45

.sink.split:                                      ; preds = %37, %30, %15
  tail call void @_ZN5NPat29CPatricia10FreeMemoryEv(ptr noundef nonnull align 8 dereferenceable(160) %0)
  br label %45

45:                                               ; preds = %.sink.split, %5, %37, %21
  %.1 = phi i32 [ -2147024882, %5 ], [ -2147024809, %21 ], [ 0, %37 ], [ -2147024882, %.sink.split ]
  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 = { nounwind "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 = { 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 #4 = { 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, !12, i64 96}
!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 = !{!6, !12, i64 100}
!20 = !{!6, !16, i64 104}
!21 = !{!6, !12, i64 132}
!22 = !{!6, !16, i64 112}
!23 = !{!6, !16, i64 144}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass