; LLVM IR from venumb/ZSPACE :: cpp/depends/alglib/cpp/src (alglibinternal)

; 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::mlpbuffers" = type { i64, i64, i64, i64, i64, %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_matrix", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector", double, %"struct.alglib_impl::ae_vector", %"struct.alglib_impl::ae_vector" }
%"struct.alglib_impl::ae_matrix" = type { i64, i64, 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 }
%"struct.alglib_impl::ae_vector" = type { i64, i64, i8, %"struct.alglib_impl::ae_dyn_block", %union.anon }
%union.anon = 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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl26hpcfinalizechunkedgradientEPNS_10mlpbuffersEPNS_9ae_vectorEPNS_8ae_stateE(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %"struct.alglib_impl::mlpbuffers", ptr %8, i32 0, i32 6
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.alglib_impl::mlpbuffers", ptr %10, i32 0, i32 4
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call noundef zeroext i1 @_ZN11alglib_implL36hpccores_hpcfinalizechunkedgradientxEPNS_9ae_vectorElS1_PNS_8ae_stateE(ptr noundef %9, i64 noundef %12, ptr noundef %13, ptr noundef %14)
  br i1 %15, label %48, label %16

16:                                               ; preds = %3
  store i64 0, ptr %7, align 8, !tbaa !17
  br label %17

17:                                               ; preds = %44, %16
  %18 = load i64, ptr %7, align 8, !tbaa !17
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.alglib_impl::mlpbuffers", ptr %19, i32 0, i32 4
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = sub nsw i64 %21, 1
  %23 = icmp sle i64 %18, %22
  br i1 %23, label %24, label %47

24:                                               ; preds = %17
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %25, i32 0, i32 4
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  %28 = load i64, ptr %7, align 8, !tbaa !17
  %29 = getelementptr inbounds double, ptr %27, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !19
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.alglib_impl::mlpbuffers", ptr %31, i32 0, i32 6
  %33 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %32, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  %35 = load i64, ptr %7, align 8, !tbaa !17
  %36 = getelementptr inbounds double, ptr %34, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !19
  %38 = fadd double %30, %37
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.alglib_impl::ae_vector", ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  %42 = load i64, ptr %7, align 8, !tbaa !17
  %43 = getelementptr inbounds double, ptr %41, i64 %42
  store double %38, ptr %43, align 8, !tbaa !19
  br label %44

44:                                               ; preds = %24
  %45 = load i64, ptr %7, align 8, !tbaa !17
  %46 = add nsw i64 %45, 1
  store i64 %46, ptr %7, align 8, !tbaa !17
  br label %17, !llvm.loop !20

47:                                               ; preds = %17
  br label %48

48:                                               ; preds = %47, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN11alglib_implL36hpccores_hpcfinalizechunkedgradientxEPNS_9ae_vectorElS1_PNS_8ae_stateE(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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, !11, i64 32}
!10 = !{!"_ZTSN11alglib_impl10mlpbuffersE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !12, i64 40, !12, i64 104, !15, i64 168, !15, i64 248, !12, i64 328, !12, i64 392, !12, i64 456, !12, i64 520, !16, i64 584, !12, i64 592, !12, i64 656}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTSN11alglib_impl9ae_vectorE", !11, i64 0, !11, i64 8, !13, i64 16, !14, i64 24, !7, i64 56}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"_ZTSN11alglib_impl9ae_matrixE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !13, i64 32, !14, i64 40, !7, i64 72}
!16 = !{!"double", !7, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!7, !7, i64 0}
!19 = !{!16, !16, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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 nounwind uwtable
define dso_local void @_ZN11alglib_impl26hpcfinalizechunkedgradientEPNS_10mlpbuffersEPNS_9ae_vectorEPNS_8ae_stateE(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 104
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = tail call noundef zeroext i1 @_ZN11alglib_implL36hpccores_hpcfinalizechunkedgradientxEPNS_9ae_vectorElS1_PNS_8ae_stateE(ptr noundef nonnull %4, i64 noundef %6, ptr noundef %1, ptr noundef %2)
  br i1 %7, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %3
  %8 = load i64, ptr %5, align 8, !tbaa !5
  %.not.not12 = icmp sgt i64 %8, 0
  br i1 %.not.not12, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %1, i64 56
  %10 = getelementptr inbounds i8, ptr %0, i64 160
  %xtraiter = and i64 %8, 1
  %11 = icmp eq i64 %8, 1
  br i1 %11, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %8, 9223372036854775806
  br label %12

12:                                               ; preds = %12, %.lr.ph.new
  %.013 = phi i64 [ 0, %.lr.ph.new ], [ %28, %12 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %12 ]
  %13 = load ptr, ptr %9, align 8, !tbaa !16
  %14 = getelementptr inbounds double, ptr %13, i64 %.013
  %15 = load double, ptr %14, align 8, !tbaa !17
  %16 = load ptr, ptr %10, align 8, !tbaa !16
  %17 = getelementptr inbounds double, ptr %16, i64 %.013
  %18 = load double, ptr %17, align 8, !tbaa !17
  %19 = fadd double %15, %18
  store double %19, ptr %14, align 8, !tbaa !17
  %20 = or disjoint i64 %.013, 1
  %21 = load ptr, ptr %9, align 8, !tbaa !16
  %22 = getelementptr inbounds double, ptr %21, i64 %20
  %23 = load double, ptr %22, align 8, !tbaa !17
  %24 = load ptr, ptr %10, align 8, !tbaa !16
  %25 = getelementptr inbounds double, ptr %24, i64 %20
  %26 = load double, ptr %25, align 8, !tbaa !17
  %27 = fadd double %23, %26
  store double %27, ptr %22, align 8, !tbaa !17
  %28 = add nuw nsw i64 %.013, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %12, !llvm.loop !18

.loopexit.loopexit.unr-lcssa:                     ; preds = %12, %.lr.ph
  %.013.unr = phi i64 [ 0, %.lr.ph ], [ %28, %12 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %29 = load ptr, ptr %9, align 8, !tbaa !16
  %30 = getelementptr inbounds double, ptr %29, i64 %.013.unr
  %31 = load double, ptr %30, align 8, !tbaa !17
  %32 = load ptr, ptr %10, align 8, !tbaa !16
  %33 = getelementptr inbounds double, ptr %32, i64 %.013.unr
  %34 = load double, ptr %33, align 8, !tbaa !17
  %35 = fadd double %31, %34
  store double %35, ptr %30, align 8, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %.preheader, %3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN11alglib_implL36hpccores_hpcfinalizechunkedgradientxEPNS_9ae_vectorElS1_PNS_8ae_stateE(ptr noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

!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, !7, i64 32}
!6 = !{!"_ZTSN11alglib_impl10mlpbuffersE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 104, !14, i64 168, !14, i64 248, !10, i64 328, !10, i64 392, !10, i64 456, !10, i64 520, !15, i64 584, !10, i64 592, !10, i64 656}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN11alglib_impl9ae_vectorE", !7, i64 0, !7, i64 8, !11, i64 16, !12, i64 24, !8, i64 56}
!11 = !{!"bool", !8, i64 0}
!12 = !{!"_ZTSN11alglib_impl12ae_dyn_blockE", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"_ZTSN11alglib_impl9ae_matrixE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !12, i64 40, !8, i64 72}
!15 = !{!"double", !8, i64 0}
!16 = !{!8, !8, i64 0}
!17 = !{!15, !15, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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