; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseInterleave.ll (ZN4Simd4Base13InterleaveBgrEPKhmS2_mS2_mmmPhm)

; 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: 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
define dso_local void @_ZN4Simd4Base13InterleaveBgrEPKhmS2_mS2_mmmPhm(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, i64 noundef %6, i64 noundef %7, ptr noundef %8, i64 noundef %9) #1 {
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i64, align 8
  %21 = alloca i64, align 8
  %22 = alloca i32, align 4
  %23 = alloca i64, align 8
  %24 = alloca i64, align 8
  store ptr %0, ptr %11, align 8, !tbaa !5
  store i64 %1, ptr %12, align 8, !tbaa !9
  store ptr %2, ptr %13, align 8, !tbaa !5
  store i64 %3, ptr %14, align 8, !tbaa !9
  store ptr %4, ptr %15, align 8, !tbaa !5
  store i64 %5, ptr %16, align 8, !tbaa !9
  store i64 %6, ptr %17, align 8, !tbaa !9
  store i64 %7, ptr %18, align 8, !tbaa !9
  store ptr %8, ptr %19, align 8, !tbaa !5
  store i64 %9, ptr %20, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #2
  store i64 0, ptr %21, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %79, %10
  %26 = load i64, ptr %21, align 8, !tbaa !9
  %27 = load i64, ptr %18, align 8, !tbaa !9
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 2, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #2
  br label %82

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #2
  store i64 0, ptr %23, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #2
  store i64 0, ptr %24, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %61, %30
  %32 = load i64, ptr %23, align 8, !tbaa !9
  %33 = load i64, ptr %17, align 8, !tbaa !9
  %34 = icmp ult i64 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 5, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #2
  br label %66

36:                                               ; preds = %31
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = load i64, ptr %23, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %37, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !11
  %41 = load ptr, ptr %19, align 8, !tbaa !5
  %42 = load i64, ptr %24, align 8, !tbaa !9
  %43 = add i64 %42, 0
  %44 = getelementptr inbounds i8, ptr %41, i64 %43
  store i8 %40, ptr %44, align 1, !tbaa !11
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = load i64, ptr %23, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = load ptr, ptr %19, align 8, !tbaa !5
  %50 = load i64, ptr %24, align 8, !tbaa !9
  %51 = add i64 %50, 1
  %52 = getelementptr inbounds i8, ptr %49, i64 %51
  store i8 %48, ptr %52, align 1, !tbaa !11
  %53 = load ptr, ptr %15, align 8, !tbaa !5
  %54 = load i64, ptr %23, align 8, !tbaa !9
  %55 = getelementptr inbounds i8, ptr %53, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !11
  %57 = load ptr, ptr %19, align 8, !tbaa !5
  %58 = load i64, ptr %24, align 8, !tbaa !9
  %59 = add i64 %58, 2
  %60 = getelementptr inbounds i8, ptr %57, i64 %59
  store i8 %56, ptr %60, align 1, !tbaa !11
  br label %61

61:                                               ; preds = %36
  %62 = load i64, ptr %23, align 8, !tbaa !9
  %63 = add i64 %62, 1
  store i64 %63, ptr %23, align 8, !tbaa !9
  %64 = load i64, ptr %24, align 8, !tbaa !9
  %65 = add i64 %64, 3
  store i64 %65, ptr %24, align 8, !tbaa !9
  br label %31, !llvm.loop !12

66:                                               ; preds = %35
  %67 = load i64, ptr %12, align 8, !tbaa !9
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 %67
  store ptr %69, ptr %11, align 8, !tbaa !5
  %70 = load i64, ptr %14, align 8, !tbaa !9
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 %70
  store ptr %72, ptr %13, align 8, !tbaa !5
  %73 = load i64, ptr %16, align 8, !tbaa !9
  %74 = load ptr, ptr %15, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i64 %73
  store ptr %75, ptr %15, align 8, !tbaa !5
  %76 = load i64, ptr %20, align 8, !tbaa !9
  %77 = load ptr, ptr %19, align 8, !tbaa !5
  %78 = getelementptr inbounds i8, ptr %77, i64 %76
  store ptr %78, ptr %19, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %66
  %80 = load i64, ptr %21, align 8, !tbaa !9
  %81 = add i64 %80, 1
  store i64 %81, ptr %21, align 8, !tbaa !9
  br label %25, !llvm.loop !14

82:                                               ; preds = %29
  ret void
}

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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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 void @_ZN4Simd4Base13InterleaveBgrEPKhmS2_mS2_mmmPhm(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3, ptr nocapture noundef readonly %4, i64 noundef %5, i64 noundef %6, i64 noundef %7, ptr nocapture noundef writeonly %8, i64 noundef %9) local_unnamed_addr #0 {
  %.not = icmp eq i64 %7, 0
  %.not40 = icmp eq i64 %6, 0
  %or.cond = or i1 %.not, %.not40
  br i1 %or.cond, label %._crit_edge39, label %.preheader.us.preheader

.preheader.us.preheader:                          ; preds = %10
  %xtraiter = and i64 %6, 1
  %11 = icmp eq i64 %6, 1
  %unroll_iter = and i64 %6, -2
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.02738.us = phi i64 [ %53, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %.02837.us = phi ptr [ %49, %._crit_edge.us ], [ %0, %.preheader.us.preheader ]
  %.02936.us = phi ptr [ %52, %._crit_edge.us ], [ %8, %.preheader.us.preheader ]
  %.03035.us = phi ptr [ %50, %._crit_edge.us ], [ %2, %.preheader.us.preheader ]
  %.03134.us = phi ptr [ %51, %._crit_edge.us ], [ %4, %.preheader.us.preheader ]
  br i1 %11, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.033.us = phi i64 [ %37, %.preheader.us.new ], [ 0, %.preheader.us ]
  %.02632.us = phi i64 [ %36, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %12 = getelementptr inbounds i8, ptr %.02837.us, i64 %.02632.us
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %.02936.us, i64 %.033.us
  store i8 %13, ptr %14, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.03035.us, i64 %.02632.us
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = or disjoint i64 %.033.us, 1
  %18 = getelementptr inbounds i8, ptr %.02936.us, i64 %17
  store i8 %16, ptr %18, align 1, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %.03134.us, i64 %.02632.us
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = add i64 %.033.us, 2
  %22 = getelementptr inbounds i8, ptr %.02936.us, i64 %21
  store i8 %20, ptr %22, align 1, !tbaa !5
  %23 = or disjoint i64 %.02632.us, 1
  %24 = add i64 %.033.us, 3
  %25 = getelementptr inbounds i8, ptr %.02837.us, i64 %23
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %.02936.us, i64 %24
  store i8 %26, ptr %27, align 1, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %.03035.us, i64 %23
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = add i64 %.033.us, 4
  %31 = getelementptr inbounds i8, ptr %.02936.us, i64 %30
  store i8 %29, ptr %31, align 1, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %.03134.us, i64 %23
  %33 = load i8, ptr %32, align 1, !tbaa !5
  %34 = add i64 %.033.us, 5
  %35 = getelementptr inbounds i8, ptr %.02936.us, i64 %34
  store i8 %33, ptr %35, align 1, !tbaa !5
  %36 = add nuw i64 %.02632.us, 2
  %37 = add i64 %.033.us, 6
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !8

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.033.us.unr = phi i64 [ 0, %.preheader.us ], [ %37, %.preheader.us.new ]
  %.02632.us.unr = phi i64 [ 0, %.preheader.us ], [ %36, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %38 = getelementptr inbounds i8, ptr %.02837.us, i64 %.02632.us.unr
  %39 = load i8, ptr %38, align 1, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %.02936.us, i64 %.033.us.unr
  store i8 %39, ptr %40, align 1, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %.03035.us, i64 %.02632.us.unr
  %42 = load i8, ptr %41, align 1, !tbaa !5
  %43 = add i64 %.033.us.unr, 1
  %44 = getelementptr inbounds i8, ptr %.02936.us, i64 %43
  store i8 %42, ptr %44, align 1, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %.03134.us, i64 %.02632.us.unr
  %46 = load i8, ptr %45, align 1, !tbaa !5
  %47 = add i64 %.033.us.unr, 2
  %48 = getelementptr inbounds i8, ptr %.02936.us, i64 %47
  store i8 %46, ptr %48, align 1, !tbaa !5
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %49 = getelementptr inbounds i8, ptr %.02837.us, i64 %1
  %50 = getelementptr inbounds i8, ptr %.03035.us, i64 %3
  %51 = getelementptr inbounds i8, ptr %.03134.us, i64 %5
  %52 = getelementptr inbounds i8, ptr %.02936.us, i64 %9
  %53 = add nuw i64 %.02738.us, 1
  %exitcond42.not = icmp eq i64 %53, %7
  br i1 %exitcond42.not, label %._crit_edge39, label %.preheader.us, !llvm.loop !10

._crit_edge39:                                    ; preds = %._crit_edge.us, %10
  ret void
}

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.mustprogress"}
!10 = distinct !{!10, !9}


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