; LLVM IR from sp-nitech/SPTK :: third_party/WORLD/matlabfunctions.ll (ZN4sptk5world8fftshiftEPKdiPd)

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

8:                                                ; preds = %39, %3
  %9 = load i32, ptr %7, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = sdiv i32 %10, 2
  %12 = icmp slt i32 %9, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %8
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = sdiv i32 %17, 2
  %19 = add nsw i32 %16, %18
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %15, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %23, i64 %25
  store double %22, ptr %26, align 8, !tbaa !11
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %27, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !11
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = sdiv i32 %34, 2
  %36 = add nsw i32 %33, %35
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %32, i64 %37
  store double %31, ptr %38, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %14
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %7, align 4, !tbaa !9
  br label %8, !llvm.loop !13

42:                                               ; preds = %13
  ret void
}

; 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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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(argmem: readwrite) uwtable
define dso_local void @_ZN4sptk5world8fftshiftEPKdiPd(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = ptrtoint ptr %0 to i64
  %5 = ptrtoint ptr %2 to i64
  %6 = icmp sgt i32 %1, 1
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %7 = lshr i32 %1, 1
  %8 = zext nneg i32 %7 to i64
  %min.iters.check = icmp ult i32 %1, 40
  br i1 %min.iters.check, label %.lr.ph.preheader23, label %vector.memcheck

.lr.ph.preheader23:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %8, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader23
  %9 = add nuw nsw i64 %indvars.iv.ph, %8
  %10 = getelementptr inbounds double, ptr %0, i64 %9
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.ph
  store double %11, ptr %12, align 8, !tbaa !5
  %13 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.ph
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds double, ptr %2, i64 %9
  store double %14, ptr %15, align 8, !tbaa !5
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader23
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader23 ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %16 = add nsw i64 %8, -1
  %17 = icmp eq i64 %indvars.iv.ph, %16
  br i1 %17, label %._crit_edge, label %.lr.ph

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %18 = shl nuw nsw i64 %8, 3
  %19 = add i64 %18, %5
  %20 = sub i64 %19, %4
  %diff.check = icmp ult i64 %20, 32
  %21 = sub i64 %5, %4
  %diff.check15 = icmp ult i64 %21, 32
  %conflict.rdx = or i1 %diff.check, %diff.check15
  %22 = sub i64 %4, %5
  %diff.check16 = icmp ult i64 %22, 32
  %conflict.rdx17 = or i1 %conflict.rdx, %diff.check16
  %23 = sub i64 %21, %18
  %diff.check18 = icmp ult i64 %23, 32
  %conflict.rdx19 = or i1 %conflict.rdx17, %diff.check18
  br i1 %conflict.rdx19, label %.lr.ph.preheader23, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %8, 1073741820
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %24 = add nuw nsw i64 %index, %8
  %25 = getelementptr inbounds double, ptr %0, i64 %24
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %wide.load = load <2 x double>, ptr %25, align 8, !tbaa !5
  %wide.load20 = load <2 x double>, ptr %26, align 8, !tbaa !5
  %27 = getelementptr inbounds double, ptr %2, i64 %index
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  store <2 x double> %wide.load, ptr %27, align 8, !tbaa !5
  store <2 x double> %wide.load20, ptr %28, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %0, i64 %index
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  %wide.load21 = load <2 x double>, ptr %29, align 8, !tbaa !5
  %wide.load22 = load <2 x double>, ptr %30, align 8, !tbaa !5
  %31 = getelementptr inbounds double, ptr %2, i64 %24
  %32 = getelementptr inbounds i8, ptr %31, i64 16
  store <2 x double> %wide.load21, ptr %31, align 8, !tbaa !5
  store <2 x double> %wide.load22, ptr %32, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %33 = icmp eq i64 %index.next, %n.vec
  br i1 %33, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %8
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader23

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %3
  ret void

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %34 = add nuw nsw i64 %indvars.iv, %8
  %35 = getelementptr inbounds double, ptr %0, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  store double %36, ptr %37, align 8, !tbaa !5
  %38 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %39 = load double, ptr %38, align 8, !tbaa !5
  %40 = getelementptr inbounds double, ptr %2, i64 %34
  store double %39, ptr %40, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %41 = add nuw nsw i64 %indvars.iv.next, %8
  %42 = getelementptr inbounds double, ptr %0, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next
  store double %43, ptr %44, align 8, !tbaa !5
  %45 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %46 = load double, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds double, ptr %2, i64 %41
  store double %46, ptr %47, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %8
  br i1 %exitcond.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !13
}

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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !11}


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