; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/LONG/AUG15/STETSKLX/A.ll (Z1fi)

; 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
@r = external dso_local global i32, align 4
@gp = external dso_local global [100100 x [51 x i32]], align 16
@ok = external dso_local global i8, align 1

; 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 uwtable
declare dso_local void @_Z3dfsii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z1fi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %28, %1
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %31

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %24, %11
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr @r, align 4, !tbaa !5
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %27

17:                                               ; preds = %12
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100100 x [51 x i32]], ptr @gp, i64 0, i64 %19
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [51 x i32], ptr %20, i64 0, i64 %22
  store i32 0, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %17
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %5, align 4, !tbaa !5
  br label %12, !llvm.loop !9

27:                                               ; preds = %16
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %3, align 4, !tbaa !5
  br label %6, !llvm.loop !11

31:                                               ; preds = %10
  store i8 0, ptr @ok, align 1, !tbaa !12
  %32 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef 1, i32 noundef %32)
  %33 = load i8, ptr @ok, align 1, !tbaa !12, !range !14, !noundef !15
  %34 = trunc i8 %33 to i1
  ret i1 %34
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}


; 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
@r = external dso_local local_unnamed_addr global i32, align 4
@gp = external dso_local local_unnamed_addr global [100100 x [51 x i32]], align 16
@ok = external dso_local local_unnamed_addr global i8, align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z1fi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not11 = icmp slt i32 %2, 1
  br i1 %.not11, label %._crit_edge13, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %1
  %3 = load i32, ptr @r, align 4, !tbaa !5
  %.not89 = icmp slt i32 %3, 0
  br i1 %.not89, label %._crit_edge13, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader.lr.ph
  %4 = add nuw i32 %3, 1
  %5 = zext i32 %4 to i64
  %6 = shl nuw nsw i64 %5, 2
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 7
  %7 = icmp ult i32 %2, 8
  br i1 %7, label %._crit_edge13.loopexit.unr-lcssa, label %.preheader.preheader.new

.preheader.preheader.new:                         ; preds = %.preheader.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483640
  br label %.preheader

.preheader:                                       ; preds = %.preheader, %.preheader.preheader.new
  %indvar = phi i64 [ 0, %.preheader.preheader.new ], [ %indvar.next.7, %.preheader ]
  %niter = phi i64 [ 0, %.preheader.preheader.new ], [ %niter.next.7, %.preheader ]
  %8 = mul nuw nsw i64 %indvar, 204
  %gep = getelementptr i8, ptr getelementptr inbounds (i8, ptr @gp, i64 204), i64 %8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %gep, i8 0, i64 %6, i1 false), !tbaa !5
  %9 = mul nuw i64 %indvar, 204
  %gep16 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @gp, i64 204), i64 204), i64 %9
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %gep16, i8 0, i64 %6, i1 false), !tbaa !5
  %10 = mul nuw i64 %indvar, 204
  %gep17 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @gp, i64 204), i64 408), i64 %10
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %gep17, i8 0, i64 %6, i1 false), !tbaa !5
  %11 = mul nuw i64 %indvar, 204
  %gep18 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @gp, i64 204), i64 612), i64 %11
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %gep18, i8 0, i64 %6, i1 false), !tbaa !5
  %12 = mul nuw i64 %indvar, 204
  %gep19 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @gp, i64 204), i64 816), i64 %12
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %gep19, i8 0, i64 %6, i1 false), !tbaa !5
  %13 = mul nuw i64 %indvar, 204
  %gep20 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @gp, i64 204), i64 1020), i64 %13
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %gep20, i8 0, i64 %6, i1 false), !tbaa !5
  %14 = mul nuw i64 %indvar, 204
  %gep21 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @gp, i64 204), i64 1224), i64 %14
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %gep21, i8 0, i64 %6, i1 false), !tbaa !5
  %15 = mul nuw i64 %indvar, 204
  %gep22 = getelementptr i8, ptr getelementptr (i8, ptr getelementptr inbounds (i8, ptr @gp, i64 204), i64 1428), i64 %15
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1) %gep22, i8 0, i64 %6, i1 false), !tbaa !5
  %indvar.next.7 = add nuw nsw i64 %indvar, 8
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge13.loopexit.unr-lcssa, label %.preheader, !llvm.loop !9

._crit_edge13.loopexit.unr-lcssa:                 ; preds = %.preheader, %.preheader.preheader
  %indvar.unr = phi i64 [ 0, %.preheader.preheader ], [ %indvar.next.7, %.preheader ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge13, label %.preheader.epil

.preheader.epil:                                  ; preds = %._crit_edge13.loopexit.unr-lcssa, %.preheader.epil
  %indvar.epil = phi i64 [ %indvar.next.epil, %.preheader.epil ], [ %indvar.unr, %._crit_edge13.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.preheader.epil ], [ 0, %._crit_edge13.loopexit.unr-lcssa ]
  %16 = mul nuw nsw i64 %indvar.epil, 204
  %gep.epil = getelementptr i8, ptr getelementptr inbounds (i8, ptr @gp, i64 204), i64 %16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %gep.epil, i8 0, i64 %6, i1 false), !tbaa !5
  %indvar.next.epil = add nuw nsw i64 %indvar.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge13, label %.preheader.epil, !llvm.loop !11

._crit_edge13:                                    ; preds = %._crit_edge13.loopexit.unr-lcssa, %.preheader.epil, %.preheader.lr.ph, %1
  store i8 0, ptr @ok, align 1, !tbaa !13
  tail call void @_Z3dfsii(i32 noundef 1, i32 noundef %0)
  %17 = load i8, ptr @ok, align 1, !tbaa !13, !range !15, !noundef !16
  %18 = trunc nuw i8 %17 to i1
  ret i1 %18
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

!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, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass