; LLVM IR from niessner/Matterport :: code/gaps/pkgs/RNBasics/RNSvd.ll (Z18golub_kahn_svd_rotPdiiS_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: mustprogress nounwind uwtable
declare dso_local noundef double @_Z6fhypotdd(double noundef, 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) #0

; 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) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z18golub_kahn_svd_rotPdiiS_iii(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6) #0 {
  %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 double, align 8
  %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
  %21 = alloca double, align 8
  %22 = alloca double, align 8
  %23 = alloca double, align 8
  %24 = alloca double, align 8
  %25 = alloca double, align 8
  %26 = alloca double, align 8
  %27 = alloca double, align 8
  %28 = alloca double, align 8
  %29 = alloca double, align 8
  %30 = alloca double, align 8
  %31 = 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 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 8, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %28) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %29) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %30) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %31) #3
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = sub nsw i32 %32, 2
  %34 = icmp slt i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %7
  br label %48

36:                                               ; preds = %7
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = sub nsw i32 %39, 2
  %41 = mul nsw i32 %38, %40
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = sub nsw i32 %42, 1
  %44 = add nsw i32 %41, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %37, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %36, %35
  %49 = phi double [ 0.000000e+00, %35 ], [ %47, %36 ]
  store double %49, ptr %22, align 8, !tbaa !11
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = sub nsw i32 %52, 1
  %54 = mul nsw i32 %51, %53
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = sub nsw i32 %55, 1
  %57 = add nsw i32 %54, %56
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %50, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !11
  store double %60, ptr %21, align 8, !tbaa !11
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = load i32, ptr %13, align 4, !tbaa !9
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = sub nsw i32 %63, 1
  %65 = mul nsw i32 %62, %64
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = add nsw i32 %65, %66
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds double, ptr %61, i64 %68
  %70 = load double, ptr %69, align 8, !tbaa !11
  store double %70, ptr %24, align 8, !tbaa !11
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load i32, ptr %13, align 4, !tbaa !9
  %73 = load i32, ptr %10, align 4, !tbaa !9
  %74 = mul nsw i32 %72, %73
  %75 = load i32, ptr %10, align 4, !tbaa !9
  %76 = add nsw i32 %74, %75
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds double, ptr %71, i64 %77
  %79 = load double, ptr %78, align 8, !tbaa !11
  store double %79, ptr %23, align 8, !tbaa !11
  %80 = load double, ptr %21, align 8, !tbaa !11
  %81 = load double, ptr %21, align 8, !tbaa !11
  %82 = load double, ptr %22, align 8, !tbaa !11
  %83 = load double, ptr %22, align 8, !tbaa !11
  %84 = fmul double %82, %83
  %85 = call double @llvm.fmuladd.f64(double %80, double %81, double %84)
  store double %85, ptr %15, align 8, !tbaa !11
  %86 = load double, ptr %21, align 8, !tbaa !11
  %87 = load double, ptr %24, align 8, !tbaa !11
  %88 = fmul double %86, %87
  store double %88, ptr %16, align 8, !tbaa !11
  %89 = load double, ptr %23, align 8, !tbaa !11
  %90 = load double, ptr %23, align 8, !tbaa !11
  %91 = load double, ptr %24, align 8, !tbaa !11
  %92 = load double, ptr %24, align 8, !tbaa !11
  %93 = fmul double %91, %92
  %94 = call double @llvm.fmuladd.f64(double %89, double %90, double %93)
  store double %94, ptr %17, align 8, !tbaa !11
  %95 = load double, ptr %15, align 8, !tbaa !11
  %96 = load double, ptr %17, align 8, !tbaa !11
  %97 = fsub double %95, %96
  %98 = fmul double 5.000000e-01, %97
  store double %98, ptr %28, align 8, !tbaa !11
  %99 = load double, ptr %28, align 8, !tbaa !11
  %100 = load double, ptr %16, align 8, !tbaa !11
  %101 = call noundef double @_Z6fhypotdd(double noundef %99, double noundef %100)
  store double %101, ptr %29, align 8, !tbaa !11
  %102 = load double, ptr %17, align 8, !tbaa !11
  %103 = load double, ptr %28, align 8, !tbaa !11
  %104 = fadd double %102, %103
  %105 = load double, ptr %28, align 8, !tbaa !11
  %106 = fcmp ogt double %105, 0.000000e+00
  br i1 %106, label %107, label %110

107:                                              ; preds = %48
  %108 = load double, ptr %29, align 8, !tbaa !11
  %109 = fneg double %108
  br label %112

110:                                              ; preds = %48
  %111 = load double, ptr %29, align 8, !tbaa !11
  br label %112

112:                                              ; preds = %110, %107
  %113 = phi double [ %109, %107 ], [ %111, %110 ]
  %114 = fadd double %104, %113
  store double %114, ptr %18, align 8, !tbaa !11
  %115 = load ptr, ptr %8, align 8, !tbaa !5
  %116 = load i32, ptr %13, align 4, !tbaa !9
  %117 = load i32, ptr %9, align 4, !tbaa !9
  %118 = mul nsw i32 %116, %117
  %119 = load i32, ptr %9, align 4, !tbaa !9
  %120 = add nsw i32 %118, %119
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds double, ptr %115, i64 %121
  %123 = load double, ptr %122, align 8, !tbaa !11
  store double %123, ptr %19, align 8, !tbaa !11
  %124 = load ptr, ptr %8, align 8, !tbaa !5
  %125 = load i32, ptr %13, align 4, !tbaa !9
  %126 = load i32, ptr %9, align 4, !tbaa !9
  %127 = mul nsw i32 %125, %126
  %128 = load i32, ptr %9, align 4, !tbaa !9
  %129 = add nsw i32 %128, 1
  %130 = add nsw i32 %127, %129
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds double, ptr %124, i64 %131
  %133 = load double, ptr %132, align 8, !tbaa !11
  store double %133, ptr %20, align 8, !tbaa !11
  %134 = load double, ptr %19, align 8, !tbaa !11
  %135 = load double, ptr %19, align 8, !tbaa !11
  %136 = fmul double %134, %135
  store double %136, ptr %15, align 8, !tbaa !11
  %137 = load double, ptr %19, align 8, !tbaa !11
  %138 = load double, ptr %20, align 8, !tbaa !11
  %139 = fmul double %137, %138
  store double %139, ptr %16, align 8, !tbaa !11
  %140 = load double, ptr %15, align 8, !tbaa !11
  %141 = load double, ptr %18, align 8, !tbaa !11
  %142 = fsub double %140, %141
  store double %142, ptr %30, align 8, !tbaa !11
  %143 = load double, ptr %16, align 8, !tbaa !11
  store double %143, ptr %31, align 8, !tbaa !11
  %144 = load double, ptr %30, align 8, !tbaa !11
  %145 = load double, ptr %31, align 8, !tbaa !11
  %146 = call noundef double @_Z6fhypotdd(double noundef %144, double noundef %145)
  store double %146, ptr %25, align 8, !tbaa !11
  %147 = load double, ptr %30, align 8, !tbaa !11
  %148 = load double, ptr %25, align 8, !tbaa !11
  %149 = fdiv double %147, %148
  store double %149, ptr %26, align 8, !tbaa !11
  %150 = load double, ptr %31, align 8, !tbaa !11
  %151 = load double, ptr %25, align 8, !tbaa !11
  %152 = fdiv double %150, %151
  store double %152, ptr %27, align 8, !tbaa !11
  %153 = load i32, ptr %9, align 4, !tbaa !9
  %154 = load i32, ptr %9, align 4, !tbaa !9
  %155 = add nsw i32 %154, 1
  %156 = load double, ptr %26, align 8, !tbaa !11
  %157 = load double, ptr %27, align 8, !tbaa !11
  %158 = load ptr, ptr %8, align 8, !tbaa !5
  %159 = load i32, ptr %9, align 4, !tbaa !9
  %160 = load i32, ptr %12, align 4, !tbaa !9
  %161 = load i32, ptr %13, align 4, !tbaa !9
  call void @_Z11rotate_colsiiddPdiiii(i32 noundef %153, i32 noundef %155, double noundef %156, double noundef %157, ptr noundef %158, i32 noundef %159, i32 noundef 2, i32 noundef %160, i32 noundef %161)
  %162 = load i32, ptr %9, align 4, !tbaa !9
  %163 = load i32, ptr %9, align 4, !tbaa !9
  %164 = add nsw i32 %163, 1
  %165 = load double, ptr %26, align 8, !tbaa !11
  %166 = load double, ptr %27, align 8, !tbaa !11
  %167 = load ptr, ptr %11, align 8, !tbaa !5
  %168 = load i32, ptr %13, align 4, !tbaa !9
  %169 = load i32, ptr %14, align 4, !tbaa !9
  %170 = load i32, ptr %13, align 4, !tbaa !9
  call void @_Z11rotate_rowsiiddPdiiii(i32 noundef %162, i32 noundef %164, double noundef %165, double noundef %166, ptr noundef %167, i32 noundef 0, i32 noundef %168, i32 noundef %169, i32 noundef %170)
  call void @llvm.lifetime.end.p0(i64 8, ptr %31) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %30) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %29) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %28) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  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 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  ret void
}

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 speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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}


; 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 nounwind uwtable
declare dso_local noundef double @_Z6fhypotdd(double noundef, double noundef) local_unnamed_addr #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 #0

; 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 #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z18golub_kahn_svd_rotPdiiS_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 #0 {
  %8 = icmp slt i32 %2, 2
  br i1 %8, label %._crit_edge, label %9

._crit_edge:                                      ; preds = %7
  %.pre = add nsw i32 %2, -1
  br label %17

9:                                                ; preds = %7
  %10 = add nsw i32 %2, -2
  %11 = mul nsw i32 %10, %5
  %12 = add nsw i32 %2, -1
  %13 = add nsw i32 %12, %11
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds double, ptr %0, i64 %14
  %16 = load double, ptr %15, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %._crit_edge, %9
  %.pre-phi = phi i32 [ %.pre, %._crit_edge ], [ %12, %9 ]
  %18 = phi double [ 0.000000e+00, %._crit_edge ], [ %16, %9 ]
  %19 = mul nsw i32 %.pre-phi, %5
  %20 = add nsw i32 %19, %.pre-phi
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds double, ptr %0, i64 %21
  %23 = load double, ptr %22, align 8, !tbaa !5
  %24 = add nsw i32 %19, %2
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %0, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = add i32 %5, 1
  %29 = mul i32 %28, %2
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %0, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = fmul double %23, %27
  %34 = insertelement <2 x double> poison, double %18, i64 0
  %35 = insertelement <2 x double> %34, double %27, i64 1
  %36 = fmul <2 x double> %35, %35
  %37 = insertelement <2 x double> poison, double %23, i64 0
  %38 = insertelement <2 x double> %37, double %32, i64 1
  %39 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %38, <2 x double> %38, <2 x double> %36)
  %40 = extractelement <2 x double> %39, i64 0
  %41 = extractelement <2 x double> %39, i64 1
  %42 = fsub double %40, %41
  %43 = fmul double %42, 5.000000e-01
  %44 = tail call noundef double @_Z6fhypotdd(double noundef %43, double noundef %33)
  %45 = fadd double %41, %43
  %46 = fcmp ogt double %43, 0.000000e+00
  %47 = fneg double %44
  %48 = select i1 %46, double %47, double %44
  %49 = fadd double %45, %48
  %50 = mul nsw i32 %5, %1
  %51 = add nsw i32 %50, %1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %0, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !5
  %55 = add nsw i32 %1, 1
  %56 = add nsw i32 %50, %55
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds double, ptr %0, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !5
  %60 = fmul double %54, %54
  %61 = fmul double %54, %59
  %62 = fsub double %60, %49
  %63 = tail call noundef double @_Z6fhypotdd(double noundef %62, double noundef %61)
  %64 = fdiv double %62, %63
  %65 = fdiv double %61, %63
  tail call void @_Z11rotate_colsiiddPdiiii(i32 noundef %1, i32 noundef %55, double noundef %64, double noundef %65, ptr noundef %0, i32 noundef %1, i32 noundef 2, i32 noundef %4, i32 noundef %5)
  tail call void @_Z11rotate_rowsiiddPdiiii(i32 noundef %1, i32 noundef %55, double noundef %64, double noundef %65, ptr noundef %3, i32 noundef 0, i32 noundef %5, i32 noundef %6, i32 noundef %5)
  ret void
}

; 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>) #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 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass