; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseResizerNearest.ll (ZN4Simd4Base14ResizerNearest6ResizeEPKhmPhm)

; 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.Simd::Resizer" = type { %"struct.Simd::Deletable", %"struct.Simd::ResParam" }
%"struct.Simd::Deletable" = type { ptr }
%"struct.Simd::ResParam" = type { i32, i32, i64, i64, i64, i64, i64, i64 }
%"class.Simd::Base::ResizerNearest" = type { %"class.Simd::Resizer", i64, %"struct.Simd::Array", %"struct.Simd::Array" }
%"struct.Simd::Array" = type { ptr, i64 }

; 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 uwtable
define dso_local void @_ZN4Simd4Base14ResizerNearest6ResizeEPKhmPhm(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i64 %4, ptr %10, align 8, !tbaa !9
  %16 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %65, %5
  %18 = load i64, ptr %11, align 8, !tbaa !9
  %19 = getelementptr inbounds %"class.Simd::Resizer", ptr %16, i32 0, i32 1
  %20 = getelementptr inbounds %"struct.Simd::ResParam", ptr %19, i32 0, i32 5
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = icmp ult i64 %18, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %17
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %68

24:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.Simd::Base::ResizerNearest", ptr %16, i32 0, i32 3
  %27 = load i64, ptr %11, align 8, !tbaa !9
  %28 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN4Simd5ArrayIiEixEm(ptr noundef nonnull align 8 dereferenceable(16) %26, i64 noundef %27)
  %29 = load i32, ptr %28, align 4, !tbaa !17
  %30 = sext i32 %29 to i64
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = mul i64 %30, %31
  %33 = getelementptr inbounds i8, ptr %25, i64 %32
  store ptr %33, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %54, %24
  %35 = load i64, ptr %14, align 8, !tbaa !9
  %36 = getelementptr inbounds %"class.Simd::Resizer", ptr %16, i32 0, i32 1
  %37 = getelementptr inbounds %"struct.Simd::ResParam", ptr %36, i32 0, i32 4
  %38 = load i64, ptr %37, align 8, !tbaa !19
  %39 = icmp ult i64 %35, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %34
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %61

41:                                               ; preds = %34
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i64, ptr %15, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %42, i64 %43
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = getelementptr inbounds %"class.Simd::Base::ResizerNearest", ptr %16, i32 0, i32 2
  %47 = load i64, ptr %14, align 8, !tbaa !9
  %48 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN4Simd5ArrayIiEixEm(ptr noundef nonnull align 8 dereferenceable(16) %46, i64 noundef %47)
  %49 = load i32, ptr %48, align 4, !tbaa !17
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i8, ptr %45, i64 %50
  %52 = getelementptr inbounds %"class.Simd::Base::ResizerNearest", ptr %16, i32 0, i32 1
  %53 = load i64, ptr %52, align 8, !tbaa !20
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %44, ptr align 1 %51, i64 %53, i1 false)
  br label %54

54:                                               ; preds = %41
  %55 = load i64, ptr %14, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %14, align 8, !tbaa !9
  %57 = getelementptr inbounds %"class.Simd::Base::ResizerNearest", ptr %16, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !20
  %59 = load i64, ptr %15, align 8, !tbaa !9
  %60 = add i64 %59, %58
  store i64 %60, ptr %15, align 8, !tbaa !9
  br label %34, !llvm.loop !23

61:                                               ; preds = %40
  %62 = load i64, ptr %10, align 8, !tbaa !9
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i64 %62
  store ptr %64, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %65

65:                                               ; preds = %61
  %66 = load i64, ptr %11, align 8, !tbaa !9
  %67 = add i64 %66, 1
  store i64 %67, ptr %11, align 8, !tbaa !9
  br label %17, !llvm.loop !25

68:                                               ; preds = %23
  ret void
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN4Simd5ArrayIiEixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #2 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { alwaysinline 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !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 = !{!12, !10, i64 40}
!12 = !{!"_ZTSN4Simd7ResizerE", !13, i64 0, !14, i64 8}
!13 = !{!"_ZTSN4Simd9DeletableE"}
!14 = !{!"_ZTSN4Simd8ResParamE", !15, i64 0, !16, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!15 = !{!"_ZTS21SimdResizeChannelType", !7, i64 0}
!16 = !{!"_ZTS20SimdResizeMethodType", !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!12, !10, i64 32}
!20 = !{!21, !10, i64 64}
!21 = !{!"_ZTSN4Simd4Base14ResizerNearestE", !12, i64 0, !10, i64 64, !22, i64 72, !22, i64 88}
!22 = !{!"_ZTSN4Simd5ArrayIiEE", !6, i64 0, !10, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


; 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 nounwind uwtable
define dso_local void @_ZN4Simd4Base14ResizerNearest6ResizeEPKhmPhm(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef writeonly %3, i64 noundef %4) local_unnamed_addr #0 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %._crit_edge23, label %.lr.ph22

.lr.ph22:                                         ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 88
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = getelementptr inbounds i8, ptr %0, i64 72
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  br label %12

._crit_edge23:                                    ; preds = %._crit_edge, %5
  ret void

12:                                               ; preds = %.lr.ph22, %._crit_edge
  %.01520 = phi ptr [ %3, %.lr.ph22 ], [ %19, %._crit_edge ]
  %.01619 = phi i64 [ 0, %.lr.ph22 ], [ %20, %._crit_edge ]
  %13 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN4Simd5ArrayIiEixEm(ptr noundef nonnull align 8 dereferenceable(16) %8, i64 noundef %.01619)
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %15 = sext i32 %14 to i64
  %16 = mul i64 %15, %2
  %17 = getelementptr inbounds i8, ptr %1, i64 %16
  %18 = load i64, ptr %9, align 8, !tbaa !16
  %.not24 = icmp eq i64 %18, 0
  br i1 %.not24, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %12
  %19 = getelementptr inbounds i8, ptr %.01520, i64 %4
  %20 = add nuw i64 %.01619, 1
  %21 = load i64, ptr %6, align 8, !tbaa !5
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %12, label %._crit_edge23, !llvm.loop !17

.lr.ph:                                           ; preds = %12, %.lr.ph
  %.018 = phi i64 [ %31, %.lr.ph ], [ 0, %12 ]
  %.01417 = phi i64 [ %29, %.lr.ph ], [ 0, %12 ]
  %23 = getelementptr inbounds i8, ptr %.01520, i64 %.018
  %24 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN4Simd5ArrayIiEixEm(ptr noundef nonnull align 8 dereferenceable(16) %10, i64 noundef %.01417)
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %17, i64 %26
  %28 = load i64, ptr %11, align 8, !tbaa !19
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %23, ptr align 1 %27, i64 %28, i1 false)
  %29 = add nuw i64 %.01417, 1
  %30 = load i64, ptr %11, align 8, !tbaa !19
  %31 = add i64 %30, %.018
  %32 = load i64, ptr %9, align 8, !tbaa !16
  %33 = icmp ult i64 %29, %32
  br i1 %33, label %.lr.ph, label %._crit_edge, !llvm.loop !23
}

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN4Simd5ArrayIiEixEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { alwaysinline 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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, !13, i64 40}
!6 = !{!"_ZTSN4Simd7ResizerE", !7, i64 0, !8, i64 8}
!7 = !{!"_ZTSN4Simd9DeletableE"}
!8 = !{!"_ZTSN4Simd8ResParamE", !9, i64 0, !12, i64 4, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48}
!9 = !{!"_ZTS21SimdResizeChannelType", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"_ZTS20SimdResizeMethodType", !10, i64 0}
!13 = !{!"long", !10, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !10, i64 0}
!16 = !{!6, !13, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !13, i64 64}
!20 = !{!"_ZTSN4Simd4Base14ResizerNearestE", !6, i64 0, !13, i64 64, !21, i64 72, !21, i64 88}
!21 = !{!"_ZTSN4Simd5ArrayIiEE", !22, i64 0, !13, i64 8}
!22 = !{!"any pointer", !10, i64 0}
!23 = distinct !{!23, !18}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass