; LLVM IR from niessner/Matterport :: code/gaps/pkgs/RNBasics/RNSvd.ll (Z19clr_top_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_top_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 %9, align 4, !tbaa !9
  %22 = add 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 %10, align 4, !tbaa !9
  %26 = icmp sle 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 %9, align 4, !tbaa !9
  %31 = mul nsw i32 %29, %30
  %32 = load i32, ptr %15, 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 %9, align 4, !tbaa !9
  %66 = mul nsw i32 %64, %65
  %67 = load i32, ptr %15, 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 %10, align 4, !tbaa !9
  %82 = icmp ne i32 %80, %81
  br i1 %82, label %83, label %93

83:                                               ; preds = %49
  %84 = load i32, ptr %9, align 4, !tbaa !9
  %85 = load i32, ptr %15, 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 = add 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_rowsiiddPdiiii(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 %9, 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 %12, align 4, !tbaa !9
  %100 = load i32, ptr %12, align 4, !tbaa !9
  %101 = load i32, ptr %14, align 4, !tbaa !9
  call void @_Z11rotate_colsiiddPdiiii(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_top_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.not51 = icmp slt i32 %1, %2
  br i1 %.not.not51, label %.lr.ph, label %._crit_edge

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

11:                                               ; preds = %.lr.ph, %27
  %indvars.iv = phi i64 [ %9, %.lr.ph ], [ %indvars.iv.next, %27 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %indvars = trunc i64 %indvars.iv.next to i32
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv.next
  %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 = %11
  %15 = mul i32 %.049, %indvars
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds double, ptr %0, i64 %16
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = fmul double %18, %18
  %20 = tail call double @llvm.fmuladd.f64(double %12, double %12, double %19)
  %sqrt = tail call double @llvm.sqrt.f64(double %20)
  %21 = fdiv double %18, %sqrt
  %22 = fdiv double %12, %sqrt
  store double 0.000000e+00, ptr %gep, align 8, !tbaa !5
  store double %sqrt, ptr %17, align 8, !tbaa !5
  %23 = icmp eq i64 %indvars.iv.next, %sext
  br i1 %23, label %27, label %24

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

27:                                               ; preds = %24, %14
  tail call void @_Z11rotate_colsiiddPdiiii(i32 noundef %indvars, i32 noundef %1, double noundef %21, double noundef %22, ptr noundef %3, i32 noundef 0, i32 noundef %4, i32 noundef %4, i32 noundef %6)
  %exitcond.not = icmp eq i64 %indvars.iv.next, %sext
  br i1 %exitcond.not, label %._crit_edge, label %11, !llvm.loop !9

._crit_edge:                                      ; preds = %27, %11, %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,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass