; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Compress (DeltaFilter)

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

%"struct.NCompress::NDelta::CDelta" = type { i32, [256 x i8] }
%struct.tagPROPVARIANT = type { i16, i16, i16, i16, %union.anon }
%union.anon = type { %struct._LARGE_INTEGER }
%struct._LARGE_INTEGER = type { i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN9NCompress6NDelta8CEncoder18SetCoderPropertiesEPKjPK14tagPROPVARIANTj(ptr noundef nonnull align 8 dereferenceable(288) %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %16 = getelementptr inbounds i8, ptr %15, i64 24
  %17 = getelementptr inbounds %"struct.NCompress::NDelta::CDelta", ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  store i32 %18, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %62, %4
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 2, ptr %12, align 4
  br label %65

24:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %25, i64 %27
  store ptr %28, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #2
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %29, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !9
  store i32 %33, ptr %14, align 4, !tbaa !9
  %34 = load i32, ptr %14, align 4, !tbaa !9
  %35 = icmp uge i32 %34, 16
  br i1 %35, label %36, label %37

36:                                               ; preds = %24
  store i32 4, ptr %12, align 4
  br label %59

37:                                               ; preds = %24
  %38 = load ptr, ptr %13, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %38, i32 0, i32 0
  %40 = load i16, ptr %39, align 8, !tbaa !13
  %41 = zext i16 %40 to i32
  %42 = icmp ne i32 %41, 19
  br i1 %42, label %43, label %44

43:                                               ; preds = %37
  store i32 -2147024809, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %59

44:                                               ; preds = %37
  %45 = load i32, ptr %14, align 4, !tbaa !9
  switch i32 %45, label %57 [
    i32 0, label %46
    i32 13, label %58
    i32 15, label %58
  ]

46:                                               ; preds = %44
  %47 = load ptr, ptr %13, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %47, i32 0, i32 4
  %49 = load i32, ptr %48, align 8, !tbaa !16
  store i32 %49, ptr %10, align 4, !tbaa !9
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = icmp ult i32 %50, 1
  br i1 %51, label %55, label %52

52:                                               ; preds = %46
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = icmp ugt i32 %53, 256
  br i1 %54, label %55, label %56

55:                                               ; preds = %52, %46
  store i32 -2147024809, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %59

56:                                               ; preds = %52
  br label %58

57:                                               ; preds = %44
  store i32 -2147024809, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %59

58:                                               ; preds = %56, %44, %44
  store i32 0, ptr %12, align 4
  br label %59

59:                                               ; preds = %58, %57, %55, %43, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  %60 = load i32, ptr %12, align 4
  switch i32 %60, label %65 [
    i32 0, label %61
    i32 4, label %62
  ]

61:                                               ; preds = %59
  br label %62

62:                                               ; preds = %61, %59
  %63 = load i32, ptr %11, align 4, !tbaa !9
  %64 = add i32 %63, 1
  store i32 %64, ptr %11, align 4, !tbaa !9
  br label %19, !llvm.loop !17

65:                                               ; preds = %59, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  %66 = load i32, ptr %12, align 4
  switch i32 %66, label %71 [
    i32 2, label %67
  ]

67:                                               ; preds = %65
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = getelementptr inbounds i8, ptr %15, i64 24
  %70 = getelementptr inbounds %"struct.NCompress::NDelta::CDelta", ptr %69, i32 0, i32 0
  store i32 %68, ptr %70, align 8, !tbaa !11
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %71

71:                                               ; preds = %67, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %72 = load i32, ptr %5, align 4
  ret i32 %72
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 0}
!12 = !{!"_ZTSN9NCompress6NDelta6CDeltaE", !10, i64 0, !7, i64 4}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS14tagPROPVARIANT", !15, i64 0, !15, i64 2, !15, i64 4, !15, i64 6, !7, i64 8}
!15 = !{!"short", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.tagPROPVARIANT = type { i16, i16, i16, i16, %union.anon }
%union.anon = type { %struct._LARGE_INTEGER }
%struct._LARGE_INTEGER = type { i64 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef i32 @_ZN9NCompress6NDelta8CEncoder18SetCoderPropertiesEPKjPK14tagPROPVARIANTj(ptr nocapture noundef nonnull align 8 dereferenceable(288) %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.not2733.not = icmp eq i32 %3, 0
  br i1 %.not2733.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = zext i32 %3 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %18
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %18 ]
  %.01835 = phi i32 [ %6, %.lr.ph.preheader ], [ %.220, %18 ]
  %7 = getelementptr inbounds %struct.tagPROPVARIANT, ptr %2, i64 %indvars.iv
  %8 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv
  %9 = load i32, ptr %8, align 4, !tbaa !10
  %10 = icmp ugt i32 %9, 15
  br i1 %10, label %18, label %11

11:                                               ; preds = %.lr.ph
  %12 = load i16, ptr %7, align 8, !tbaa !11
  %.not = icmp eq i16 %12, 19
  br i1 %.not, label %13, label %.thread30

13:                                               ; preds = %11
  switch i32 %9, label %.thread30 [
    i32 0, label %14
    i32 13, label %18
    i32 15, label %18
  ]

14:                                               ; preds = %13
  %15 = getelementptr inbounds i8, ptr %7, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = add i32 %16, -257
  %or.cond = icmp ult i32 %17, -256
  br i1 %or.cond, label %.thread30, label %18

18:                                               ; preds = %13, %13, %14, %.lr.ph
  %.220 = phi i32 [ %.01835, %.lr.ph ], [ %.01835, %13 ], [ %.01835, %13 ], [ %16, %14 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %18, %4
  %.018.lcssa = phi i32 [ %6, %4 ], [ %.220, %18 ]
  store i32 %.018.lcssa, ptr %5, align 8, !tbaa !5
  br label %.thread30

.thread30:                                        ; preds = %11, %14, %13, %._crit_edge
  %.3 = phi i32 [ 0, %._crit_edge ], [ -2147024809, %13 ], [ -2147024809, %14 ], [ -2147024809, %11 ]
  ret i32 %.3
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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, !7, i64 0}
!6 = !{!"_ZTSN9NCompress6NDelta6CDeltaE", !7, i64 0, !8, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS14tagPROPVARIANT", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !8, i64 8}
!13 = !{!"short", !8, i64 0}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass