; LLVM IR from bondhugula/pluto :: examples/trisolv (trisolv)

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

@B = external hidden global [1000 x [1000 x double]], align 16
@L = external hidden global [1000 x [1000 x double]], align 16

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

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

6:                                                ; preds = %68, %1
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = sub nsw i64 %8, 1
  %10 = icmp sle i64 %7, %9
  br i1 %10, label %11, label %71

11:                                               ; preds = %6
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %64, %11
  %13 = load i64, ptr %4, align 8, !tbaa !5
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = sub nsw i64 %14, 1
  %16 = icmp sle i64 %13, %15
  br i1 %16, label %17, label %67

17:                                               ; preds = %12
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %45, %17
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = sub nsw i64 %20, 1
  %22 = icmp sle i64 %19, %21
  br i1 %22, label %23, label %48

23:                                               ; preds = %18
  %24 = load i64, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds [1000 x [1000 x double]], ptr @B, i64 0, i64 %24
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds [1000 x double], ptr %25, i64 0, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = load i64, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds [1000 x [1000 x double]], ptr @L, i64 0, i64 %29
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds [1000 x double], ptr %30, i64 0, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !9
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds [1000 x [1000 x double]], ptr @B, i64 0, i64 %34
  %36 = load i64, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds [1000 x double], ptr %35, i64 0, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = fneg double %33
  %40 = call double @llvm.fmuladd.f64(double %39, double %38, double %28)
  %41 = load i64, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds [1000 x [1000 x double]], ptr @B, i64 0, i64 %41
  %43 = load i64, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds [1000 x double], ptr %42, i64 0, i64 %43
  store double %40, ptr %44, align 8, !tbaa !9
  br label %45

45:                                               ; preds = %23
  %46 = load i64, ptr %5, align 8, !tbaa !5
  %47 = add nsw i64 %46, 1
  store i64 %47, ptr %5, align 8, !tbaa !5
  br label %18, !llvm.loop !11

48:                                               ; preds = %18
  %49 = load i64, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds [1000 x [1000 x double]], ptr @B, i64 0, i64 %49
  %51 = load i64, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds [1000 x double], ptr %50, i64 0, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !9
  %54 = load i64, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds [1000 x [1000 x double]], ptr @L, i64 0, i64 %54
  %56 = load i64, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds [1000 x double], ptr %55, i64 0, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !9
  %59 = fdiv double %53, %58
  %60 = load i64, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds [1000 x [1000 x double]], ptr @B, i64 0, i64 %60
  %62 = load i64, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds [1000 x double], ptr %61, i64 0, i64 %62
  store double %59, ptr %63, align 8, !tbaa !9
  br label %64

64:                                               ; preds = %48
  %65 = load i64, ptr %4, align 8, !tbaa !5
  %66 = add nsw i64 %65, 1
  store i64 %66, ptr %4, align 8, !tbaa !5
  br label %12, !llvm.loop !13

67:                                               ; preds = %12
  br label %68

68:                                               ; preds = %67
  %69 = load i64, ptr %3, align 8, !tbaa !5
  %70 = add nsw i64 %69, 1
  store i64 %70, ptr %3, align 8, !tbaa !5
  br label %6, !llvm.loop !14

71:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

@B = external hidden local_unnamed_addr global [1000 x [1000 x double]], align 16
@L = external hidden local_unnamed_addr global [1000 x [1000 x double]], align 16

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

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @trisolv(i64 noundef %0) local_unnamed_addr #1 {
  %.not.not34 = icmp sgt i64 %0, 0
  br i1 %.not.not34, label %.preheader28.us, label %._crit_edge36

.preheader28.us:                                  ; preds = %1, %._crit_edge33.us
  %.02435.us = phi i64 [ %32, %._crit_edge33.us ], [ 0, %1 ]
  %.phi.trans.insert = getelementptr inbounds [1000 x [1000 x double]], ptr @B, i64 0, i64 0, i64 %.02435.us
  br label %.preheader.us

._crit_edge.us.loopexit.unr-lcssa:                ; preds = %14, %.lr.ph.us
  %.lcssa.ph = phi double [ poison, %.lr.ph.us ], [ %28, %14 ]
  %.unr = phi double [ %.promoted.us, %.lr.ph.us ], [ %28, %14 ]
  %.030.us.unr = phi i64 [ 0, %.lr.ph.us ], [ %29, %14 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.loopexit.epilog-lcssa

._crit_edge.us.loopexit.epilog-lcssa:             ; preds = %._crit_edge.us.loopexit.unr-lcssa
  %2 = getelementptr inbounds [1000 x [1000 x double]], ptr @L, i64 0, i64 %.02332.us, i64 %.030.us.unr
  %3 = load double, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds [1000 x [1000 x double]], ptr @B, i64 0, i64 %.030.us.unr, i64 %.02435.us
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = fneg double %3
  %7 = tail call double @llvm.fmuladd.f64(double %6, double %5, double %.unr)
  store double %7, ptr %30, align 8, !tbaa !5
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.loopexit.epilog-lcssa, %._crit_edge.us.loopexit.unr-lcssa, %.preheader.us.._crit_edge.us_crit_edge
  %8 = phi double [ %.pre, %.preheader.us.._crit_edge.us_crit_edge ], [ %.lcssa.ph, %._crit_edge.us.loopexit.unr-lcssa ], [ %7, %._crit_edge.us.loopexit.epilog-lcssa ]
  %9 = getelementptr inbounds [1000 x [1000 x double]], ptr @B, i64 0, i64 %.02332.us, i64 %.02435.us
  %10 = getelementptr inbounds [1000 x [1000 x double]], ptr @L, i64 0, i64 %.02332.us, i64 %.02332.us
  %11 = load double, ptr %10, align 8, !tbaa !5
  %12 = fdiv double %8, %11
  store double %12, ptr %9, align 8, !tbaa !5
  %13 = add nuw nsw i64 %.02332.us, 1
  %exitcond37.not = icmp eq i64 %13, %0
  br i1 %exitcond37.not, label %._crit_edge33.us, label %.preheader.us, !llvm.loop !9

14:                                               ; preds = %14, %.lr.ph.us.new
  %15 = phi double [ %.promoted.us, %.lr.ph.us.new ], [ %28, %14 ]
  %.030.us = phi i64 [ 0, %.lr.ph.us.new ], [ %29, %14 ]
  %niter = phi i64 [ 0, %.lr.ph.us.new ], [ %niter.next.1, %14 ]
  %16 = getelementptr inbounds [1000 x [1000 x double]], ptr @L, i64 0, i64 %.02332.us, i64 %.030.us
  %17 = load double, ptr %16, align 16, !tbaa !5
  %18 = getelementptr inbounds [1000 x [1000 x double]], ptr @B, i64 0, i64 %.030.us, i64 %.02435.us
  %19 = load double, ptr %18, align 8, !tbaa !5
  %20 = fneg double %17
  %21 = tail call double @llvm.fmuladd.f64(double %20, double %19, double %15)
  store double %21, ptr %30, align 8, !tbaa !5
  %22 = or disjoint i64 %.030.us, 1
  %23 = getelementptr inbounds [1000 x [1000 x double]], ptr @L, i64 0, i64 %.02332.us, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds [1000 x [1000 x double]], ptr @B, i64 0, i64 %22, i64 %.02435.us
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = fneg double %24
  %28 = tail call double @llvm.fmuladd.f64(double %27, double %26, double %21)
  store double %28, ptr %30, align 8, !tbaa !5
  %29 = add nuw nsw i64 %.030.us, 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 %._crit_edge.us.loopexit.unr-lcssa, label %14, !llvm.loop !11

.preheader.us:                                    ; preds = %.preheader28.us, %._crit_edge.us
  %.02332.us = phi i64 [ 0, %.preheader28.us ], [ %13, %._crit_edge.us ]
  %.not.not2729.us.not = icmp eq i64 %.02332.us, 0
  br i1 %.not.not2729.us.not, label %.preheader.us.._crit_edge.us_crit_edge, label %.lr.ph.us

.preheader.us.._crit_edge.us_crit_edge:           ; preds = %.preheader.us
  %.pre = load double, ptr %.phi.trans.insert, align 8, !tbaa !5
  br label %._crit_edge.us

.lr.ph.us:                                        ; preds = %.preheader.us
  %30 = getelementptr inbounds [1000 x [1000 x double]], ptr @B, i64 0, i64 %.02332.us, i64 %.02435.us
  %.promoted.us = load double, ptr %30, align 8, !tbaa !5
  %xtraiter = and i64 %.02332.us, 1
  %31 = icmp eq i64 %.02332.us, 1
  br i1 %31, label %._crit_edge.us.loopexit.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us
  %unroll_iter = and i64 %.02332.us, 9223372036854775806
  br label %14

._crit_edge33.us:                                 ; preds = %._crit_edge.us
  %32 = add nuw nsw i64 %.02435.us, 1
  %exitcond38.not = icmp eq i64 %32, %0
  br i1 %exitcond38.not, label %._crit_edge36, label %.preheader28.us, !llvm.loop !12

._crit_edge36:                                    ; preds = %._crit_edge33.us, %1
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


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