; LLVM IR from avrtt/finite-element-method :: math.ll (Z11multVectByAPdS_)

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

@N = external global i32, align 4
@diOrig = external global ptr, align 8
@ig = external global ptr, align 8
@ggl = external global ptr, align 8
@jg = external global ptr, align 8
@ggu = external global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z11multVectByAPdS_(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %86, %2
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = load i32, ptr @N, align 4, !tbaa !9
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %11, label %89

11:                                               ; preds = %7
  %12 = load ptr, ptr @diOrig, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds double, ptr %12, i64 %14
  %16 = load double, ptr %15, align 8, !tbaa !11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds double, ptr %17, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !11
  %22 = fmul double %16, %21
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %23, i64 %25
  store double %22, ptr %26, align 8, !tbaa !11
  %27 = load ptr, ptr @ig, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr %27, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  store i32 %31, ptr %6, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %82, %11
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = load ptr, ptr @ig, align 8, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = add nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %34, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = icmp slt i32 %33, %39
  br i1 %40, label %41, label %85

41:                                               ; preds = %32
  %42 = load ptr, ptr @ggl, align 8, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %42, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !11
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = load ptr, ptr @jg, align 8, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i32, ptr %48, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds double, ptr %47, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !11
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %56, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !11
  %61 = call double @llvm.fmuladd.f64(double %46, double %55, double %60)
  store double %61, ptr %59, align 8, !tbaa !11
  %62 = load ptr, ptr @ggu, align 8, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds double, ptr %62, i64 %64
  %66 = load double, ptr %65, align 8, !tbaa !11
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = load i32, ptr %5, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds double, ptr %67, i64 %69
  %71 = load double, ptr %70, align 8, !tbaa !11
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = load ptr, ptr @jg, align 8, !tbaa !5
  %74 = load i32, ptr %6, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i32, ptr %73, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds double, ptr %72, i64 %78
  %80 = load double, ptr %79, align 8, !tbaa !11
  %81 = call double @llvm.fmuladd.f64(double %66, double %71, double %80)
  store double %81, ptr %79, align 8, !tbaa !11
  br label %82

82:                                               ; preds = %41
  %83 = load i32, ptr %6, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %6, align 4, !tbaa !9
  br label %32, !llvm.loop !13

85:                                               ; preds = %32
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %5, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !15

89:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@N = external local_unnamed_addr global i32, align 4
@diOrig = external local_unnamed_addr global ptr, align 8
@ig = external local_unnamed_addr global ptr, align 8
@ggl = external local_unnamed_addr global ptr, align 8
@jg = external local_unnamed_addr global ptr, align 8
@ggu = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z11multVectByAPdS_(ptr nocapture noundef readonly %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @N, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph23, label %._crit_edge

.lr.ph23:                                         ; preds = %2
  %5 = load ptr, ptr @diOrig, align 8, !tbaa !9
  %6 = load ptr, ptr @ig, align 8, !tbaa !9
  %7 = load ptr, ptr @ggl, align 8
  %8 = load ptr, ptr @jg, align 8
  %9 = load ptr, ptr @ggu, align 8
  %wide.trip.count28 = zext nneg i32 %3 to i64
  %.pre = load i32, ptr %6, align 4, !tbaa !5
  br label %10

.loopexit:                                        ; preds = %.lr.ph, %10
  %exitcond29.not = icmp eq i64 %indvars.iv.next26, %wide.trip.count28
  br i1 %exitcond29.not, label %._crit_edge, label %10, !llvm.loop !11

10:                                               ; preds = %.lr.ph23, %.loopexit
  %11 = phi i32 [ %.pre, %.lr.ph23 ], [ %19, %.loopexit ]
  %indvars.iv25 = phi i64 [ 0, %.lr.ph23 ], [ %indvars.iv.next26, %.loopexit ]
  %12 = getelementptr inbounds double, ptr %5, i64 %indvars.iv25
  %13 = load double, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds double, ptr %0, i64 %indvars.iv25
  %15 = load double, ptr %14, align 8, !tbaa !13
  %16 = fmul double %13, %15
  %17 = getelementptr inbounds double, ptr %1, i64 %indvars.iv25
  store double %16, ptr %17, align 8, !tbaa !13
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %18 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv.next26
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = icmp slt i32 %11, %19
  br i1 %20, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %10
  %21 = sext i32 %11 to i64
  %wide.trip.count = sext i32 %19 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %21, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %22 = getelementptr inbounds double, ptr %7, i64 %indvars.iv
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = getelementptr inbounds i32, ptr %8, i64 %indvars.iv
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds double, ptr %0, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !13
  %29 = load double, ptr %17, align 8, !tbaa !13
  %30 = tail call double @llvm.fmuladd.f64(double %23, double %28, double %29)
  store double %30, ptr %17, align 8, !tbaa !13
  %31 = getelementptr inbounds double, ptr %9, i64 %indvars.iv
  %32 = load double, ptr %31, align 8, !tbaa !13
  %33 = load double, ptr %14, align 8, !tbaa !13
  %34 = getelementptr inbounds double, ptr %1, i64 %26
  %35 = load double, ptr %34, align 8, !tbaa !13
  %36 = tail call double @llvm.fmuladd.f64(double %32, double %33, double %35)
  store double %36, ptr %34, align 8, !tbaa !13
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.loopexit, %2
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !12}


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