; LLVM IR from manishbisht/Competitive-Programming :: Spoj/Practice/CPP/prata-roti.ll (Z9isParathaxxPxx)

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

; 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 noundef zeroext i1 @_Z9isParathaxxPxx(i64 noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  store i64 0, ptr %11, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %43, %4
  %15 = load i64, ptr %11, align 8, !tbaa !5
  %16 = load i64, ptr %8, align 8, !tbaa !5
  %17 = icmp slt i64 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %46

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %20 = load ptr, ptr %7, align 8, !tbaa !9
  %21 = load i64, ptr %11, align 8, !tbaa !5
  %22 = getelementptr inbounds i64, ptr %20, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  store i64 %23, ptr %12, align 8, !tbaa !5
  %24 = load i64, ptr %12, align 8, !tbaa !5
  store i64 %24, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  store i64 2, ptr %13, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %29, %19
  %26 = load i64, ptr %9, align 8, !tbaa !5
  %27 = load i64, ptr %5, align 8, !tbaa !5
  %28 = icmp sle i64 %26, %27
  br i1 %28, label %29, label %42

29:                                               ; preds = %25
  %30 = load i64, ptr %10, align 8, !tbaa !5
  %31 = add nsw i64 %30, 1
  store i64 %31, ptr %10, align 8, !tbaa !5
  %32 = load i64, ptr %9, align 8, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !9
  %34 = load i64, ptr %11, align 8, !tbaa !5
  %35 = getelementptr inbounds i64, ptr %33, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !5
  %37 = load i64, ptr %13, align 8, !tbaa !5
  %38 = mul nsw i64 %36, %37
  %39 = add nsw i64 %32, %38
  store i64 %39, ptr %9, align 8, !tbaa !5
  %40 = load i64, ptr %13, align 8, !tbaa !5
  %41 = add nsw i64 %40, 1
  store i64 %41, ptr %13, align 8, !tbaa !5
  br label %25, !llvm.loop !11

42:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %11, align 8, !tbaa !5
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %11, align 8, !tbaa !5
  br label %14, !llvm.loop !13

46:                                               ; preds = %18
  %47 = load i64, ptr %6, align 8, !tbaa !5
  %48 = load i64, ptr %10, align 8, !tbaa !5
  %49 = icmp sle i64 %47, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i1 %49
}

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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef zeroext i1 @_Z9isParathaxxPxx(i64 noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i64 %3, 0
  br i1 %5, label %.lr.ph25.preheader, label %._crit_edge26

.lr.ph25.preheader:                               ; preds = %4
  %xtraiter = and i64 %3, 1
  %6 = icmp eq i64 %3, 1
  br i1 %6, label %._crit_edge26.loopexit.unr-lcssa, label %.lr.ph25.preheader.new

.lr.ph25.preheader.new:                           ; preds = %.lr.ph25.preheader
  %unroll_iter = and i64 %3, 9223372036854775806
  br label %.lr.ph25

._crit_edge26.loopexit.unr-lcssa:                 ; preds = %._crit_edge.1, %.lr.ph25.preheader
  %.1.lcssa.lcssa.ph = phi i64 [ poison, %.lr.ph25.preheader ], [ %.1.lcssa.1, %._crit_edge.1 ]
  %.01623.unr = phi i64 [ 0, %.lr.ph25.preheader ], [ %27, %._crit_edge.1 ]
  %.01722.unr = phi i64 [ 0, %.lr.ph25.preheader ], [ %.1.lcssa.1, %._crit_edge.1 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge26, label %.lr.ph25.epil

.lr.ph25.epil:                                    ; preds = %._crit_edge26.loopexit.unr-lcssa
  %7 = getelementptr inbounds i64, ptr %2, i64 %.01623.unr
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %.not18.epil = icmp sgt i64 %8, %0
  br i1 %.not18.epil, label %._crit_edge26, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.lr.ph25.epil, %.lr.ph.epil
  %.021.epil = phi i64 [ %12, %.lr.ph.epil ], [ 2, %.lr.ph25.epil ]
  %.01520.epil = phi i64 [ %11, %.lr.ph.epil ], [ %8, %.lr.ph25.epil ]
  %.119.epil = phi i64 [ %9, %.lr.ph.epil ], [ %.01722.unr, %.lr.ph25.epil ]
  %9 = add nsw i64 %.119.epil, 1
  %10 = mul nsw i64 %.021.epil, %8
  %11 = add nsw i64 %10, %.01520.epil
  %12 = add nuw nsw i64 %.021.epil, 1
  %.not.epil = icmp sgt i64 %11, %0
  br i1 %.not.epil, label %._crit_edge26, label %.lr.ph.epil, !llvm.loop !9

._crit_edge26:                                    ; preds = %._crit_edge26.loopexit.unr-lcssa, %.lr.ph.epil, %.lr.ph25.epil, %4
  %.017.lcssa = phi i64 [ 0, %4 ], [ %.1.lcssa.lcssa.ph, %._crit_edge26.loopexit.unr-lcssa ], [ %.01722.unr, %.lr.ph25.epil ], [ %9, %.lr.ph.epil ]
  %13 = icmp sge i64 %.017.lcssa, %1
  ret i1 %13

.lr.ph25:                                         ; preds = %._crit_edge.1, %.lr.ph25.preheader.new
  %.01623 = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %27, %._crit_edge.1 ]
  %.01722 = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %.1.lcssa.1, %._crit_edge.1 ]
  %niter = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %niter.next.1, %._crit_edge.1 ]
  %14 = getelementptr inbounds i64, ptr %2, i64 %.01623
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %.not18 = icmp sgt i64 %15, %0
  br i1 %.not18, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph25, %.lr.ph
  %.021 = phi i64 [ %19, %.lr.ph ], [ 2, %.lr.ph25 ]
  %.01520 = phi i64 [ %18, %.lr.ph ], [ %15, %.lr.ph25 ]
  %.119 = phi i64 [ %16, %.lr.ph ], [ %.01722, %.lr.ph25 ]
  %16 = add nsw i64 %.119, 1
  %17 = mul nsw i64 %.021, %15
  %18 = add nsw i64 %17, %.01520
  %19 = add nuw nsw i64 %.021, 1
  %.not = icmp sgt i64 %18, %0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph25
  %.1.lcssa = phi i64 [ %.01722, %.lr.ph25 ], [ %16, %.lr.ph ]
  %20 = or disjoint i64 %.01623, 1
  %21 = getelementptr inbounds i64, ptr %2, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %.not18.1 = icmp sgt i64 %22, %0
  br i1 %.not18.1, label %._crit_edge.1, label %.lr.ph.1

.lr.ph.1:                                         ; preds = %._crit_edge, %.lr.ph.1
  %.021.1 = phi i64 [ %26, %.lr.ph.1 ], [ 2, %._crit_edge ]
  %.01520.1 = phi i64 [ %25, %.lr.ph.1 ], [ %22, %._crit_edge ]
  %.119.1 = phi i64 [ %23, %.lr.ph.1 ], [ %.1.lcssa, %._crit_edge ]
  %23 = add nsw i64 %.119.1, 1
  %24 = mul nsw i64 %.021.1, %22
  %25 = add nsw i64 %24, %.01520.1
  %26 = add nuw nsw i64 %.021.1, 1
  %.not.1 = icmp sgt i64 %25, %0
  br i1 %.not.1, label %._crit_edge.1, label %.lr.ph.1, !llvm.loop !9

._crit_edge.1:                                    ; preds = %.lr.ph.1, %._crit_edge
  %.1.lcssa.1 = phi i64 [ %.1.lcssa, %._crit_edge ], [ %23, %.lr.ph.1 ]
  %27 = add nuw nsw i64 %.01623, 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_edge26.loopexit.unr-lcssa, label %.lr.ph25, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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 = !{!"long long", !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}


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