; LLVM IR from Dimandragon/non-parametric-dsp :: alglib-cpp/src (linalg)

; 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"

%"struct.alglib_impl::ae_vector" = type { i64, i64, i8, %"struct.alglib_impl::ae_dyn_block", %union.anon.1 }
%"struct.alglib_impl::ae_dyn_block" = type { ptr, ptr, ptr, ptr }
%union.anon.1 = type { ptr }

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

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

declare void @_ZN11alglib_impl23rvectorsetlengthatleastEPNS_9ae_vectorElPNS_8ae_stateE(ptr noundef, i64 noundef, ptr noundef) #1

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

21:                                               ; preds = %7
  store i32 1, ptr %17, align 4
  br label %63

22:                                               ; preds = %7
  %23 = load i8, ptr %13, align 1, !tbaa !11, !range !13, !noundef !14
  %24 = trunc i8 %23 to i1
  br i1 %24, label %25, label %29

25:                                               ; preds = %22
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = load ptr, ptr %14, align 8, !tbaa !5
  call void @_ZN11alglib_impl23rvectorsetlengthatleastEPNS_9ae_vectorElPNS_8ae_stateE(ptr noundef %26, i64 noundef %27, ptr noundef %28)
  br label %29

29:                                               ; preds = %25, %22
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %59, %29
  %31 = load i64, ptr %15, align 8, !tbaa !9
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = sub nsw i64 %32, 1
  %34 = icmp sle i64 %31, %33
  br i1 %34, label %35, label %62

35:                                               ; preds = %30
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load i64, ptr %15, align 8, !tbaa !9
  %40 = load ptr, ptr %14, align 8, !tbaa !5
  %41 = call noundef double @_ZN11alglib_impl6rdotvrElPKNS_9ae_vectorEPKNS_9ae_matrixElPNS_8ae_stateE(i64 noundef %36, ptr noundef %37, ptr noundef %38, i64 noundef %39, ptr noundef %40)
  store double %41, ptr %16, align 8, !tbaa !15
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = load double, ptr %16, align 8, !tbaa !15
  %44 = fneg double %43
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load i64, ptr %15, align 8, !tbaa !9
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = load ptr, ptr %14, align 8, !tbaa !5
  call void @_ZN11alglib_impl6raddrvEldPKNS_9ae_matrixElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %42, double noundef %44, ptr noundef %45, i64 noundef %46, ptr noundef %47, ptr noundef %48)
  %49 = load i8, ptr %13, align 1, !tbaa !11, !range !13, !noundef !14
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %58

51:                                               ; preds = %35
  %52 = load double, ptr %16, align 8, !tbaa !15
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !17
  %56 = load i64, ptr %15, align 8, !tbaa !9
  %57 = getelementptr inbounds double, ptr %55, i64 %56
  store double %52, ptr %57, align 8, !tbaa !15
  br label %58

58:                                               ; preds = %51, %35
  br label %59

59:                                               ; preds = %58
  %60 = load i64, ptr %15, align 8, !tbaa !9
  %61 = add nsw i64 %60, 1
  store i64 %61, ptr %15, align 8, !tbaa !9
  br label %30, !llvm.loop !18

62:                                               ; preds = %30
  store i32 0, ptr %17, align 4
  br label %63

63:                                               ; preds = %62, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  %64 = load i32, ptr %17, align 4
  switch i32 %64, label %66 [
    i32 0, label %65
    i32 1, label %65
  ]

65:                                               ; preds = %63, %63
  ret void

66:                                               ; preds = %63
  unreachable
}

declare noundef double @_ZN11alglib_impl6rdotvrElPKNS_9ae_vectorEPKNS_9ae_matrixElPNS_8ae_stateE(i64 noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) #1

declare void @_ZN11alglib_impl6raddrvEldPKNS_9ae_matrixElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef, double noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { mustprogress 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

declare void @_ZN11alglib_impl23rvectorsetlengthatleastEPNS_9ae_vectorElPNS_8ae_stateE(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl18rowwisegramschmidtEPKNS_9ae_matrixEllPNS_9ae_vectorES4_bPNS_8ae_stateE(ptr noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, i1 noundef zeroext %5, ptr noundef %6) local_unnamed_addr #1 {
  %8 = icmp eq i64 %1, 0
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %7
  br i1 %5, label %10, label %.thread

10:                                               ; preds = %9
  tail call void @_ZN11alglib_impl23rvectorsetlengthatleastEPNS_9ae_vectorElPNS_8ae_stateE(ptr noundef %4, i64 noundef %1, ptr noundef %6)
  %.not.not23 = icmp sgt i64 %1, 0
  br i1 %.not.not23, label %.lr.ph.split.us.preheader, label %.loopexit

.thread:                                          ; preds = %9
  %.not.not2327 = icmp sgt i64 %1, 0
  br i1 %.not.not2327, label %.lr.ph.split, label %.loopexit

.lr.ph.split.us.preheader:                        ; preds = %10
  %11 = getelementptr inbounds i8, ptr %4, i64 56
  br label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.preheader, %.lr.ph.split.us
  %.024.us = phi i64 [ %16, %.lr.ph.split.us ], [ 0, %.lr.ph.split.us.preheader ]
  %12 = tail call noundef double @_ZN11alglib_impl6rdotvrElPKNS_9ae_vectorEPKNS_9ae_matrixElPNS_8ae_stateE(i64 noundef %2, ptr noundef %3, ptr noundef %0, i64 noundef %.024.us, ptr noundef %6)
  %13 = fneg double %12
  tail call void @_ZN11alglib_impl6raddrvEldPKNS_9ae_matrixElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %2, double noundef %13, ptr noundef %0, i64 noundef %.024.us, ptr noundef %3, ptr noundef %6)
  %14 = load ptr, ptr %11, align 8, !tbaa !5
  %15 = getelementptr inbounds double, ptr %14, i64 %.024.us
  store double %12, ptr %15, align 8, !tbaa !8
  %16 = add nuw nsw i64 %.024.us, 1
  %exitcond26.not = icmp eq i64 %16, %1
  br i1 %exitcond26.not, label %.loopexit, label %.lr.ph.split.us, !llvm.loop !10

.lr.ph.split:                                     ; preds = %.thread, %.lr.ph.split
  %.024 = phi i64 [ %19, %.lr.ph.split ], [ 0, %.thread ]
  %17 = tail call noundef double @_ZN11alglib_impl6rdotvrElPKNS_9ae_vectorEPKNS_9ae_matrixElPNS_8ae_stateE(i64 noundef %2, ptr noundef %3, ptr noundef %0, i64 noundef %.024, ptr noundef %6)
  %18 = fneg double %17
  tail call void @_ZN11alglib_impl6raddrvEldPKNS_9ae_matrixElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef %2, double noundef %18, ptr noundef %0, i64 noundef %.024, ptr noundef %3, ptr noundef %6)
  %19 = add nuw nsw i64 %.024, 1
  %exitcond.not = icmp eq i64 %19, %1
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph.split, !llvm.loop !10

.loopexit:                                        ; preds = %.lr.ph.split, %.lr.ph.split.us, %.thread, %10, %7
  ret void
}

declare noundef double @_ZN11alglib_impl6rdotvrElPKNS_9ae_vectorEPKNS_9ae_matrixElPNS_8ae_stateE(i64 noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

declare void @_ZN11alglib_impl6raddrvEldPKNS_9ae_matrixElPNS_9ae_vectorEPNS_8ae_stateE(i64 noundef, double noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

attributes #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 = { mustprogress 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"double", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass