; LLVM IR from reyadussalahin/problem-solving :: data_structure/segment_tree/loj/F1135/Solution.ll (Z4lazyii)

; 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 dso_local global [3 x [400040 x i32]], align 16
@u = external dso_local global [400040 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: 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 void @_Z4lazyii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %44, %2
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [400040 x i32], ptr getelementptr inbounds ([3 x [400040 x i32]], ptr @b, i64 0, i64 2), i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %16, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [400040 x i32], ptr getelementptr inbounds ([3 x [400040 x i32]], ptr @b, i64 0, i64 1), i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [400040 x i32], ptr getelementptr inbounds ([3 x [400040 x i32]], ptr @b, i64 0, i64 2), i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [400040 x i32], ptr @b, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [400040 x i32], ptr getelementptr inbounds ([3 x [400040 x i32]], ptr @b, i64 0, i64 1), i64 0, i64 %29
  store i32 %27, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [400040 x i32], ptr @b, i64 0, i64 %33
  store i32 %31, ptr %34, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [400040 x i32], ptr @u, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  %40 = srem i32 %39, 3
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [400040 x i32], ptr @u, i64 0, i64 %42
  store i32 %40, ptr %43, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %44

44:                                               ; preds = %12
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %5, align 4, !tbaa !5
  br label %7, !llvm.loop !9

47:                                               ; preds = %11
  ret void
}

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


; 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 dso_local local_unnamed_addr global [3 x [400040 x i32]], align 16
@u = external dso_local local_unnamed_addr global [400040 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4lazyii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 0
  br i1 %3, label %.lr.ph, label %16

.lr.ph:                                           ; preds = %2
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [400040 x i32], ptr getelementptr inbounds (i8, ptr @b, i64 3200320), i64 0, i64 %4
  %6 = getelementptr inbounds [400040 x i32], ptr getelementptr inbounds (i8, ptr @b, i64 1600160), i64 0, i64 %4
  %7 = getelementptr inbounds [400040 x i32], ptr @b, i64 0, i64 %4
  %8 = getelementptr inbounds [400040 x i32], ptr @u, i64 0, i64 %4
  %.promoted = load i32, ptr %5, align 4, !tbaa !5
  %.promoted13 = load i32, ptr %6, align 4, !tbaa !5
  %.promoted15 = load i32, ptr %7, align 4, !tbaa !5
  %.promoted17 = load i32, ptr %8, align 4, !tbaa !5
  %xtraiter = and i32 %1, 3
  %9 = icmp ult i32 %1, 4
  br i1 %9, label %._crit_edge.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i32 %1, 2147483644
  br label %17

._crit_edge.unr-lcssa:                            ; preds = %17, %.lr.ph
  %.lcssa30.ph = phi i32 [ poison, %.lr.ph ], [ %19, %17 ]
  %.lcssa29.ph = phi i32 [ poison, %.lr.ph ], [ %20, %17 ]
  %.lcssa28.ph = phi i32 [ poison, %.lr.ph ], [ %21, %17 ]
  %.lcssa.ph = phi i32 [ poison, %.lr.ph ], [ %29, %17 ]
  %.unr = phi i32 [ %.promoted17, %.lr.ph ], [ %29, %17 ]
  %.unr31 = phi i32 [ %.promoted15, %.lr.ph ], [ %21, %17 ]
  %.unr32 = phi i32 [ %.promoted13, %.lr.ph ], [ %19, %17 ]
  %.unr33 = phi i32 [ %.promoted, %.lr.ph ], [ %20, %17 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.unr-lcssa, %.epil.preheader
  %10 = phi i32 [ %15, %.epil.preheader ], [ %.unr, %._crit_edge.unr-lcssa ]
  %11 = phi i32 [ %13, %.epil.preheader ], [ %.unr31, %._crit_edge.unr-lcssa ]
  %12 = phi i32 [ %11, %.epil.preheader ], [ %.unr32, %._crit_edge.unr-lcssa ]
  %13 = phi i32 [ %12, %.epil.preheader ], [ %.unr33, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.unr-lcssa ]
  %14 = add nsw i32 %10, 1
  %15 = srem i32 %14, 3
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %.epil.preheader, %._crit_edge.unr-lcssa
  %.lcssa30 = phi i32 [ %.lcssa30.ph, %._crit_edge.unr-lcssa ], [ %11, %.epil.preheader ]
  %.lcssa29 = phi i32 [ %.lcssa29.ph, %._crit_edge.unr-lcssa ], [ %12, %.epil.preheader ]
  %.lcssa28 = phi i32 [ %.lcssa28.ph, %._crit_edge.unr-lcssa ], [ %13, %.epil.preheader ]
  %.lcssa = phi i32 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %15, %.epil.preheader ]
  store i32 %.lcssa29, ptr %5, align 4, !tbaa !5
  store i32 %.lcssa30, ptr %6, align 4, !tbaa !5
  store i32 %.lcssa28, ptr %7, align 4, !tbaa !5
  store i32 %.lcssa, ptr %8, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %._crit_edge, %2
  ret void

17:                                               ; preds = %17, %.lr.ph.new
  %18 = phi i32 [ %.promoted17, %.lr.ph.new ], [ %29, %17 ]
  %19 = phi i32 [ %.promoted15, %.lr.ph.new ], [ %21, %17 ]
  %20 = phi i32 [ %.promoted13, %.lr.ph.new ], [ %19, %17 ]
  %21 = phi i32 [ %.promoted, %.lr.ph.new ], [ %20, %17 ]
  %niter = phi i32 [ 0, %.lr.ph.new ], [ %niter.next.3, %17 ]
  %22 = add nsw i32 %18, 1
  %23 = srem i32 %22, 3
  %24 = add nsw i32 %23, 1
  %25 = srem i32 %24, 3
  %26 = add nsw i32 %25, 1
  %27 = srem i32 %26, 3
  %28 = add nsw i32 %27, 1
  %29 = srem i32 %28, 3
  %niter.next.3 = add i32 %niter, 4
  %niter.ncmp.3 = icmp eq i32 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.unr-lcssa, label %17, !llvm.loop !11
}

attributes #0 = { 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" }

!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.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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