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

; 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 [2000 x [2000 x double]], align 16
@a = external hidden global [2000 x [2000 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 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: nounwind uwtable
define dso_local void @strsm(i64 noundef %0) #2 {
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i64 %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %78, %1
  %7 = load i32, ptr %3, align 4, !tbaa !9
  %8 = sext i32 %7 to i64
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = icmp slt i64 %8, %9
  br i1 %10, label %11, label %81

11:                                               ; preds = %6
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %74, %11
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = icmp slt i64 %14, %15
  br i1 %16, label %17, label %77

17:                                               ; preds = %12
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %5, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %70, %17
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = load i64, ptr %2, align 8, !tbaa !5
  %24 = icmp slt i64 %22, %23
  br i1 %24, label %25, label %73

25:                                               ; preds = %20
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  %29 = icmp eq i32 %26, %28
  br i1 %29, label %30, label %46

30:                                               ; preds = %25
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %32
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [2000 x double], ptr %33, i64 0, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %39
  %41 = load i32, ptr %3, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [2000 x double], ptr %40, i64 0, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = fdiv double %44, %37
  store double %45, ptr %43, align 8, !tbaa !11
  br label %46

46:                                               ; preds = %30, %25
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %48
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [2000 x double], ptr %49, i64 0, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !11
  %54 = load i32, ptr %4, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %55
  %57 = load i32, ptr %3, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [2000 x double], ptr %56, i64 0, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !11
  %61 = load i32, ptr %4, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %62
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [2000 x double], ptr %63, i64 0, i64 %65
  %67 = load double, ptr %66, align 8, !tbaa !11
  %68 = fneg double %53
  %69 = call double @llvm.fmuladd.f64(double %68, double %60, double %67)
  store double %69, ptr %66, align 8, !tbaa !11
  br label %70

70:                                               ; preds = %46
  %71 = load i32, ptr %5, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %5, align 4, !tbaa !9
  br label %20, !llvm.loop !13

73:                                               ; preds = %20
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %4, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %4, align 4, !tbaa !9
  br label %12, !llvm.loop !15

77:                                               ; preds = %12
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %3, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %3, align 4, !tbaa !9
  br label %6, !llvm.loop !16

81:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, 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 = !{!"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"

@b = external hidden local_unnamed_addr global [2000 x [2000 x double]], align 16
@a = external hidden local_unnamed_addr global [2000 x [2000 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 @strsm(i64 noundef %0) local_unnamed_addr #1 {
  %2 = icmp sgt i64 %0, 0
  br i1 %2, label %.preheader.us.preheader, label %._crit_edge

.preheader.us.preheader:                          ; preds = %1
  %3 = add nsw i64 %0, -2
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge31.us
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %._crit_edge31.us ], [ 0, %.preheader.us.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next.pre-phi, %._crit_edge31.us ], [ 1, %.preheader.us.preheader ]
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %4 = icmp ult i64 %indvars.iv.next46, %0
  br i1 %4, label %.lr.ph.us.us.preheader, label %.lr.ph30.split.us35.preheader

.lr.ph30.split.us35.preheader:                    ; preds = %.preheader.us
  %.pre52 = add nuw i64 %indvars.iv, 1
  br label %._crit_edge31.us

.lr.ph.us.us.preheader:                           ; preds = %.preheader.us
  %5 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv45, i64 %indvars.iv45
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv45, i64 %indvars.iv
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = fneg double %8
  %indvars.iv.next39.peel = add nuw i64 %indvars.iv, 1
  %10 = icmp ult i64 %indvars.iv.next39.peel, %0
  %11 = sub i64 %indvars.iv, %0
  %12 = and i64 %11, 1
  %lcmp.mod.not.not = icmp eq i64 %12, 0
  %13 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv45, i64 %indvars.iv.next39.peel
  %indvars.iv.next39.prol = add nuw i64 %indvars.iv, 2
  %14 = icmp eq i64 %3, %indvars.iv
  br label %15

._crit_edge31.us:                                 ; preds = %._crit_edge.us.us, %.lr.ph30.split.us35.preheader
  %indvars.iv.next.pre-phi = phi i64 [ %.pre52, %.lr.ph30.split.us35.preheader ], [ %indvars.iv.next39.peel, %._crit_edge.us.us ]
  %exitcond48.not = icmp eq i64 %indvars.iv.next46, %0
  br i1 %exitcond48.not, label %._crit_edge, label %.preheader.us, !llvm.loop !9

15:                                               ; preds = %.lr.ph.us.us.preheader, %._crit_edge.us.us
  %indvars.iv42 = phi i64 [ 0, %.lr.ph.us.us.preheader ], [ %indvars.iv.next43, %._crit_edge.us.us ]
  %16 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %indvars.iv42, i64 %indvars.iv45
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = fdiv double %17, %6
  store double %18, ptr %16, align 8, !tbaa !5
  %19 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %indvars.iv42, i64 %indvars.iv
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = tail call double @llvm.fmuladd.f64(double %9, double %18, double %20)
  store double %21, ptr %19, align 8, !tbaa !5
  br i1 %10, label %.peel.next.preheader, label %._crit_edge.us.us

.peel.next.preheader:                             ; preds = %15
  br i1 %lcmp.mod.not.not, label %.peel.next.prol, label %.peel.next.prol.loopexit

.peel.next.prol:                                  ; preds = %.peel.next.preheader
  %.pre49.prol = load double, ptr %16, align 8, !tbaa !5
  %.phi.trans.insert.prol = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %indvars.iv42, i64 %indvars.iv.next39.peel
  %.pre51.prol = load double, ptr %.phi.trans.insert.prol, align 8, !tbaa !5
  %22 = load double, ptr %13, align 8, !tbaa !5
  %23 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %indvars.iv42, i64 %indvars.iv.next39.peel
  %24 = fneg double %22
  %25 = tail call double @llvm.fmuladd.f64(double %24, double %.pre49.prol, double %.pre51.prol)
  store double %25, ptr %23, align 8, !tbaa !5
  br label %.peel.next.prol.loopexit

.peel.next.prol.loopexit:                         ; preds = %.peel.next.prol, %.peel.next.preheader
  %indvars.iv38.unr = phi i64 [ %indvars.iv.next39.peel, %.peel.next.preheader ], [ %indvars.iv.next39.prol, %.peel.next.prol ]
  br i1 %14, label %._crit_edge.us.us, label %.peel.next

.peel.next:                                       ; preds = %.peel.next.prol.loopexit, %.peel.next
  %indvars.iv38 = phi i64 [ %indvars.iv.next39.1, %.peel.next ], [ %indvars.iv38.unr, %.peel.next.prol.loopexit ]
  %.pre49 = load double, ptr %16, align 8, !tbaa !5
  %.phi.trans.insert = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %indvars.iv42, i64 %indvars.iv38
  %.pre51 = load double, ptr %.phi.trans.insert, align 8, !tbaa !5
  %26 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv45, i64 %indvars.iv38
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %indvars.iv42, i64 %indvars.iv38
  %29 = fneg double %27
  %30 = tail call double @llvm.fmuladd.f64(double %29, double %.pre49, double %.pre51)
  store double %30, ptr %28, align 8, !tbaa !5
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %.pre49.1 = load double, ptr %16, align 8, !tbaa !5
  %.phi.trans.insert.1 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %indvars.iv42, i64 %indvars.iv.next39
  %.pre51.1 = load double, ptr %.phi.trans.insert.1, align 8, !tbaa !5
  %31 = getelementptr inbounds [2000 x [2000 x double]], ptr @a, i64 0, i64 %indvars.iv45, i64 %indvars.iv.next39
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds [2000 x [2000 x double]], ptr @b, i64 0, i64 %indvars.iv42, i64 %indvars.iv.next39
  %34 = fneg double %32
  %35 = tail call double @llvm.fmuladd.f64(double %34, double %.pre49.1, double %.pre51.1)
  store double %35, ptr %33, align 8, !tbaa !5
  %indvars.iv.next39.1 = add nuw nsw i64 %indvars.iv38, 2
  %36 = icmp ult i64 %indvars.iv.next39.1, %0
  br i1 %36, label %.peel.next, label %._crit_edge.us.us, !llvm.loop !11

._crit_edge.us.us:                                ; preds = %.peel.next.prol.loopexit, %.peel.next, %15
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next43, %0
  br i1 %exitcond.not, label %._crit_edge31.us, label %15, !llvm.loop !13

._crit_edge:                                      ; preds = %._crit_edge31.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}
!12 = !{!"llvm.loop.peeled.count", i32 1}
!13 = distinct !{!13, !10}


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