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

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

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z13backwardGaussPdS_(ptr noundef %0, ptr noundef %1) #2 {
  %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 = %21, %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 %24

11:                                               ; preds = %7
  %12 = load ptr, ptr %3, 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 %4, 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
  store double %16, ptr %20, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %11
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !13

24:                                               ; preds = %7
  %25 = load i32, ptr @N, align 4, !tbaa !9
  %26 = sub nsw i32 %25, 1
  store i32 %26, ptr %5, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %71, %24
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = icmp sge i32 %28, 0
  br i1 %29, label %30, label %74

30:                                               ; preds = %27
  %31 = load ptr, ptr @ig, align 8, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr %31, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !9
  store i32 %35, ptr %6, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %67, %30
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = load ptr, ptr @ig, align 8, !tbaa !5
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %38, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = icmp slt i32 %37, %43
  br i1 %44, label %45, label %70

45:                                               ; preds = %36
  %46 = load ptr, ptr @U, align 8, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %46, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !11
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds double, ptr %51, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !11
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load ptr, ptr @jg, align 8, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i32, ptr %57, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %56, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !11
  %65 = fneg double %50
  %66 = call double @llvm.fmuladd.f64(double %65, double %55, double %64)
  store double %66, ptr %63, align 8, !tbaa !11
  br label %67

67:                                               ; preds = %45
  %68 = load i32, ptr %6, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %6, align 4, !tbaa !9
  br label %36, !llvm.loop !15

70:                                               ; preds = %36
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = add nsw i32 %72, -1
  store i32 %73, ptr %5, align 4, !tbaa !9
  br label %27, !llvm.loop !16

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !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}
!16 = distinct !{!16, !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
@jg = external local_unnamed_addr global ptr, align 8
@U = external local_unnamed_addr global ptr, align 8

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

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

.lr.ph.preheader:                                 ; preds = %2
  %5 = ptrtoint ptr %1 to i64
  %6 = ptrtoint ptr %0 to i64
  %wide.trip.count = zext nneg i32 %3 to i64
  %min.iters.check = icmp ult i32 %3, 6
  %7 = sub i64 %5, %6
  %diff.check = icmp ult i64 %7, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader35, label %vector.ph

.lr.ph.preheader35:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 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.preheader35, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %indvars.iv.ph, %.lr.ph.preheader35 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader35 ]
  %8 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.prol
  %9 = load double, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.prol
  store double %9, ptr %10, align 8, !tbaa !9
  %indvars.iv.next.prol = add nuw 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 !11

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader35
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader35 ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %11 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %12 = icmp ugt i64 %11, -4
  br i1 %12, label %.preheader, label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %13 = getelementptr inbounds double, ptr %0, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %wide.load = load <2 x double>, ptr %13, align 8, !tbaa !9
  %wide.load34 = load <2 x double>, ptr %14, align 8, !tbaa !9
  %15 = getelementptr inbounds double, ptr %1, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store <2 x double> %wide.load, ptr %15, align 8, !tbaa !9
  store <2 x double> %wide.load34, ptr %16, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.preheader, label %.lr.ph.preheader35

.preheader:                                       ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block
  br i1 %4, label %.lr.ph24, label %._crit_edge

.lr.ph24:                                         ; preds = %.preheader
  %18 = load ptr, ptr @ig, align 8, !tbaa !17
  %19 = load ptr, ptr @U, align 8
  %20 = load ptr, ptr @jg, align 8
  %21 = zext nneg i32 %3 to i64
  %.phi.trans.insert = getelementptr inbounds i32, ptr %18, i64 %21
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  br label %35

.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 ]
  %22 = getelementptr inbounds double, ptr %0, i64 %indvars.iv
  %23 = load double, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  store double %23, ptr %24, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  store double %26, ptr %27, align 8, !tbaa !9
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %28 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next.1
  %29 = load double, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next.1
  store double %29, ptr %30, align 8, !tbaa !9
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %31 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next.2
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next.2
  store double %32, ptr %33, align 8, !tbaa !9
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %.preheader, label %.lr.ph, !llvm.loop !19

.loopexit:                                        ; preds = %.prol.loopexit, %.lr.ph20.new, %35
  %34 = icmp sgt i64 %indvars.iv31, 1
  br i1 %34, label %35, label %._crit_edge, !llvm.loop !20

35:                                               ; preds = %.lr.ph24, %.loopexit
  %36 = phi i32 [ %.pre, %.lr.ph24 ], [ %38, %.loopexit ]
  %indvars.iv31 = phi i64 [ %21, %.lr.ph24 ], [ %indvars.iv.next32, %.loopexit ]
  %indvars.iv.next32 = add nsw i64 %indvars.iv31, -1
  %37 = getelementptr inbounds i32, ptr %18, i64 %indvars.iv.next32
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = icmp slt i32 %38, %36
  br i1 %39, label %.lr.ph20, label %.loopexit

.lr.ph20:                                         ; preds = %35
  %40 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next32
  %41 = sext i32 %38 to i64
  %wide.trip.count29 = sext i32 %36 to i64
  %42 = sub nsw i64 %wide.trip.count29, %41
  %xtraiter36 = and i64 %42, 1
  %lcmp.mod37.not = icmp eq i64 %xtraiter36, 0
  br i1 %lcmp.mod37.not, label %.prol.loopexit, label %.prol.loopexit.unr-lcssa

.prol.loopexit.unr-lcssa:                         ; preds = %.lr.ph20
  %43 = getelementptr inbounds double, ptr %19, i64 %41
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = load double, ptr %40, align 8, !tbaa !9
  %46 = getelementptr inbounds i32, ptr %20, i64 %41
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %1, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !9
  %51 = fneg double %44
  %52 = tail call double @llvm.fmuladd.f64(double %51, double %45, double %50)
  store double %52, ptr %49, align 8, !tbaa !9
  %indvars.iv.next27.prol = add nsw i64 %41, 1
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph20
  %indvars.iv26.unr = phi i64 [ %41, %.lr.ph20 ], [ %indvars.iv.next27.prol, %.prol.loopexit.unr-lcssa ]
  %53 = add nsw i64 %wide.trip.count29, -1
  %54 = icmp eq i64 %53, %41
  br i1 %54, label %.loopexit, label %.lr.ph20.new

.lr.ph20.new:                                     ; preds = %.prol.loopexit, %.lr.ph20.new
  %indvars.iv26 = phi i64 [ %indvars.iv.next27.1, %.lr.ph20.new ], [ %indvars.iv26.unr, %.prol.loopexit ]
  %55 = getelementptr inbounds double, ptr %19, i64 %indvars.iv26
  %56 = load double, ptr %55, align 8, !tbaa !9
  %57 = load double, ptr %40, align 8, !tbaa !9
  %58 = getelementptr inbounds i32, ptr %20, i64 %indvars.iv26
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds double, ptr %1, i64 %60
  %62 = load double, ptr %61, align 8, !tbaa !9
  %63 = fneg double %56
  %64 = tail call double @llvm.fmuladd.f64(double %63, double %57, double %62)
  store double %64, ptr %61, align 8, !tbaa !9
  %indvars.iv.next27 = add nsw i64 %indvars.iv26, 1
  %65 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.next27
  %66 = load double, ptr %65, align 8, !tbaa !9
  %67 = load double, ptr %40, align 8, !tbaa !9
  %68 = getelementptr inbounds i32, ptr %20, i64 %indvars.iv.next27
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds double, ptr %1, i64 %70
  %72 = load double, ptr %71, align 8, !tbaa !9
  %73 = fneg double %66
  %74 = tail call double @llvm.fmuladd.f64(double %73, double %67, double %72)
  store double %74, ptr %71, align 8, !tbaa !9
  %indvars.iv.next27.1 = add nsw i64 %indvars.iv26, 2
  %exitcond30.not.1 = icmp eq i64 %indvars.iv.next27.1, %wide.trip.count29
  br i1 %exitcond30.not.1, label %.loopexit, label %.lr.ph20.new, !llvm.loop !21

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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" }

!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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !14, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = !{!18, !18, i64 0}
!18 = !{!"any pointer", !7, i64 0}
!19 = distinct !{!19, !14, !15}
!20 = distinct !{!20, !14}
!21 = distinct !{!21, !14}


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