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

; 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: nounwind
declare double @sqrt(double noundef) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11rotate_colsiiddPdiiii(i32 noundef, i32 noundef, double noundef, double noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11rotate_rowsiiddPdiiii(i32 noundef, i32 noundef, double noundef, double noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #3

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

23:                                               ; preds = %102, %7
  %24 = load i32, ptr %15, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp sge i32 %24, %25
  br i1 %26, label %27, label %105

27:                                               ; preds = %23
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load i32, ptr %13, align 4, !tbaa !9
  %30 = load i32, ptr %15, align 4, !tbaa !9
  %31 = mul nsw i32 %29, %30
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = add nsw i32 %31, %32
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds double, ptr %28, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !11
  store double %36, ptr %16, align 8, !tbaa !11
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = load i32, ptr %15, align 4, !tbaa !9
  %40 = mul nsw i32 %38, %39
  %41 = load i32, ptr %15, align 4, !tbaa !9
  %42 = add nsw i32 %40, %41
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds double, ptr %37, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !11
  store double %45, ptr %17, align 8, !tbaa !11
  %46 = load double, ptr %16, align 8, !tbaa !11
  %47 = fcmp oeq double %46, 0.000000e+00
  br i1 %47, label %48, label %49

48:                                               ; preds = %27
  br label %105

49:                                               ; preds = %27
  %50 = load double, ptr %16, align 8, !tbaa !11
  %51 = load double, ptr %16, align 8, !tbaa !11
  %52 = load double, ptr %17, align 8, !tbaa !11
  %53 = load double, ptr %17, align 8, !tbaa !11
  %54 = fmul double %52, %53
  %55 = call double @llvm.fmuladd.f64(double %50, double %51, double %54)
  %56 = call double @sqrt(double noundef %55) #4
  store double %56, ptr %18, align 8, !tbaa !11
  %57 = load double, ptr %17, align 8, !tbaa !11
  %58 = load double, ptr %18, align 8, !tbaa !11
  %59 = fdiv double %57, %58
  store double %59, ptr %19, align 8, !tbaa !11
  %60 = load double, ptr %16, align 8, !tbaa !11
  %61 = load double, ptr %18, align 8, !tbaa !11
  %62 = fdiv double %60, %61
  store double %62, ptr %20, align 8, !tbaa !11
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load i32, ptr %13, align 4, !tbaa !9
  %65 = load i32, ptr %15, align 4, !tbaa !9
  %66 = mul nsw i32 %64, %65
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = add nsw i32 %66, %67
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds double, ptr %63, i64 %69
  store double 0.000000e+00, ptr %70, align 8, !tbaa !11
  %71 = load double, ptr %18, align 8, !tbaa !11
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = load i32, ptr %13, align 4, !tbaa !9
  %74 = load i32, ptr %15, align 4, !tbaa !9
  %75 = mul nsw i32 %73, %74
  %76 = load i32, ptr %15, align 4, !tbaa !9
  %77 = add nsw i32 %75, %76
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds double, ptr %72, i64 %78
  store double %71, ptr %79, align 8, !tbaa !11
  %80 = load i32, ptr %15, align 4, !tbaa !9
  %81 = load i32, ptr %9, align 4, !tbaa !9
  %82 = icmp ne i32 %80, %81
  br i1 %82, label %83, label %93

83:                                               ; preds = %49
  %84 = load i32, ptr %15, align 4, !tbaa !9
  %85 = load i32, ptr %10, align 4, !tbaa !9
  %86 = load double, ptr %19, align 8, !tbaa !11
  %87 = load double, ptr %20, align 8, !tbaa !11
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = load i32, ptr %15, align 4, !tbaa !9
  %90 = sub nsw i32 %89, 1
  %91 = load i32, ptr %12, align 4, !tbaa !9
  %92 = load i32, ptr %13, align 4, !tbaa !9
  call void @_Z11rotate_colsiiddPdiiii(i32 noundef %84, i32 noundef %85, double noundef %86, double noundef %87, ptr noundef %88, i32 noundef %90, i32 noundef 1, i32 noundef %91, i32 noundef %92)
  br label %93

93:                                               ; preds = %83, %49
  %94 = load i32, ptr %15, align 4, !tbaa !9
  %95 = load i32, ptr %10, align 4, !tbaa !9
  %96 = load double, ptr %19, align 8, !tbaa !11
  %97 = load double, ptr %20, align 8, !tbaa !11
  %98 = load ptr, ptr %11, align 8, !tbaa !5
  %99 = load i32, ptr %13, align 4, !tbaa !9
  %100 = load i32, ptr %14, align 4, !tbaa !9
  %101 = load i32, ptr %13, align 4, !tbaa !9
  call void @_Z11rotate_rowsiiddPdiiii(i32 noundef %94, i32 noundef %95, double noundef %96, double noundef %97, ptr noundef %98, i32 noundef 0, i32 noundef %99, i32 noundef %100, i32 noundef %101)
  br label %102

102:                                              ; preds = %93
  %103 = load i32, ptr %15, align 4, !tbaa !9
  %104 = add nsw i32 %103, -1
  store i32 %104, ptr %15, align 4, !tbaa !9
  br label %23, !llvm.loop !13

105:                                              ; preds = %48, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  ret void
}

attributes #0 = { nounwind "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 speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11rotate_colsiiddPdiiii(i32 noundef, i32 noundef, double noundef, double noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z11rotate_rowsiiddPdiiii(i32 noundef, i32 noundef, double noundef, double noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z19clr_bot_supdiag_eltPdiiS_iii(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #1 {
  %.not.not50 = icmp sgt i32 %2, %1
  br i1 %.not.not50, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %7
  %8 = sext i32 %2 to i64
  %9 = sext i32 %1 to i64
  %10 = sext i32 %5 to i64
  %invariant.gep = getelementptr double, ptr %0, i64 %8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %28
  %indvars.iv = phi i64 [ %8, %.lr.ph.preheader ], [ %indvars.iv.next, %28 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %indvars = trunc i64 %indvars.iv.next to i32
  %11 = mul nsw i64 %indvars.iv.next, %10
  %gep = getelementptr double, ptr %invariant.gep, i64 %11
  %12 = load double, ptr %gep, align 8, !tbaa !5
  %13 = fcmp oeq double %12, 0.000000e+00
  br i1 %13, label %._crit_edge, label %14

14:                                               ; preds = %.lr.ph
  %15 = mul nsw i32 %indvars, %5
  %16 = sext i32 %15 to i64
  %17 = getelementptr double, ptr %0, i64 %indvars.iv.next
  %18 = getelementptr double, ptr %17, i64 %16
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = fmul double %19, %19
  %21 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %20)
  %sqrt = tail call double @llvm.sqrt.f64(double %21)
  %22 = fdiv double %19, %sqrt
  %23 = fdiv double %12, %sqrt
  store double 0.000000e+00, ptr %gep, align 8, !tbaa !5
  store double %sqrt, ptr %18, align 8, !tbaa !5
  %24 = icmp eq i64 %indvars.iv.next, %9
  br i1 %24, label %28, label %25

25:                                               ; preds = %14
  %26 = trunc i64 %indvars.iv to i32
  %27 = add i32 %26, -2
  tail call void @_Z11rotate_colsiiddPdiiii(i32 noundef %indvars, i32 noundef %2, double noundef %22, double noundef %23, ptr noundef nonnull %0, i32 noundef %27, i32 noundef 1, i32 noundef %4, i32 noundef %5)
  br label %28

28:                                               ; preds = %25, %14
  tail call void @_Z11rotate_rowsiiddPdiiii(i32 noundef %indvars, i32 noundef %2, double noundef %22, double noundef %23, ptr noundef %3, i32 noundef 0, i32 noundef %5, i32 noundef %6, i32 noundef %5)
  %.not.not = icmp sgt i64 %indvars.iv.next, %9
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %28, %.lr.ph, %7
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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