; LLVM IR from Muhammad-Magdi/problem-solving :: LIS.ll (Z10rollingLISv)

; 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 dso_local global i32, align 4
@A = external dso_local global [1009 x i32], align 16
@rdp = external dso_local global [2 x [1009 x i32]], 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

; 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 noundef i32 @_Z10rollingLISv() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %27, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = load i32, ptr @n, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %30

12:                                               ; preds = %7
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  %15 = xor i1 %14, true
  %16 = zext i1 %15 to i64
  %17 = getelementptr inbounds [2 x [1009 x i32]], ptr @rdp, i64 0, i64 %16
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1009 x i32], ptr %17, i64 0, i64 %19
  store i32 0, ptr %20, align 4, !tbaa !5
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2 x [1009 x i32]], ptr @rdp, i64 0, i64 %22
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1009 x i32], ptr %23, i64 0, i64 %25
  store i32 0, ptr %26, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %12
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !9

30:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  store i32 %32, ptr %3, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %95, %30
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = xor i32 %34, -1
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %98

38:                                               ; preds = %33
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = icmp ne i32 %39, 0
  %41 = xor i1 %40, true
  %42 = zext i1 %41 to i32
  store i32 %42, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %43 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %43, ptr %5, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %91, %38
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = xor i32 %45, -1
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %49, label %48

48:                                               ; preds = %44
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %94

49:                                               ; preds = %44
  %50 = load i32, ptr %1, align 4, !tbaa !5
  %51 = icmp ne i32 %50, 0
  %52 = xor i1 %51, true
  %53 = zext i1 %52 to i64
  %54 = getelementptr inbounds [2 x [1009 x i32]], ptr @rdp, i64 0, i64 %53
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1009 x i32], ptr %54, i64 0, i64 %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = load i32, ptr @n, align 4, !tbaa !5
  %60 = icmp eq i32 %58, %59
  br i1 %60, label %71, label %61

61:                                               ; preds = %49
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1009 x i32], ptr @A, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [1009 x i32], ptr @A, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = icmp sgt i32 %65, %69
  br i1 %70, label %71, label %80

71:                                               ; preds = %61, %49
  %72 = load i32, ptr %1, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [2 x [1009 x i32]], ptr @rdp, i64 0, i64 %73
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [1009 x i32], ptr %74, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  br label %81

80:                                               ; preds = %61
  br label %81

81:                                               ; preds = %80, %71
  %82 = phi i32 [ %79, %71 ], [ 0, %80 ]
  store i32 %82, ptr %6, align 4, !tbaa !5
  %83 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %57, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = load i32, ptr %1, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [2 x [1009 x i32]], ptr @rdp, i64 0, i64 %86
  %88 = load i32, ptr %5, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [1009 x i32], ptr %87, i64 0, i64 %89
  store i32 %84, ptr %90, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %91

91:                                               ; preds = %81
  %92 = load i32, ptr %5, align 4, !tbaa !5
  %93 = add nsw i32 %92, -1
  store i32 %93, ptr %5, align 4, !tbaa !5
  br label %44, !llvm.loop !11

94:                                               ; preds = %48
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %3, align 4, !tbaa !5
  %97 = add nsw i32 %96, -1
  store i32 %97, ptr %3, align 4, !tbaa !5
  br label %33, !llvm.loop !12

98:                                               ; preds = %37
  %99 = load i32, ptr %1, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [2 x [1009 x i32]], ptr @rdp, i64 0, i64 %100
  %102 = load i32, ptr @n, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [1009 x i32], ptr %101, i64 0, i64 %103
  %105 = load i32, ptr %104, align 4, !tbaa !5
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret i32 %105
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; 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 dso_local local_unnamed_addr global i32, align 4
@A = external dso_local local_unnamed_addr global [1009 x i32], align 16
@rdp = external dso_local global [2 x [1009 x i32]], align 16

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) 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 nounwind uwtable
define dso_local noundef i32 @_Z10rollingLISv() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not28 = icmp slt i32 %2, 0
  br i1 %.not28, label %.lr.ph37, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %3 = add nuw i32 %2, 1
  %wide.trip.count = zext i32 %3 to i64
  %min.iters.check = icmp ult i32 %2, 7
  br i1 %min.iters.check, label %.lr.ph.preheader49, label %vector.ph

.lr.ph.preheader49:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 4294967288
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %4 = getelementptr inbounds [1009 x i32], ptr getelementptr inbounds (i8, ptr @rdp, i64 4036), i64 0, i64 %index
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  store <4 x i32> zeroinitializer, ptr %4, align 4, !tbaa !5
  store <4 x i32> zeroinitializer, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds [1009 x i32], ptr @rdp, i64 0, i64 %index
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  store <4 x i32> zeroinitializer, ptr %6, align 16, !tbaa !5
  store <4 x i32> zeroinitializer, ptr %7, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %8 = icmp eq i64 %index.next, %n.vec
  br i1 %8, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.preheader, label %.lr.ph.preheader49

.preheader:                                       ; preds = %.lr.ph, %middle.block
  %cond = icmp eq i32 %2, 0
  br i1 %cond, label %._crit_edge, label %.lr.ph37.split.preheader

.lr.ph37:                                         ; preds = %0
  %9 = icmp ne i32 %2, -1
  tail call void @llvm.assume(i1 %9)
  br label %.lr.ph37.split.preheader

.lr.ph37.split.preheader:                         ; preds = %.preheader, %.lr.ph37
  %.02133 = add i32 %2, -1
  %10 = sext i32 %.02133 to i64
  br label %.lr.ph37.split

.lr.ph:                                           ; preds = %.lr.ph.preheader49, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader49 ]
  %11 = getelementptr inbounds [1009 x i32], ptr getelementptr inbounds (i8, ptr @rdp, i64 4036), i64 0, i64 %indvars.iv
  store i32 0, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds [1009 x i32], ptr @rdp, i64 0, i64 %indvars.iv
  store i32 0, ptr %12, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !13

.loopexit:                                        ; preds = %39, %.lr.ph37.split
  %indvars.iv.next46 = add nsw i64 %indvars.iv45, -1
  %13 = icmp eq i64 %indvars.iv45, 0
  br i1 %13, label %._crit_edge.loopexit39, label %.lr.ph37.split, !llvm.loop !14

._crit_edge.loopexit39:                           ; preds = %.loopexit
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  %14 = zext nneg i32 %19 to i64
  %15 = sext i32 %.pre to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.preheader, %._crit_edge.loopexit39
  %16 = phi i64 [ 0, %.preheader ], [ %15, %._crit_edge.loopexit39 ]
  %.023.lcssa = phi i64 [ 0, %.preheader ], [ %14, %._crit_edge.loopexit39 ]
  %17 = getelementptr inbounds [2 x [1009 x i32]], ptr @rdp, i64 0, i64 %.023.lcssa, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  ret i32 %18

.lr.ph37.split:                                   ; preds = %.lr.ph37.split.preheader, %.loopexit
  %indvars.iv45 = phi i64 [ %10, %.lr.ph37.split.preheader ], [ %indvars.iv.next46, %.loopexit ]
  %.02335 = phi i32 [ 0, %.lr.ph37.split.preheader ], [ %19, %.loopexit ]
  %19 = xor i32 %.02335, 1
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %.not2630 = icmp eq i32 %20, -1
  br i1 %.not2630, label %.loopexit, label %.lr.ph32

.lr.ph32:                                         ; preds = %.lr.ph37.split
  %21 = zext nneg i32 %.02335 to i64
  %22 = getelementptr inbounds [1009 x i32], ptr @A, i64 0, i64 %indvars.iv45
  %23 = zext nneg i32 %19 to i64
  %24 = getelementptr inbounds [2 x [1009 x i32]], ptr @rdp, i64 0, i64 %23, i64 %indvars.iv45
  %25 = sext i32 %20 to i64
  br label %26

26:                                               ; preds = %.lr.ph32, %39
  %indvars.iv42 = phi i64 [ %25, %.lr.ph32 ], [ %indvars.iv.next43, %39 ]
  %27 = getelementptr inbounds [2 x [1009 x i32]], ptr @rdp, i64 0, i64 %21, i64 %indvars.iv42
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = trunc nsw i64 %indvars.iv42 to i32
  %30 = icmp eq i32 %28, %29
  br i1 %30, label %36, label %31

31:                                               ; preds = %26
  %32 = load i32, ptr %22, align 4, !tbaa !5
  %33 = getelementptr inbounds [1009 x i32], ptr @A, i64 0, i64 %indvars.iv42
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = icmp sgt i32 %32, %34
  br i1 %35, label %36, label %39

36:                                               ; preds = %31, %26
  %37 = load i32, ptr %24, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  br label %39

39:                                               ; preds = %31, %36
  %40 = phi i32 [ %38, %36 ], [ 0, %31 ]
  store i32 %40, ptr %1, align 4, !tbaa !5
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %27, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = getelementptr inbounds [2 x [1009 x i32]], ptr @rdp, i64 0, i64 %23, i64 %indvars.iv42
  store i32 %42, ptr %43, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %indvars.iv.next43 = add nsw i64 %indvars.iv42, -1
  %44 = icmp eq i64 %indvars.iv42, 0
  br i1 %44, label %.loopexit, label %26, !llvm.loop !16
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #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 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}
!14 = distinct !{!14, !10, !15}
!15 = !{!"llvm.loop.unswitch.partial.disable"}
!16 = distinct !{!16, !10}


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