; LLVM IR from avrtt/finite-element-method :: gauss.ll (Z12forwardGaussPdS_)

; 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
@ig = external global ptr, align 8
@L = external global ptr, align 8
@jg = external global ptr, align 8
@di = external global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z12forwardGaussPdS_(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
  %7 = alloca double, align 8
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

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

12:                                               ; preds = %8
  store double 0.000000e+00, ptr %7, align 8, !tbaa !11
  %13 = load ptr, ptr @ig, align 8, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i32, ptr %13, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %17, ptr %6, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %44, %12
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = load ptr, ptr @ig, align 8, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %20, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = icmp slt i32 %19, %25
  br i1 %26, label %27, label %47

27:                                               ; preds = %18
  %28 = load ptr, ptr @L, align 8, !tbaa !5
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %28, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr @jg, align 8, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %34, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds double, ptr %33, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !11
  %42 = load double, ptr %7, align 8, !tbaa !11
  %43 = call double @llvm.fmuladd.f64(double %32, double %41, double %42)
  store double %43, ptr %7, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %27
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %6, align 4, !tbaa !9
  br label %18, !llvm.loop !13

47:                                               ; preds = %18
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %48, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !11
  %53 = load double, ptr %7, align 8, !tbaa !11
  %54 = fsub double %52, %53
  %55 = load ptr, ptr @di, align 8, !tbaa !5
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds double, ptr %55, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !11
  %60 = fdiv double %54, %59
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds double, ptr %61, i64 %63
  store double %60, ptr %64, align 8, !tbaa !11
  br label %65

65:                                               ; preds = %47
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !15

68:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  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
@ig = external local_unnamed_addr global ptr, align 8
@L = external local_unnamed_addr global ptr, align 8
@jg = external local_unnamed_addr global ptr, align 8
@di = 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 @_Z12forwardGaussPdS_(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.ph22, label %._crit_edge23

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

9:                                                ; preds = %.lr.ph22, %._crit_edge
  %10 = phi i32 [ %.pre, %.lr.ph22 ], [ %12, %._crit_edge ]
  %indvars.iv25 = phi i64 [ 0, %.lr.ph22 ], [ %indvars.iv.next26, %._crit_edge ]
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %11 = getelementptr inbounds i32, ptr %5, i64 %indvars.iv.next26
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %9
  %14 = sext i32 %10 to i64
  %wide.trip.count = sext i32 %12 to i64
  %15 = sub nsw i64 %wide.trip.count, %14
  %xtraiter = and i64 %15, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %14, %.lr.ph.preheader ]
  %.018.prol = phi double [ %23, %.lr.ph.prol ], [ 0.000000e+00, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %16 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.prol
  %17 = load double, ptr %16, align 8, !tbaa !11
  %18 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv.prol
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %1, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = tail call double @llvm.fmuladd.f64(double %17, double %22, double %.018.prol)
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !13

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa.unr = phi double [ poison, %.lr.ph.preheader ], [ %23, %.lr.ph.prol ]
  %indvars.iv.unr = phi i64 [ %14, %.lr.ph.preheader ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %.018.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %23, %.lr.ph.prol ]
  %24 = sub nsw i64 %14, %wide.trip.count
  %25 = icmp ugt i64 %24, -4
  br i1 %25, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %.018 = phi double [ %57, %.lr.ph ], [ %.018.unr, %.lr.ph.prol.loopexit ]
  %26 = getelementptr inbounds double, ptr %6, i64 %indvars.iv
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %1, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = tail call double @llvm.fmuladd.f64(double %27, double %32, double %.018)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %34 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv.next
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %1, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = tail call double @llvm.fmuladd.f64(double %35, double %40, double %33)
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %42 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next.1
  %43 = load double, ptr %42, align 8, !tbaa !11
  %44 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv.next.1
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %1, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !11
  %49 = tail call double @llvm.fmuladd.f64(double %43, double %48, double %41)
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, 3
  %50 = getelementptr inbounds double, ptr %6, i64 %indvars.iv.next.2
  %51 = load double, ptr %50, align 8, !tbaa !11
  %52 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv.next.2
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %1, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !11
  %57 = tail call double @llvm.fmuladd.f64(double %51, double %56, double %49)
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %9
  %.0.lcssa = phi double [ 0.000000e+00, %9 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %57, %.lr.ph ]
  %58 = getelementptr inbounds double, ptr %0, i64 %indvars.iv25
  %59 = load double, ptr %58, align 8, !tbaa !11
  %60 = fsub double %59, %.0.lcssa
  %61 = getelementptr inbounds double, ptr %8, i64 %indvars.iv25
  %62 = load double, ptr %61, align 8, !tbaa !11
  %63 = fdiv double %60, %62
  %64 = getelementptr inbounds double, ptr %1, i64 %indvars.iv25
  store double %63, ptr %64, align 8, !tbaa !11
  %exitcond29.not = icmp eq i64 %indvars.iv.next26, %wide.trip.count28
  br i1 %exitcond29.not, label %._crit_edge23, label %9, !llvm.loop !17

._crit_edge23:                                    ; preds = %._crit_edge, %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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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