; LLVM IR from shyams2/SIMPLE_Solver :: SIMPLE.ll (Z6psicalv)

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

@u = external dso_local global [90601 x double], align 16
@v = external dso_local global [90601 x double], align 16
@psix = external dso_local global [90601 x double], align 16
@psiy = external dso_local global [90601 x double], align 16
@psi = external dso_local global [90601 x double], align 16
@dx = external dso_local global double, align 8
@dy = external dso_local global double, align 8
@psimax = external dso_local global double, align 8
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4

; 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: mustprogress nounwind uwtable
define dso_local void @_Z6psicalv() #2 {
  %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 1, ptr %2, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %92, %0
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @k, align 4, !tbaa !5
  %6 = icmp slt i32 %4, %5
  br i1 %6, label %7, label %95

7:                                                ; preds = %3
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %88, %7
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = load i32, ptr @k, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %91

12:                                               ; preds = %8
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sub nsw i32 %14, 1
  %16 = mul nsw i32 %13, %15
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = add nsw i32 %16, %17
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [90601 x double], ptr @psiy, i64 0, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = mul nsw i32 %22, %23
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = add nsw i32 %24, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [90601 x double], ptr @u, i64 0, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !9
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  %33 = mul nsw i32 %30, %32
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = add nsw i32 %33, %34
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [90601 x double], ptr @u, i64 0, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = fadd double %29, %38
  %40 = fmul double 5.000000e-01, %39
  %41 = load double, ptr @dy, align 8, !tbaa !9
  %42 = call double @llvm.fmuladd.f64(double %40, double %41, double %21)
  %43 = load i32, ptr @n, align 4, !tbaa !5
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = mul nsw i32 %43, %44
  %46 = load i32, ptr %1, align 4, !tbaa !5
  %47 = add nsw i32 %45, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [90601 x double], ptr @psiy, i64 0, i64 %48
  store double %42, ptr %49, align 8, !tbaa !9
  %50 = load i32, ptr @n, align 4, !tbaa !5
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = mul nsw i32 %50, %51
  %53 = load i32, ptr %1, align 4, !tbaa !5
  %54 = sub nsw i32 %53, 1
  %55 = add nsw i32 %52, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [90601 x double], ptr @psix, i64 0, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !9
  %59 = load i32, ptr @n, align 4, !tbaa !5
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = mul nsw i32 %59, %60
  %62 = load i32, ptr %1, align 4, !tbaa !5
  %63 = add nsw i32 %61, %62
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [90601 x double], ptr @v, i64 0, i64 %64
  %66 = load double, ptr %65, align 8, !tbaa !9
  %67 = load i32, ptr @n, align 4, !tbaa !5
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = mul nsw i32 %67, %68
  %70 = load i32, ptr %1, align 4, !tbaa !5
  %71 = sub nsw i32 %70, 1
  %72 = add nsw i32 %69, %71
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [90601 x double], ptr @v, i64 0, i64 %73
  %75 = load double, ptr %74, align 8, !tbaa !9
  %76 = fadd double %66, %75
  %77 = fmul double 5.000000e-01, %76
  %78 = load double, ptr @dx, align 8, !tbaa !9
  %79 = fneg double %77
  %80 = call double @llvm.fmuladd.f64(double %79, double %78, double %58)
  %81 = load i32, ptr @n, align 4, !tbaa !5
  %82 = load i32, ptr %2, align 4, !tbaa !5
  %83 = mul nsw i32 %81, %82
  %84 = load i32, ptr %1, align 4, !tbaa !5
  %85 = add nsw i32 %83, %84
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [90601 x double], ptr @psix, i64 0, i64 %86
  store double %80, ptr %87, align 8, !tbaa !9
  br label %88

88:                                               ; preds = %12
  %89 = load i32, ptr %1, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !11

91:                                               ; preds = %8
  br label %92

92:                                               ; preds = %91
  %93 = load i32, ptr %2, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %2, align 4, !tbaa !5
  br label %3, !llvm.loop !13

95:                                               ; preds = %3
  store double -1.000000e+00, ptr @psimax, align 8, !tbaa !9
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %96

96:                                               ; preds = %128, %95
  %97 = load i32, ptr %1, align 4, !tbaa !5
  %98 = load i32, ptr @n, align 4, !tbaa !5
  %99 = load i32, ptr @n, align 4, !tbaa !5
  %100 = mul nsw i32 %98, %99
  %101 = icmp slt i32 %97, %100
  br i1 %101, label %102, label %131

102:                                              ; preds = %96
  %103 = load i32, ptr %1, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [90601 x double], ptr @psix, i64 0, i64 %104
  %106 = load double, ptr %105, align 8, !tbaa !9
  %107 = load i32, ptr %1, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [90601 x double], ptr @psiy, i64 0, i64 %108
  %110 = load double, ptr %109, align 8, !tbaa !9
  %111 = fadd double %106, %110
  %112 = fmul double 5.000000e-01, %111
  %113 = load i32, ptr %1, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [90601 x double], ptr @psi, i64 0, i64 %114
  store double %112, ptr %115, align 8, !tbaa !9
  %116 = load i32, ptr %1, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [90601 x double], ptr @psi, i64 0, i64 %117
  %119 = load double, ptr %118, align 8, !tbaa !9
  %120 = load double, ptr @psimax, align 8, !tbaa !9
  %121 = fcmp ogt double %119, %120
  br i1 %121, label %122, label %127

122:                                              ; preds = %102
  %123 = load i32, ptr %1, align 4, !tbaa !5
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds [90601 x double], ptr @psi, i64 0, i64 %124
  %126 = load double, ptr %125, align 8, !tbaa !9
  store double %126, ptr @psimax, align 8, !tbaa !9
  br label %127

127:                                              ; preds = %122, %102
  br label %128

128:                                              ; preds = %127
  %129 = load i32, ptr %1, align 4, !tbaa !5
  %130 = add nsw i32 %129, 1
  store i32 %130, ptr %1, align 4, !tbaa !5
  br label %96, !llvm.loop !14

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

@u = external dso_local local_unnamed_addr global [90601 x double], align 16
@v = external dso_local local_unnamed_addr global [90601 x double], align 16
@psix = external dso_local local_unnamed_addr global [90601 x double], align 16
@psiy = external dso_local local_unnamed_addr global [90601 x double], align 16
@psi = external dso_local local_unnamed_addr global [90601 x double], align 16
@dx = external dso_local local_unnamed_addr global double, align 8
@dy = external dso_local local_unnamed_addr global double, align 8
@psimax = external dso_local local_unnamed_addr global double, align 8
@n = external dso_local local_unnamed_addr global i32, align 4
@k = external dso_local local_unnamed_addr global i32, align 4

; 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(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z6psicalv() local_unnamed_addr #1 {
  %1 = load i32, ptr @k, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 1
  %.pre = load i32, ptr @n, align 4
  br i1 %2, label %.preheader.lr.ph, label %._crit_edge31

.preheader.lr.ph:                                 ; preds = %0
  %3 = load double, ptr @dy, align 8
  %4 = load double, ptr @dx, align 8
  %5 = sext i32 %.pre to i64
  %wide.trip.count37 = zext nneg i32 %1 to i64
  %6 = shl nsw i64 %5, 3
  %7 = shl nsw i64 %5, 3
  %8 = getelementptr i8, ptr @psix, i64 %6
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph
  %indvar = phi i64 [ %indvar.next, %._crit_edge.us ], [ 0, %.preheader.lr.ph ]
  %indvars.iv34 = phi i64 [ %indvars.iv.next35, %._crit_edge.us ], [ 1, %.preheader.lr.ph ]
  %9 = mul i64 %7, %indvar
  %scevgep = getelementptr i8, ptr %8, i64 %9
  %10 = add nsw i64 %indvars.iv34, -1
  %11 = mul nsw i64 %10, %5
  %12 = mul nsw i64 %indvars.iv34, %5
  %load_initial = load double, ptr %scevgep, align 8
  br label %13

13:                                               ; preds = %.preheader.us, %13
  %store_forwarded = phi double [ %load_initial, %.preheader.us ], [ %34, %13 ]
  %indvars.iv = phi i64 [ 1, %.preheader.us ], [ %indvars.iv.next, %13 ]
  %14 = add nsw i64 %11, %indvars.iv
  %15 = getelementptr inbounds [90601 x double], ptr @psiy, i64 0, i64 %14
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = add nsw i64 %12, %indvars.iv
  %18 = getelementptr inbounds [90601 x double], ptr @u, i64 0, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds [90601 x double], ptr @u, i64 0, i64 %14
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fadd double %19, %21
  %23 = fmul double %22, 5.000000e-01
  %24 = tail call double @llvm.fmuladd.f64(double %23, double %3, double %16)
  %25 = getelementptr inbounds [90601 x double], ptr @psiy, i64 0, i64 %17
  store double %24, ptr %25, align 8, !tbaa !9
  %26 = add nsw i64 %indvars.iv, -1
  %27 = add nsw i64 %26, %12
  %28 = getelementptr inbounds [90601 x double], ptr @v, i64 0, i64 %17
  %29 = load double, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds [90601 x double], ptr @v, i64 0, i64 %27
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = fadd double %29, %31
  %33 = fmul double %32, -5.000000e-01
  %34 = tail call double @llvm.fmuladd.f64(double %33, double %4, double %store_forwarded)
  %35 = getelementptr inbounds [90601 x double], ptr @psix, i64 0, i64 %17
  store double %34, ptr %35, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count37
  br i1 %exitcond.not, label %._crit_edge.us, label %13, !llvm.loop !11

._crit_edge.us:                                   ; preds = %13
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  %indvar.next = add i64 %indvar, 1
  br i1 %exitcond38.not, label %._crit_edge31, label %.preheader.us, !llvm.loop !13

._crit_edge31:                                    ; preds = %._crit_edge.us, %0
  store double -1.000000e+00, ptr @psimax, align 8, !tbaa !9
  %.not = icmp eq i32 %.pre, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %._crit_edge31
  %36 = mul i32 %.pre, %.pre
  %umax = tail call i32 @llvm.umax.i32(i32 %36, i32 1)
  %wide.trip.count42 = zext i32 %umax to i64
  %xtraiter = and i64 %wide.trip.count42, 1
  %37 = icmp ult i32 %36, 2
  br i1 %37, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count42, 4294967294
  br label %.lr.ph

.lr.ph:                                           ; preds = %58, %.lr.ph.preheader.new
  %indvars.iv39 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next40.1, %58 ]
  %38 = phi double [ -1.000000e+00, %.lr.ph.preheader.new ], [ %59, %58 ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %58 ]
  %39 = getelementptr inbounds [90601 x double], ptr @psix, i64 0, i64 %indvars.iv39
  %40 = load double, ptr %39, align 16, !tbaa !9
  %41 = getelementptr inbounds [90601 x double], ptr @psiy, i64 0, i64 %indvars.iv39
  %42 = load double, ptr %41, align 16, !tbaa !9
  %43 = fadd double %40, %42
  %44 = fmul double %43, 5.000000e-01
  %45 = getelementptr inbounds [90601 x double], ptr @psi, i64 0, i64 %indvars.iv39
  store double %44, ptr %45, align 16, !tbaa !9
  %46 = fcmp ogt double %44, %38
  br i1 %46, label %47, label %.lr.ph.1

47:                                               ; preds = %.lr.ph
  store double %44, ptr @psimax, align 8, !tbaa !9
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph, %47
  %48 = phi double [ %38, %.lr.ph ], [ %44, %47 ]
  %indvars.iv.next40 = or disjoint i64 %indvars.iv39, 1
  %49 = getelementptr inbounds [90601 x double], ptr @psix, i64 0, i64 %indvars.iv.next40
  %50 = load double, ptr %49, align 8, !tbaa !9
  %51 = getelementptr inbounds [90601 x double], ptr @psiy, i64 0, i64 %indvars.iv.next40
  %52 = load double, ptr %51, align 8, !tbaa !9
  %53 = fadd double %50, %52
  %54 = fmul double %53, 5.000000e-01
  %55 = getelementptr inbounds [90601 x double], ptr @psi, i64 0, i64 %indvars.iv.next40
  store double %54, ptr %55, align 8, !tbaa !9
  %56 = fcmp ogt double %54, %48
  br i1 %56, label %57, label %58

57:                                               ; preds = %.lr.ph.1
  store double %54, ptr @psimax, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %57, %.lr.ph.1
  %59 = phi double [ %48, %.lr.ph.1 ], [ %54, %57 ]
  %indvars.iv.next40.1 = add nuw nsw i64 %indvars.iv39, 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 !14

._crit_edge.loopexit.unr-lcssa:                   ; preds = %58, %.lr.ph.preheader
  %indvars.iv39.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next40.1, %58 ]
  %.unr = phi double [ -1.000000e+00, %.lr.ph.preheader ], [ %59, %58 ]
  %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
  %60 = getelementptr inbounds [90601 x double], ptr @psix, i64 0, i64 %indvars.iv39.unr
  %61 = load double, ptr %60, align 8, !tbaa !9
  %62 = getelementptr inbounds [90601 x double], ptr @psiy, i64 0, i64 %indvars.iv39.unr
  %63 = load double, ptr %62, align 8, !tbaa !9
  %64 = fadd double %61, %63
  %65 = fmul double %64, 5.000000e-01
  %66 = getelementptr inbounds [90601 x double], ptr @psi, i64 0, i64 %indvars.iv39.unr
  store double %65, ptr %66, align 8, !tbaa !9
  %67 = fcmp ogt double %65, %.unr
  br i1 %67, label %68, label %._crit_edge

68:                                               ; preds = %.lr.ph.epil
  store double %65, ptr @psimax, align 8, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %68, %.lr.ph.epil, %._crit_edge31
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #2

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

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


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