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

; 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
@U = external global ptr, align 8
@ggl = external global ptr, align 8
@ggu = external global ptr, align 8
@diOrig = 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

3:                                                ; preds = %84, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = load i32, ptr @N, align 4, !tbaa !5
  %6 = icmp slt i32 %4, %5
  br i1 %6, label %7, label %87

7:                                                ; preds = %3
  %8 = load ptr, ptr @ig, align 8, !tbaa !9
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds i32, ptr %8, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %12, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %67, %7
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = load ptr, ptr @ig, align 8, !tbaa !9
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i32, ptr %15, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp slt i32 %14, %20
  br i1 %21, label %22, label %70

22:                                               ; preds = %13
  %23 = load ptr, ptr @ggl, align 8, !tbaa !9
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %23, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = load ptr, ptr @jg, align 8, !tbaa !9
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %29, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = call noundef double @_Z3sumii(i32 noundef %28, i32 noundef %33)
  %35 = fsub double %27, %34
  %36 = load ptr, ptr @L, align 8, !tbaa !9
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %36, i64 %38
  store double %35, ptr %39, align 8, !tbaa !11
  %40 = load ptr, ptr @ggu, align 8, !tbaa !9
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %40, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = load ptr, ptr @jg, align 8, !tbaa !9
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %45, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %1, align 4, !tbaa !5
  %51 = call noundef double @_Z3sumii(i32 noundef %49, i32 noundef %50)
  %52 = fsub double %44, %51
  %53 = load ptr, ptr @di, align 8, !tbaa !9
  %54 = load ptr, ptr @jg, align 8, !tbaa !9
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds double, ptr %53, i64 %59
  %61 = load double, ptr %60, align 8, !tbaa !11
  %62 = fdiv double %52, %61
  %63 = load ptr, ptr @U, align 8, !tbaa !9
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds double, ptr %63, i64 %65
  store double %62, ptr %66, align 8, !tbaa !11
  br label %67

67:                                               ; preds = %22
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !13

70:                                               ; preds = %13
  %71 = load ptr, ptr @diOrig, align 8, !tbaa !9
  %72 = load i32, ptr %1, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds double, ptr %71, i64 %73
  %75 = load double, ptr %74, align 8, !tbaa !11
  %76 = load i32, ptr %1, align 4, !tbaa !5
  %77 = load i32, ptr %1, align 4, !tbaa !5
  %78 = call noundef double @_Z3sumii(i32 noundef %76, i32 noundef %77)
  %79 = fsub double %75, %78
  %80 = load ptr, ptr @di, align 8, !tbaa !9
  %81 = load i32, ptr %1, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds double, ptr %80, i64 %82
  store double %79, ptr %83, align 8, !tbaa !11
  br label %84

84:                                               ; preds = %70
  %85 = load i32, ptr %1, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !15

87:                                               ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

declare noundef double @_Z3sumii(i32 noundef, i32 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 = { "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 = !{!"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.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
@U = external local_unnamed_addr global ptr, align 8
@ggl = external local_unnamed_addr global ptr, align 8
@ggu = external local_unnamed_addr global ptr, align 8
@diOrig = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z13factorizationv() local_unnamed_addr #0 {
  %1 = load i32, ptr @N, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph23, label %._crit_edge24

.lr.ph23:                                         ; preds = %0, %._crit_edge
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %._crit_edge ], [ 0, %0 ]
  %3 = load ptr, ptr @ig, align 8, !tbaa !9
  %4 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv26
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %6 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv.next27
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp slt i32 %5, %7
  br i1 %8, label %.lr.ph.preheader, label %.lr.ph23.._crit_edge_crit_edge

.lr.ph23.._crit_edge_crit_edge:                   ; preds = %.lr.ph23
  %.pre29 = trunc nuw nsw i64 %indvars.iv26 to i32
  br label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph23
  %9 = sext i32 %5 to i64
  %.pre = load ptr, ptr @jg, align 8, !tbaa !9
  %10 = trunc nuw nsw i64 %indvars.iv26 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %11 = phi ptr [ %.pre, %.lr.ph.preheader ], [ %30, %.lr.ph ]
  %indvars.iv = phi i64 [ %9, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %12 = load ptr, ptr @ggl, align 8, !tbaa !9
  %13 = getelementptr inbounds double, ptr %12, i64 %indvars.iv
  %14 = load double, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds i32, ptr %11, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = tail call noundef double @_Z3sumii(i32 noundef %10, i32 noundef %16)
  %18 = fsub double %14, %17
  %19 = load ptr, ptr @L, align 8, !tbaa !9
  %20 = getelementptr inbounds double, ptr %19, i64 %indvars.iv
  store double %18, ptr %20, align 8, !tbaa !11
  %21 = load ptr, ptr @ggu, align 8, !tbaa !9
  %22 = getelementptr inbounds double, ptr %21, i64 %indvars.iv
  %23 = load double, ptr %22, align 8, !tbaa !11
  %24 = load ptr, ptr @jg, align 8, !tbaa !9
  %25 = getelementptr inbounds i32, ptr %24, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = tail call noundef double @_Z3sumii(i32 noundef %26, i32 noundef %10)
  %28 = fsub double %23, %27
  %29 = load ptr, ptr @di, align 8, !tbaa !9
  %30 = load ptr, ptr @jg, align 8, !tbaa !9
  %31 = getelementptr inbounds i32, ptr %30, i64 %indvars.iv
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds double, ptr %29, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = fdiv double %28, %35
  %37 = load ptr, ptr @U, align 8, !tbaa !9
  %38 = getelementptr inbounds double, ptr %37, i64 %indvars.iv
  store double %36, ptr %38, align 8, !tbaa !11
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %39 = load ptr, ptr @ig, align 8, !tbaa !9
  %40 = getelementptr inbounds i32, ptr %39, i64 %indvars.iv.next27
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = icmp slt i64 %indvars.iv.next, %42
  br i1 %43, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph23.._crit_edge_crit_edge
  %.pre-phi = phi i32 [ %.pre29, %.lr.ph23.._crit_edge_crit_edge ], [ %10, %.lr.ph ]
  %44 = load ptr, ptr @diOrig, align 8, !tbaa !9
  %45 = getelementptr inbounds double, ptr %44, i64 %indvars.iv26
  %46 = load double, ptr %45, align 8, !tbaa !11
  %47 = tail call noundef double @_Z3sumii(i32 noundef %.pre-phi, i32 noundef %.pre-phi)
  %48 = fsub double %46, %47
  %49 = load ptr, ptr @di, align 8, !tbaa !9
  %50 = getelementptr inbounds double, ptr %49, i64 %indvars.iv26
  store double %48, ptr %50, align 8, !tbaa !11
  %51 = load i32, ptr @N, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = icmp slt i64 %indvars.iv.next27, %52
  br i1 %53, label %.lr.ph23, label %._crit_edge24, !llvm.loop !15

._crit_edge24:                                    ; preds = %._crit_edge, %0
  ret void
}

declare noundef double @_Z3sumii(i32 noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 #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" }

!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.mustprogress"}
!15 = distinct !{!15, !14}


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