; LLVM IR from SanketSarmalkar/Numerical_Methods :: System_of_Equation/DirectMethod.ll (Z17back_substitutionPPdii)

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

@.str.13 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [3 x i8], align 1

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

declare i32 @printf(ptr noundef, ...) #1

; 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) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z17back_substitutionPPdii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca [100 x double], align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 800, ptr %10) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %85, %3
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %88

15:                                               ; preds = %11
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = sub nsw i32 %17, 1
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = sub nsw i32 %18, %19
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds ptr, ptr %16, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds double, ptr %23, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !11
  store double %27, ptr %9, align 8, !tbaa !11
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %58, %15
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = load i32, ptr %7, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %61

32:                                               ; preds = %28
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 1
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = sub nsw i32 %34, %35
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100 x double], ptr %10, i64 0, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = sub nsw i32 %41, 1
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = sub nsw i32 %42, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds ptr, ptr %40, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = sub nsw i32 %48, 1
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = sub nsw i32 %49, %50
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %47, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !11
  %55 = load double, ptr %9, align 8, !tbaa !11
  %56 = fneg double %39
  %57 = call double @llvm.fmuladd.f64(double %56, double %54, double %55)
  store double %57, ptr %9, align 8, !tbaa !11
  br label %58

58:                                               ; preds = %32
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %8, align 4, !tbaa !9
  br label %28, !llvm.loop !13

61:                                               ; preds = %28
  %62 = load double, ptr %9, align 8, !tbaa !11
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = sub nsw i32 %64, 1
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = sub nsw i32 %65, %66
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds ptr, ptr %63, i64 %68
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = sub nsw i32 %71, 1
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = sub nsw i32 %72, %73
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds double, ptr %70, i64 %75
  %77 = load double, ptr %76, align 8, !tbaa !11
  %78 = fdiv double %62, %77
  %79 = load i32, ptr %6, align 4, !tbaa !9
  %80 = sub nsw i32 %79, 1
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = sub nsw i32 %80, %81
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [100 x double], ptr %10, i64 0, i64 %83
  store double %78, ptr %84, align 8, !tbaa !11
  br label %85

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

88:                                               ; preds = %11
  %89 = load i32, ptr %7, align 4, !tbaa !9
  %90 = load i32, ptr %7, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [100 x double], ptr %10, i64 0, i64 %91
  %93 = load double, ptr %92, align 8, !tbaa !11
  %94 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, i32 noundef %89, double noundef %93)
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %95

95:                                               ; preds = %105, %88
  %96 = load i32, ptr %7, align 4, !tbaa !9
  %97 = load i32, ptr %6, align 4, !tbaa !9
  %98 = icmp slt i32 %96, %97
  br i1 %98, label %99, label %108

99:                                               ; preds = %95
  %100 = load i32, ptr %7, align 4, !tbaa !9
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [100 x double], ptr %10, i64 0, i64 %101
  %103 = load double, ptr %102, align 8, !tbaa !11
  %104 = call i32 (ptr, ...) @printf(ptr noundef @.str.14, double noundef %103)
  br label %105

105:                                              ; preds = %99
  %106 = load i32, ptr %7, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %7, align 4, !tbaa !9
  br label %95, !llvm.loop !16

108:                                              ; preds = %95
  %109 = call i32 (ptr, ...) @printf(ptr noundef @.str.15)
  call void @llvm.lifetime.end.p0(i64 800, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { 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"

@.str.13 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z17back_substitutionPPdii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #3 {
  %4 = alloca [100 x double], align 16
  call void @llvm.lifetime.start.p0(i64 800, ptr nonnull %4) #4
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph39, label %._crit_edge40.thread

._crit_edge40.thread:                             ; preds = %3
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, i32 noundef 0, double noundef undef)
  br label %._crit_edge45

.lr.ph39:                                         ; preds = %3
  %7 = add nsw i32 %2, -1
  %8 = zext nneg i32 %2 to i64
  %9 = zext nneg i32 %7 to i64
  br label %10

10:                                               ; preds = %.lr.ph39, %._crit_edge
  %indvars.iv48 = phi i64 [ 0, %.lr.ph39 ], [ %indvars.iv.next49, %._crit_edge ]
  %11 = sub nsw i64 %9, %indvars.iv48
  %12 = getelementptr inbounds ptr, ptr %0, i64 %11
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds double, ptr %13, i64 %8
  %15 = load double, ptr %14, align 8, !tbaa !9
  %.not = icmp eq i64 %indvars.iv48, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %10
  %xtraiter = and i64 %indvars.iv48, 1
  %16 = icmp eq i64 %indvars.iv48, 1
  br i1 %16, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %indvars.iv48, 9223372036854775806
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.036 = phi double [ %15, %.lr.ph.preheader.new ], [ %30, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %17 = sub nsw i64 %9, %indvars.iv
  %18 = getelementptr inbounds [100 x double], ptr %4, i64 0, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds double, ptr %13, i64 %17
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fneg double %19
  %23 = tail call double @llvm.fmuladd.f64(double %22, double %21, double %.036)
  %indvars.iv.next.neg = xor i64 %indvars.iv, -1
  %24 = add nsw i64 %indvars.iv.next.neg, %9
  %25 = getelementptr inbounds [100 x double], ptr %4, i64 0, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds double, ptr %13, i64 %24
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = fneg double %26
  %30 = tail call double @llvm.fmuladd.f64(double %29, double %28, double %23)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 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.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !11

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %30, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.036.unr = phi double [ %15, %.lr.ph.preheader ], [ %30, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %31 = sub nsw i64 %9, %indvars.iv.unr
  %32 = getelementptr inbounds [100 x double], ptr %4, i64 0, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !9
  %34 = getelementptr inbounds double, ptr %13, i64 %31
  %35 = load double, ptr %34, align 8, !tbaa !9
  %36 = fneg double %33
  %37 = tail call double @llvm.fmuladd.f64(double %36, double %35, double %.036.unr)
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %10
  %.0.lcssa = phi double [ %15, %10 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %37, %.lr.ph.epil ]
  %38 = getelementptr inbounds double, ptr %13, i64 %11
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = fdiv double %.0.lcssa, %39
  %41 = getelementptr inbounds [100 x double], ptr %4, i64 0, i64 %11
  store double %40, ptr %41, align 8, !tbaa !9
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %exitcond52.not = icmp eq i64 %indvars.iv.next49, %8
  br i1 %exitcond52.not, label %._crit_edge40, label %10, !llvm.loop !13

._crit_edge40:                                    ; preds = %._crit_edge
  %.phi.trans.insert = getelementptr inbounds [100 x double], ptr %4, i64 0, i64 %8
  %.pre = load double, ptr %.phi.trans.insert, align 8, !tbaa !9
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, i32 noundef %2, double noundef %.pre)
  br i1 %5, label %.lr.ph44.preheader, label %._crit_edge45

.lr.ph44.preheader:                               ; preds = %._crit_edge40
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.lr.ph44

.lr.ph44:                                         ; preds = %.lr.ph44.preheader, %.lr.ph44
  %indvars.iv53 = phi i64 [ 0, %.lr.ph44.preheader ], [ %indvars.iv.next54, %.lr.ph44 ]
  %43 = getelementptr inbounds [100 x double], ptr %4, i64 0, i64 %indvars.iv53
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14, double noundef %44)
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 1
  %exitcond56.not = icmp eq i64 %indvars.iv.next54, %wide.trip.count
  br i1 %exitcond56.not, label %._crit_edge45, label %.lr.ph44, !llvm.loop !14

._crit_edge45:                                    ; preds = %.lr.ph44, %._crit_edge40.thread, %._crit_edge40
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.15)
  call void @llvm.lifetime.end.p0(i64 800, ptr nonnull %4) #4
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree nounwind "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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress nofree 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 #4 = { 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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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