; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/282 Division 2/Problem D/D.ll (Z3kmpv)

; 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] }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@fail = external dso_local global [100001 x i32], align 16
@found = external dso_local global [100001 x i32], align 16
@_Z1sB5cxx11 = 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 void @_Z3kmpv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 -1, ptr @fail, align 16, !tbaa !5
  store i32 -1, ptr %2, align 4, !tbaa !5
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %40, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = load i32, ptr @m, align 4, !tbaa !5
  %7 = icmp sle i32 %5, %6
  br i1 %7, label %8, label %43

8:                                                ; preds = %4
  br label %9

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

12:                                               ; preds = %9
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1tB5cxx11, i64 noundef %14)
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = sext i8 %16 to i32
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sub nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  %21 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1tB5cxx11, i64 noundef %20)
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %23 = sext i8 %22 to i32
  %24 = icmp ne i32 %17, %23
  br label %25

25:                                               ; preds = %12, %9
  %26 = phi i1 [ false, %9 ], [ %24, %12 ]
  br i1 %26, label %27, label %32

27:                                               ; preds = %25
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100001 x i32], ptr @fail, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !10

32:                                               ; preds = %25
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100001 x i32], ptr @fail, i64 0, i64 %36
  store i32 %34, ptr %37, align 4, !tbaa !5
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %2, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %32
  %41 = load i32, ptr %1, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !12

43:                                               ; preds = %4
  store i32 0, ptr %1, align 4, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %85, %43
  %45 = load i32, ptr %1, align 4, !tbaa !5
  %46 = load i32, ptr @n, align 4, !tbaa !5
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %48, label %88

48:                                               ; preds = %44
  br label %49

49:                                               ; preds = %66, %48
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = icmp sge i32 %50, 0
  br i1 %51, label %52, label %64

52:                                               ; preds = %49
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1tB5cxx11, i64 noundef %54)
  %56 = load i8, ptr %55, align 1, !tbaa !9
  %57 = sext i8 %56 to i32
  %58 = load i32, ptr %1, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %59)
  %61 = load i8, ptr %60, align 1, !tbaa !9
  %62 = sext i8 %61 to i32
  %63 = icmp ne i32 %57, %62
  br label %64

64:                                               ; preds = %52, %49
  %65 = phi i1 [ false, %49 ], [ %63, %52 ]
  br i1 %65, label %66, label %71

66:                                               ; preds = %64
  %67 = load i32, ptr %3, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [100001 x i32], ptr @fail, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  store i32 %70, ptr %3, align 4, !tbaa !5
  br label %49, !llvm.loop !13

71:                                               ; preds = %64
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %3, align 4, !tbaa !5
  %74 = load i32, ptr @m, align 4, !tbaa !5
  %75 = icmp sge i32 %73, %74
  br i1 %75, label %76, label %84

76:                                               ; preds = %71
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [100001 x i32], ptr @fail, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  store i32 %80, ptr %3, align 4, !tbaa !5
  %81 = load i32, ptr %1, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [100001 x i32], ptr @found, i64 0, i64 %82
  store i32 1, ptr %83, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %76, %71
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %1, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %1, align 4, !tbaa !5
  br label %44, !llvm.loop !14

88:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


; 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] }

@n = external dso_local local_unnamed_addr global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@fail = external dso_local local_unnamed_addr global [100001 x i32], align 16
@found = external dso_local local_unnamed_addr global [100001 x i32], align 16
@_Z1sB5cxx11 = 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 void @_Z3kmpv() local_unnamed_addr #0 {
  store i32 -1, ptr @fail, align 16, !tbaa !5
  %1 = load i32, ptr @m, align 4, !tbaa !5
  %.not34 = icmp slt i32 %1, 1
  br i1 %.not34, label %.preheader29, label %.preheader30

.preheader30:                                     ; preds = %0, %.critedge
  %2 = phi i32 [ %18, %.critedge ], [ %1, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.critedge ], [ 1, %0 ]
  %.02036 = phi i32 [ %19, %.critedge ], [ -1, %0 ]
  %3 = icmp sgt i32 %.02036, -1
  br i1 %3, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.preheader30
  %4 = add nsw i64 %indvars.iv, -1
  br label %8

.preheader29:                                     ; preds = %.critedge, %0
  %5 = phi i32 [ %1, %0 ], [ %18, %.critedge ]
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.preheader, label %._crit_edge

8:                                                ; preds = %.lr.ph, %14
  %.12131 = phi i32 [ %.02036, %.lr.ph ], [ %16, %14 ]
  %9 = zext nneg i32 %.12131 to i64
  %10 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1tB5cxx11, i64 noundef %9)
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1tB5cxx11, i64 noundef %4)
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %.not28 = icmp eq i8 %11, %13
  br i1 %.not28, label %.critedge.loopexit, label %14

14:                                               ; preds = %8
  %15 = getelementptr inbounds [100001 x i32], ptr @fail, i64 0, i64 %9
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, -1
  br i1 %17, label %8, label %.critedge.loopexit, !llvm.loop !10

.critedge.loopexit:                               ; preds = %14, %8
  %.121.lcssa.ph = phi i32 [ %.12131, %8 ], [ %16, %14 ]
  %.pre = load i32, ptr @m, align 4, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.preheader30
  %18 = phi i32 [ %2, %.preheader30 ], [ %.pre, %.critedge.loopexit ]
  %.121.lcssa = phi i32 [ %.02036, %.preheader30 ], [ %.121.lcssa.ph, %.critedge.loopexit ]
  %19 = add nsw i32 %.121.lcssa, 1
  %20 = getelementptr inbounds [100001 x i32], ptr @fail, i64 0, i64 %indvars.iv
  store i32 %19, ptr %20, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = sext i32 %18 to i64
  %.not.not = icmp slt i64 %indvars.iv, %21
  br i1 %.not.not, label %.preheader30, label %.preheader29, !llvm.loop !12

.preheader:                                       ; preds = %.preheader29, %40
  %22 = phi i32 [ %33, %40 ], [ %5, %.preheader29 ]
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %40 ], [ 0, %.preheader29 ]
  %.043 = phi i32 [ %.2, %40 ], [ 0, %.preheader29 ]
  %23 = icmp sgt i32 %.043, -1
  br i1 %23, label %.lr.ph38, label %.critedge2

.lr.ph38:                                         ; preds = %.preheader, %29
  %.137 = phi i32 [ %31, %29 ], [ %.043, %.preheader ]
  %24 = zext nneg i32 %.137 to i64
  %25 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1tB5cxx11, i64 noundef %24)
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %indvars.iv45)
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %.not26 = icmp eq i8 %26, %28
  br i1 %.not26, label %.critedge2.loopexit, label %29

29:                                               ; preds = %.lr.ph38
  %30 = getelementptr inbounds [100001 x i32], ptr @fail, i64 0, i64 %24
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp sgt i32 %31, -1
  br i1 %32, label %.lr.ph38, label %.critedge2.loopexit, !llvm.loop !13

.critedge2.loopexit:                              ; preds = %29, %.lr.ph38
  %.1.lcssa.ph = phi i32 [ %.137, %.lr.ph38 ], [ %31, %29 ]
  %.pre48 = load i32, ptr @m, align 4, !tbaa !5
  br label %.critedge2

.critedge2:                                       ; preds = %.critedge2.loopexit, %.preheader
  %33 = phi i32 [ %22, %.preheader ], [ %.pre48, %.critedge2.loopexit ]
  %.1.lcssa = phi i32 [ %.043, %.preheader ], [ %.1.lcssa.ph, %.critedge2.loopexit ]
  %34 = add nsw i32 %.1.lcssa, 1
  %.not27 = icmp slt i32 %34, %33
  br i1 %.not27, label %40, label %35

35:                                               ; preds = %.critedge2
  %36 = sext i32 %34 to i64
  %37 = getelementptr inbounds [100001 x i32], ptr @fail, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = getelementptr inbounds [100001 x i32], ptr @found, i64 0, i64 %indvars.iv45
  store i32 1, ptr %39, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %.critedge2, %35
  %.2 = phi i32 [ %38, %35 ], [ %34, %.critedge2 ]
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %41 = load i32, ptr @n, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = icmp slt i64 %indvars.iv.next46, %42
  br i1 %43, label %.preheader, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %40, %.preheader29
  ret void
}

; 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

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

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


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