; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseSynetPermute.ll (ZN4Simd4Base12SynetPermute7ForwardEPKhPh)

; 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::Base::SynetPermute" = type { %"struct.Simd::Deletable", %"struct.Simd::Base::PermuteParam", %"struct.Simd::Array", i64, i64, i64, %"class.std::vector", %"class.std::vector", %"class.std::vector", %"class.std::vector", %"class.std::vector", %"class.std::vector", ptr }
%"struct.Simd::Deletable" = type { ptr }
%"struct.Simd::Base::PermuteParam" = type <{ %"class.std::vector", %"class.std::vector", i64, i64, i32, [4 x i8] }>
%"struct.Simd::Array" = type { ptr, i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; 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 @_ZN4Simd4Base12SynetPermute7ForwardEPKhPh(ptr noundef nonnull align 8 dereferenceable(272) %0, ptr noundef %1, ptr noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %30, %3
  %10 = load i64, ptr %7, align 8, !tbaa !9
  %11 = getelementptr inbounds %"class.Simd::Base::SynetPermute", ptr %8, i32 0, i32 3
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = icmp ult i64 %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %33

15:                                               ; preds = %9
  %16 = getelementptr inbounds %"class.Simd::Base::SynetPermute", ptr %8, i32 0, i32 12
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %"class.Simd::Base::SynetPermute", ptr %8, i32 0, i32 9
  %20 = getelementptr inbounds %"class.Simd::Base::SynetPermute", ptr %8, i32 0, i32 8
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  call void %17(ptr noundef %18, ptr noundef nonnull align 8 dereferenceable(24) %19, ptr noundef nonnull align 8 dereferenceable(24) %20, ptr noundef %21)
  %22 = getelementptr inbounds %"class.Simd::Base::SynetPermute", ptr %8, i32 0, i32 4
  %23 = load i64, ptr %22, align 8, !tbaa !22
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 %23
  store ptr %25, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.Simd::Base::SynetPermute", ptr %8, i32 0, i32 4
  %27 = load i64, ptr %26, align 8, !tbaa !22
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %28, i64 %27
  store ptr %29, ptr %6, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %15
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = add i64 %31, 1
  store i64 %32, ptr %7, align 8, !tbaa !9
  br label %9, !llvm.loop !23

33:                                               ; preds = %14
  ret void
}

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 = { 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 96}
!12 = !{!"_ZTSN4Simd4Base12SynetPermuteE", !13, i64 0, !14, i64 8, !20, i64 80, !10, i64 96, !10, i64 104, !10, i64 112, !15, i64 120, !15, i64 144, !15, i64 168, !15, i64 192, !15, i64 216, !15, i64 240, !6, i64 264}
!13 = !{!"_ZTSN4Simd9DeletableE"}
!14 = !{!"_ZTSN4Simd4Base12PermuteParamE", !15, i64 0, !15, i64 24, !10, i64 48, !10, i64 56, !19, i64 64}
!15 = !{!"_ZTSSt6vectorImSaImEE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseImSaImEE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseImSaImEE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseImSaImEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!"_ZTS18SimdTensorDataType", !7, i64 0}
!20 = !{!"_ZTSN4Simd5ArrayIiEE", !6, i64 0, !10, i64 8}
!21 = !{!12, !6, i64 264}
!22 = !{!12, !10, i64 104}
!23 = distinct !{!23, !24}
!24 = !{!"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 uwtable
define dso_local void @_ZN4Simd4Base12SynetPermute7ForwardEPKhPh(ptr noundef nonnull align 8 dereferenceable(272) %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 264
  %7 = getelementptr inbounds i8, ptr %0, i64 192
  %8 = getelementptr inbounds i8, ptr %0, i64 168
  %9 = getelementptr inbounds i8, ptr %0, i64 104
  br label %10

._crit_edge:                                      ; preds = %10, %3
  ret void

10:                                               ; preds = %.lr.ph, %10
  %.010 = phi i64 [ 0, %.lr.ph ], [ %15, %10 ]
  %.069 = phi ptr [ %2, %.lr.ph ], [ %14, %10 ]
  %.078 = phi ptr [ %1, %.lr.ph ], [ %13, %10 ]
  %11 = load ptr, ptr %6, align 8, !tbaa !19
  tail call void %11(ptr noundef %.078, ptr noundef nonnull align 8 dereferenceable(24) %7, ptr noundef nonnull align 8 dereferenceable(24) %8, ptr noundef %.069)
  %12 = load i64, ptr %9, align 8, !tbaa !20
  %13 = getelementptr inbounds i8, ptr %.078, i64 %12
  %14 = getelementptr inbounds i8, ptr %.069, i64 %12
  %15 = add nuw i64 %.010, 1
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %10, label %._crit_edge, !llvm.loop !21
}

attributes #0 = { 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" }

!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, !16, i64 96}
!6 = !{!"_ZTSN4Simd4Base12SynetPermuteE", !7, i64 0, !8, i64 8, !18, i64 80, !16, i64 96, !16, i64 104, !16, i64 112, !9, i64 120, !9, i64 144, !9, i64 168, !9, i64 192, !9, i64 216, !9, i64 240, !13, i64 264}
!7 = !{!"_ZTSN4Simd9DeletableE"}
!8 = !{!"_ZTSN4Simd4Base12PermuteParamE", !9, i64 0, !9, i64 24, !16, i64 48, !16, i64 56, !17, i64 64}
!9 = !{!"_ZTSSt6vectorImSaImEE", !10, i64 0}
!10 = !{!"_ZTSSt12_Vector_baseImSaImEE", !11, i64 0}
!11 = !{!"_ZTSNSt12_Vector_baseImSaImEE12_Vector_implE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseImSaImEE17_Vector_impl_dataE", !13, i64 0, !13, i64 8, !13, i64 16}
!13 = !{!"any pointer", !14, i64 0}
!14 = !{!"omnipotent char", !15, i64 0}
!15 = !{!"Simple C++ TBAA"}
!16 = !{!"long", !14, i64 0}
!17 = !{!"_ZTS18SimdTensorDataType", !14, i64 0}
!18 = !{!"_ZTSN4Simd5ArrayIiEE", !13, i64 0, !16, i64 8}
!19 = !{!6, !13, i64 264}
!20 = !{!6, !16, i64 104}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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