; LLVM IR from niessner/Matterport :: code/gaps/pkgs/RNBasics/RNSvd.ll (Z11rotate_colsiiddPdiiii)

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; 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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z11rotate_colsiiddPdiiii(i32 noundef %0, i32 noundef %1, double noundef %2, double noundef %3, ptr noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8) #2 {
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca double, align 8
  %22 = alloca double, align 8
  store i32 %0, ptr %10, align 4, !tbaa !5
  store i32 %1, ptr %11, align 4, !tbaa !5
  store double %2, ptr %12, align 8, !tbaa !9
  store double %3, ptr %13, align 8, !tbaa !9
  store ptr %4, ptr %14, align 8, !tbaa !11
  store i32 %5, ptr %15, align 4, !tbaa !5
  store i32 %6, ptr %16, align 4, !tbaa !5
  store i32 %7, ptr %17, align 4, !tbaa !5
  store i32 %8, ptr %18, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %23 = load i32, ptr %15, align 4, !tbaa !5
  %24 = load i32, ptr %16, align 4, !tbaa !5
  %25 = add nsw i32 %23, %24
  store i32 %25, ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #3
  %26 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %26, ptr %20, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %79, %9
  %28 = load i32, ptr %20, align 4, !tbaa !5
  %29 = load i32, ptr %19, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %82

31:                                               ; preds = %27
  %32 = load ptr, ptr %14, align 8, !tbaa !11
  %33 = load i32, ptr %18, align 4, !tbaa !5
  %34 = load i32, ptr %20, align 4, !tbaa !5
  %35 = mul nsw i32 %33, %34
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %32, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !9
  store double %40, ptr %21, align 8, !tbaa !9
  %41 = load ptr, ptr %14, align 8, !tbaa !11
  %42 = load i32, ptr %18, align 4, !tbaa !5
  %43 = load i32, ptr %20, align 4, !tbaa !5
  %44 = mul nsw i32 %42, %43
  %45 = load i32, ptr %11, align 4, !tbaa !5
  %46 = add nsw i32 %44, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %41, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !9
  store double %49, ptr %22, align 8, !tbaa !9
  %50 = load double, ptr %12, align 8, !tbaa !9
  %51 = load double, ptr %21, align 8, !tbaa !9
  %52 = load double, ptr %13, align 8, !tbaa !9
  %53 = load double, ptr %22, align 8, !tbaa !9
  %54 = fmul double %52, %53
  %55 = call double @llvm.fmuladd.f64(double %50, double %51, double %54)
  %56 = load ptr, ptr %14, align 8, !tbaa !11
  %57 = load i32, ptr %18, align 4, !tbaa !5
  %58 = load i32, ptr %20, align 4, !tbaa !5
  %59 = mul nsw i32 %57, %58
  %60 = load i32, ptr %10, align 4, !tbaa !5
  %61 = add nsw i32 %59, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %56, i64 %62
  store double %55, ptr %63, align 8, !tbaa !9
  %64 = load double, ptr %13, align 8, !tbaa !9
  %65 = fneg double %64
  %66 = load double, ptr %21, align 8, !tbaa !9
  %67 = load double, ptr %12, align 8, !tbaa !9
  %68 = load double, ptr %22, align 8, !tbaa !9
  %69 = fmul double %67, %68
  %70 = call double @llvm.fmuladd.f64(double %65, double %66, double %69)
  %71 = load ptr, ptr %14, align 8, !tbaa !11
  %72 = load i32, ptr %18, align 4, !tbaa !5
  %73 = load i32, ptr %20, align 4, !tbaa !5
  %74 = mul nsw i32 %72, %73
  %75 = load i32, ptr %11, align 4, !tbaa !5
  %76 = add nsw i32 %74, %75
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds double, ptr %71, i64 %77
  store double %70, ptr %78, align 8, !tbaa !9
  br label %79

79:                                               ; preds = %31
  %80 = load i32, ptr %20, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %20, align 4, !tbaa !5
  br label %27, !llvm.loop !13

82:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z11rotate_colsiiddPdiiii(i32 noundef %0, i32 noundef %1, double noundef %2, double noundef %3, ptr nocapture noundef %4, i32 noundef %5, i32 noundef %6, i32 noundef %7, i32 noundef %8) local_unnamed_addr #1 {
  %10 = icmp sgt i32 %6, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9
  %11 = add nsw i32 %6, %5
  %12 = fneg double %3
  %13 = sext i32 %5 to i64
  %14 = sext i32 %8 to i64
  %15 = sext i32 %0 to i64
  %16 = sext i32 %1 to i64
  %17 = sext i32 %11 to i64
  %invariant.gep = getelementptr double, ptr %4, i64 %15
  %invariant.gep31 = getelementptr double, ptr %4, i64 %16
  %18 = add nsw i64 %13, 1
  %smax36 = tail call i64 @llvm.smax.i64(i64 %18, i64 %17)
  %19 = sub i64 %smax36, %13
  %min.iters.check = icmp ugt i64 %19, 9
  %ident.check.not = icmp eq i32 %8, 1
  %or.cond = and i1 %min.iters.check, %ident.check.not
  br i1 %or.cond, label %vector.memcheck, label %scalar.ph.preheader

vector.memcheck:                                  ; preds = %.lr.ph
  %20 = add nsw i64 %15, %13
  %21 = shl nsw i64 %20, 3
  %scevgep = getelementptr i8, ptr %4, i64 %21
  %22 = add nsw i64 %13, 1
  %smax = tail call i64 @llvm.smax.i64(i64 %22, i64 %17)
  %23 = add i64 %smax, %15
  %24 = shl nsw i64 %23, 3
  %scevgep33 = getelementptr i8, ptr %4, i64 %24
  %25 = add nsw i64 %16, %13
  %26 = shl nsw i64 %25, 3
  %scevgep34 = getelementptr i8, ptr %4, i64 %26
  %27 = add i64 %smax, %16
  %28 = shl nsw i64 %27, 3
  %scevgep35 = getelementptr i8, ptr %4, i64 %28
  %bound0 = icmp ult ptr %scevgep, %scevgep35
  %bound1 = icmp ult ptr %scevgep34, %scevgep33
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %19, -2
  %ind.end = add i64 %n.vec, %13
  %broadcast.splatinsert = insertelement <2 x double> poison, double %3, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert38 = insertelement <2 x double> poison, double %2, i64 0
  %broadcast.splat39 = shufflevector <2 x double> %broadcast.splatinsert38, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert40 = insertelement <2 x double> poison, double %12, i64 0
  %broadcast.splat41 = shufflevector <2 x double> %broadcast.splatinsert40, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = add i64 %index, %13
  %29 = getelementptr double, ptr %invariant.gep, i64 %offset.idx
  %wide.load = load <2 x double>, ptr %29, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  %30 = getelementptr double, ptr %invariant.gep31, i64 %offset.idx
  %wide.load37 = load <2 x double>, ptr %30, align 8, !tbaa !5, !alias.scope !12
  %31 = fmul <2 x double> %wide.load37, %broadcast.splat
  %32 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat39, <2 x double> %wide.load, <2 x double> %31)
  store <2 x double> %32, ptr %29, align 8, !tbaa !5, !alias.scope !9, !noalias !12
  %33 = fmul <2 x double> %wide.load37, %broadcast.splat39
  %34 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat41, <2 x double> %wide.load, <2 x double> %33)
  store <2 x double> %34, ptr %30, align 8, !tbaa !5, !alias.scope !12
  %index.next = add nuw i64 %index, 2
  %35 = icmp eq i64 %index.next, %n.vec
  br i1 %35, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %19, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ %13, %vector.memcheck ], [ %13, %.lr.ph ], [ %ind.end, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %36 = mul nsw i64 %indvars.iv, %14
  %gep = getelementptr double, ptr %invariant.gep, i64 %36
  %37 = load double, ptr %gep, align 8, !tbaa !5
  %gep32 = getelementptr double, ptr %invariant.gep31, i64 %36
  %38 = load double, ptr %gep32, align 8, !tbaa !5
  %39 = fmul double %38, %3
  %40 = tail call double @llvm.fmuladd.f64(double %2, double %37, double %39)
  store double %40, ptr %gep, align 8, !tbaa !5
  %41 = fmul double %38, %2
  %42 = tail call double @llvm.fmuladd.f64(double %12, double %37, double %41)
  store double %42, ptr %gep32, align 8, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %43 = icmp slt i64 %indvars.iv.next, %17
  br i1 %43, label %scalar.ph, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %9
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !16}


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