; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/402 Division 1/A/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"

%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@a = external dso_local global [200100 x i32], align 16
@bad = external dso_local global [200100 x i32], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@_Z1pB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_Z1tB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z1fi(i32 noundef %0) #0 {
  %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
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %16, %1
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr @m, 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 %3) #3
  br label %19

12:                                               ; preds = %7
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [200100 x i32], ptr @bad, i64 0, i64 %14
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %12
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %3, align 4, !tbaa !5
  br label %7, !llvm.loop !9

19:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %32, %19
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %35

25:                                               ; preds = %20
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200100 x i32], ptr @bad, i64 0, i64 %30
  store i32 1, ptr %31, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %25
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %4, align 4, !tbaa !5
  br label %20, !llvm.loop !11

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

36:                                               ; preds = %70, %35
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = load i32, ptr @m, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %44

40:                                               ; preds = %36
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = icmp slt i32 %41, %42
  br label %44

44:                                               ; preds = %40, %36
  %45 = phi i1 [ false, %36 ], [ %43, %40 ]
  br i1 %45, label %47, label %46

46:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %73

47:                                               ; preds = %44
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [200100 x i32], ptr @bad, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %47
  br label %70

54:                                               ; preds = %47
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1tB5cxx11, i64 noundef %56)
  %58 = load i8, ptr %57, align 1, !tbaa !12
  %59 = sext i8 %58 to i32
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1pB5cxx11, i64 noundef %61)
  %63 = load i8, ptr %62, align 1, !tbaa !12
  %64 = sext i8 %63 to i32
  %65 = icmp eq i32 %59, %64
  br i1 %65, label %66, label %69

66:                                               ; preds = %54
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %5, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %66, %54
  br label %70

70:                                               ; preds = %69, %53
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %6, align 4, !tbaa !5
  br label %36, !llvm.loop !13

73:                                               ; preds = %46
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = load i32, ptr @n, align 4, !tbaa !5
  %76 = icmp eq i32 %74, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i1 %76
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #2 align 2

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 nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !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"

%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@a = external dso_local local_unnamed_addr global [200100 x i32], align 16
@bad = external dso_local local_unnamed_addr global [200100 x i32], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@_Z1pB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_Z1tB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z1fi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @m, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph.preheader, label %.preheader19

.lr.ph.preheader:                                 ; preds = %1
  %4 = zext nneg i32 %2 to i64
  %5 = shl nuw nsw i64 %4, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @bad, i8 0, i64 %5, i1 false), !tbaa !5
  br label %.preheader19

.preheader19:                                     ; preds = %.lr.ph.preheader, %1
  %.not21 = icmp slt i32 %0, 1
  br i1 %.not21, label %.preheader, label %.lr.ph23.preheader

.lr.ph23.preheader:                               ; preds = %.preheader19
  %6 = zext nneg i32 %0 to i64
  %xtraiter = and i64 %6, 3
  %7 = icmp ult i32 %0, 4
  br i1 %7, label %.preheader.loopexit.unr-lcssa, label %.lr.ph23.preheader.new

.lr.ph23.preheader.new:                           ; preds = %.lr.ph23.preheader
  %unroll_iter = and i64 %6, 2147483644
  br label %.lr.ph23

.preheader.loopexit.unr-lcssa:                    ; preds = %.lr.ph23, %.lr.ph23.preheader
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph23.preheader ], [ %indvars.iv.next.3, %.lr.ph23 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph23.epil

.lr.ph23.epil:                                    ; preds = %.preheader.loopexit.unr-lcssa, %.lr.ph23.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph23.epil ], [ %indvars.iv.unr, %.preheader.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph23.epil ], [ 0, %.preheader.loopexit.unr-lcssa ]
  %8 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %indvars.iv.epil
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [200100 x i32], ptr @bad, i64 0, i64 %10
  store i32 1, ptr %11, align 4, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.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 %.preheader, label %.lr.ph23.epil, !llvm.loop !9

.preheader:                                       ; preds = %.preheader.loopexit.unr-lcssa, %.lr.ph23.epil, %.preheader19
  %12 = load i32, ptr @n, align 4
  %13 = icmp sgt i32 %12, 0
  %14 = select i1 %3, i1 %13, i1 false
  br i1 %14, label %.lr.ph26, label %._crit_edge

.lr.ph23:                                         ; preds = %.lr.ph23, %.lr.ph23.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph23.preheader.new ], [ %indvars.iv.next.3, %.lr.ph23 ]
  %niter = phi i64 [ 0, %.lr.ph23.preheader.new ], [ %niter.next.3, %.lr.ph23 ]
  %15 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [200100 x i32], ptr @bad, i64 0, i64 %17
  store i32 1, ptr %18, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %indvars.iv.next
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [200100 x i32], ptr @bad, i64 0, i64 %21
  store i32 1, ptr %22, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %23 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %indvars.iv.next.1
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [200100 x i32], ptr @bad, i64 0, i64 %25
  store i32 1, ptr %26, align 4, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %27 = getelementptr inbounds [200100 x i32], ptr @a, i64 0, i64 %indvars.iv.next.2
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [200100 x i32], ptr @bad, i64 0, i64 %29
  store i32 1, ptr %30, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader.loopexit.unr-lcssa, label %.lr.ph23, !llvm.loop !11

._crit_edge:                                      ; preds = %44, %.preheader
  %.015.lcssa = phi i32 [ 0, %.preheader ], [ %.1, %44 ]
  %.lcssa = phi i32 [ %12, %.preheader ], [ %45, %44 ]
  %31 = icmp eq i32 %.015.lcssa, %.lcssa
  ret i1 %31

.lr.ph26:                                         ; preds = %.preheader, %44
  %32 = phi i32 [ %45, %44 ], [ %12, %.preheader ]
  %33 = phi i32 [ %46, %44 ], [ %2, %.preheader ]
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %44 ], [ 0, %.preheader ]
  %.01524 = phi i32 [ %.1, %44 ], [ 0, %.preheader ]
  %34 = getelementptr inbounds [200100 x i32], ptr @bad, i64 0, i64 %indvars.iv31
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %.not18 = icmp eq i32 %35, 0
  br i1 %.not18, label %36, label %44

36:                                               ; preds = %.lr.ph26
  %37 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1tB5cxx11, i64 noundef %indvars.iv31)
  %38 = load i8, ptr %37, align 1, !tbaa !13
  %39 = sext i32 %.01524 to i64
  %40 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1pB5cxx11, i64 noundef %39)
  %41 = load i8, ptr %40, align 1, !tbaa !13
  %42 = icmp eq i8 %38, %41
  %43 = zext i1 %42 to i32
  %spec.select = add nsw i32 %.01524, %43
  %.pre = load i32, ptr @m, align 4, !tbaa !5
  %.pre34 = load i32, ptr @n, align 4
  br label %44

44:                                               ; preds = %36, %.lr.ph26
  %45 = phi i32 [ %32, %.lr.ph26 ], [ %.pre34, %36 ]
  %46 = phi i32 [ %33, %.lr.ph26 ], [ %.pre, %36 ]
  %.1 = phi i32 [ %.01524, %.lr.ph26 ], [ %spec.select, %36 ]
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %47 = sext i32 %46 to i64
  %48 = icmp slt i64 %indvars.iv.next32, %47
  %49 = icmp slt i32 %.1, %45
  %50 = select i1 %48, i1 %49, i1 false
  br i1 %50, label %.lr.ph26, label %._crit_edge, !llvm.loop !14
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 2

; 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 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 #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.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !12}


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