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

; 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.0 }
%"struct.alglib_impl::ae_dyn_block" = type { ptr, ptr, ptr, ptr }
%union.anon.0 = type { ptr }

@.str.182 = external hidden unnamed_addr constant [52 x i8], align 1

; 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_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext, ptr noundef, ptr noundef) #1

declare noundef double @_ZN11alglib_impl7ae_fabsEdPNS_8ae_stateE(double noundef, ptr noundef) #1

declare noundef double @_ZN11alglib_impl10ae_maxrealEddPNS_8ae_stateE(double noundef, double noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl27unscaleandchecknlcviolationEPKNS_9ae_vectorES2_llPdPlPNS_8ae_stateE(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #2 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca double, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i64 %2, ptr %10, align 8, !tbaa !9
  store i64 %3, ptr %11, align 8, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  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
  %17 = load ptr, ptr %12, align 8, !tbaa !5
  store double 0.000000e+00, ptr %17, align 8, !tbaa !11
  %18 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 0, ptr %18, align 8, !tbaa !9
  %19 = load ptr, ptr %12, align 8, !tbaa !5
  store double 0.000000e+00, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 -1, ptr %20, align 8, !tbaa !9
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %75, %7
  %22 = load i64, ptr %15, align 8, !tbaa !9
  %23 = load i64, ptr %10, align 8, !tbaa !9
  %24 = load i64, ptr %11, align 8, !tbaa !9
  %25 = add nsw i64 %23, %24
  %26 = sub nsw i64 %25, 1
  %27 = icmp sle i64 %22, %26
  br i1 %27, label %28, label %78

28:                                               ; preds = %21
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %29, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = load i64, ptr %15, align 8, !tbaa !9
  %33 = add nsw i64 %32, 1
  %34 = getelementptr inbounds double, ptr %31, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = call noundef zeroext i1 @_ZN11alglib_impl13ae_fp_greaterEdd(double noundef %35, double noundef 0.000000e+00)
  %37 = load ptr, ptr %14, align 8, !tbaa !5
  call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %36, ptr noundef @.str.182, ptr noundef %37)
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %38, i32 0, i32 4
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = load i64, ptr %15, align 8, !tbaa !9
  %42 = add nsw i64 %41, 1
  %43 = getelementptr inbounds double, ptr %40, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = load i64, ptr %15, align 8, !tbaa !9
  %49 = add nsw i64 %48, 1
  %50 = getelementptr inbounds double, ptr %47, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !11
  %52 = fmul double %44, %51
  store double %52, ptr %16, align 8, !tbaa !11
  %53 = load i64, ptr %15, align 8, !tbaa !9
  %54 = load i64, ptr %10, align 8, !tbaa !9
  %55 = icmp slt i64 %53, %54
  br i1 %55, label %56, label %60

56:                                               ; preds = %28
  %57 = load double, ptr %16, align 8, !tbaa !11
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = call noundef double @_ZN11alglib_impl7ae_fabsEdPNS_8ae_stateE(double noundef %57, ptr noundef %58)
  store double %59, ptr %16, align 8, !tbaa !11
  br label %64

60:                                               ; preds = %28
  %61 = load double, ptr %16, align 8, !tbaa !11
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = call noundef double @_ZN11alglib_impl10ae_maxrealEddPNS_8ae_stateE(double noundef %61, double noundef 0.000000e+00, ptr noundef %62)
  store double %63, ptr %16, align 8, !tbaa !11
  br label %64

64:                                               ; preds = %60, %56
  %65 = load double, ptr %16, align 8, !tbaa !11
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = load double, ptr %66, align 8, !tbaa !11
  %68 = fcmp ogt double %65, %67
  br i1 %68, label %69, label %74

69:                                               ; preds = %64
  %70 = load double, ptr %16, align 8, !tbaa !11
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  store double %70, ptr %71, align 8, !tbaa !11
  %72 = load i64, ptr %15, align 8, !tbaa !9
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  store i64 %72, ptr %73, align 8, !tbaa !9
  br label %74

74:                                               ; preds = %69, %64
  br label %75

75:                                               ; preds = %74
  %76 = load i64, ptr %15, align 8, !tbaa !9
  %77 = add nsw i64 %76, 1
  store i64 %77, ptr %15, align 8, !tbaa !9
  br label %21, !llvm.loop !14

78:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  ret void
}

declare noundef zeroext i1 @_ZN11alglib_impl13ae_fp_greaterEdd(double noundef, double 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 = !{!"double", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@.str.182 = external hidden unnamed_addr constant [52 x i8], align 1

declare void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext, ptr noundef, ptr noundef) local_unnamed_addr #0

declare noundef double @_ZN11alglib_impl7ae_fabsEdPNS_8ae_stateE(double noundef, ptr noundef) local_unnamed_addr #0

declare noundef double @_ZN11alglib_impl10ae_maxrealEddPNS_8ae_stateE(double noundef, double noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl27unscaleandchecknlcviolationEPKNS_9ae_vectorES2_llPdPlPNS_8ae_stateE(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef %4, ptr nocapture noundef writeonly %5, ptr noundef %6) local_unnamed_addr #1 {
  store double 0.000000e+00, ptr %4, align 8, !tbaa !5
  store i64 -1, ptr %5, align 8, !tbaa !9
  %8 = add nsw i64 %3, %2
  %.not.not27 = icmp sgt i64 %8, 0
  br i1 %.not.not27, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %7
  %9 = getelementptr inbounds i8, ptr %1, i64 56
  %10 = getelementptr inbounds i8, ptr %0, i64 56
  br label %11

11:                                               ; preds = %.lr.ph, %33
  %.02628 = phi i64 [ 0, %.lr.ph ], [ %13, %33 ]
  %12 = load ptr, ptr %9, align 8, !tbaa !11
  %13 = add nuw nsw i64 %.02628, 1
  %14 = getelementptr inbounds double, ptr %12, i64 %13
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = tail call noundef zeroext i1 @_ZN11alglib_impl13ae_fp_greaterEdd(double noundef %15, double noundef 0.000000e+00)
  tail call void @_ZN11alglib_impl9ae_assertEbPKcPNS_8ae_stateE(i1 noundef zeroext %16, ptr noundef nonnull @.str.182, ptr noundef %6)
  %17 = load ptr, ptr %10, align 8, !tbaa !11
  %18 = getelementptr inbounds double, ptr %17, i64 %13
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = load ptr, ptr %9, align 8, !tbaa !11
  %21 = getelementptr inbounds double, ptr %20, i64 %13
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = fmul double %19, %22
  %24 = icmp slt i64 %.02628, %2
  br i1 %24, label %25, label %27

25:                                               ; preds = %11
  %26 = tail call noundef double @_ZN11alglib_impl7ae_fabsEdPNS_8ae_stateE(double noundef %23, ptr noundef %6)
  br label %29

27:                                               ; preds = %11
  %28 = tail call noundef double @_ZN11alglib_impl10ae_maxrealEddPNS_8ae_stateE(double noundef %23, double noundef 0.000000e+00, ptr noundef %6)
  br label %29

29:                                               ; preds = %27, %25
  %.0 = phi double [ %26, %25 ], [ %28, %27 ]
  %30 = load double, ptr %4, align 8, !tbaa !5
  %31 = fcmp ogt double %.0, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store double %.0, ptr %4, align 8, !tbaa !5
  store i64 %.02628, ptr %5, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %29, %32
  %exitcond.not = icmp eq i64 %13, %8
  br i1 %exitcond.not, label %._crit_edge, label %11, !llvm.loop !12

._crit_edge:                                      ; preds = %33, %7
  ret void
}

declare noundef zeroext i1 @_ZN11alglib_impl13ae_fp_greaterEdd(double noundef, double 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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