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

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

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

15:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %43

16:                                               ; preds = %3
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = and i32 %17, -2
  store i32 %18, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  store ptr %22, ptr %10, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %37, %16
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #2
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 0
  %26 = load i8, ptr %25, align 1, !tbaa !11
  store i8 %26, ptr %11, align 1, !tbaa !11
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 1
  %29 = load i8, ptr %28, align 1, !tbaa !11
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 0
  store i8 %29, ptr %31, align 1, !tbaa !11
  %32 = load i8, ptr %11, align 1, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 1
  store i8 %32, ptr %34, align 1, !tbaa !11
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 2
  store ptr %36, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #2
  br label %37

37:                                               ; preds = %23
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = icmp ne ptr %38, %39
  br i1 %40, label %23, label %41, !llvm.loop !12

41:                                               ; preds = %37
  %42 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %42, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %43

43:                                               ; preds = %41, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %44 = load i32, ptr %4, align 4
  ret i32 %44
}

; 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 0, -1) i32 @_ZN9NCompress9NByteSwap10CByteSwap26FilterEPhj(ptr nocapture noundef nonnull readnone align 8 dereferenceable(12) %0, ptr noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = icmp ult i32 %2, 2
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %3
  %6 = and i32 %2, -2
  %7 = zext i32 %6 to i64
  %8 = getelementptr inbounds i8, ptr %1, i64 %7
  %9 = add nsw i64 %7, -2
  %10 = lshr exact i64 %9, 1
  %11 = add nuw i64 %10, 1
  %xtraiter = and i64 %11, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.preheader

.prol.preheader:                                  ; preds = %5, %.prol.preheader
  %.014.prol = phi ptr [ %15, %.prol.preheader ], [ %1, %5 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.prol.preheader ], [ 0, %5 ]
  %12 = load i8, ptr %.014.prol, align 1, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.014.prol, i64 1
  %14 = load i8, ptr %13, align 1, !tbaa !5
  store i8 %14, ptr %.014.prol, align 1, !tbaa !5
  store i8 %12, ptr %13, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.014.prol, i64 2
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.prol.loopexit, label %.prol.preheader, !llvm.loop !8

.prol.loopexit:                                   ; preds = %.prol.preheader, %5
  %.014.unr = phi ptr [ %1, %5 ], [ %15, %.prol.preheader ]
  %16 = icmp ult i64 %9, 6
  br i1 %16, label %.loopexit, label %.new

.new:                                             ; preds = %.prol.loopexit, %.new
  %.014 = phi ptr [ %32, %.new ], [ %.014.unr, %.prol.loopexit ]
  %17 = load i8, ptr %.014, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.014, i64 1
  %19 = load i8, ptr %18, align 1, !tbaa !5
  store i8 %19, ptr %.014, align 1, !tbaa !5
  store i8 %17, ptr %18, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %.014, i64 2
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %.014, i64 3
  %23 = load i8, ptr %22, align 1, !tbaa !5
  store i8 %23, ptr %20, align 1, !tbaa !5
  store i8 %21, ptr %22, align 1, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.014, i64 4
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %.014, i64 5
  %27 = load i8, ptr %26, align 1, !tbaa !5
  store i8 %27, ptr %24, align 1, !tbaa !5
  store i8 %25, ptr %26, align 1, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.014, i64 6
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %.014, i64 7
  %31 = load i8, ptr %30, align 1, !tbaa !5
  store i8 %31, ptr %28, align 1, !tbaa !5
  store i8 %29, ptr %30, align 1, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %.014, i64 8
  %.not.3 = icmp eq ptr %32, %8
  br i1 %.not.3, label %.loopexit, label %.new, !llvm.loop !10

.loopexit:                                        ; preds = %.prol.loopexit, %.new, %3
  %.0 = phi i32 [ 0, %3 ], [ %6, %.new ], [ %6, %.prol.loopexit ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.unroll.disable"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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