; LLVM IR from AdarshGaur/Competitive-Programming :: Codeforces/Random Problems/B. Strongly Connected City.ll (Z3dfsll)

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

@vis = external dso_local global [21 x [21 x i8]], align 16
@n = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@_Z1hB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_Z1vB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@t = external dso_local global i64, align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsll(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  %5 = load i64, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds [21 x [21 x i8]], ptr @vis, i64 0, i64 %5
  %7 = load i64, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds [21 x i8], ptr %6, i64 0, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !9, !range !11, !noundef !12
  %10 = trunc i8 %9 to i1
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  br label %76

12:                                               ; preds = %2
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds [21 x [21 x i8]], ptr @vis, i64 0, i64 %13
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds [21 x i8], ptr %14, i64 0, i64 %15
  store i8 1, ptr %16, align 1, !tbaa !9
  %17 = load i64, ptr @t, align 8, !tbaa !5
  %18 = add nsw i64 %17, 1
  store i64 %18, ptr @t, align 8, !tbaa !5
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1hB5cxx11, i64 noundef %19)
  %21 = load i8, ptr %20, align 1, !tbaa !13
  %22 = sext i8 %21 to i32
  %23 = icmp eq i32 %22, 62
  br i1 %23, label %24, label %33

24:                                               ; preds = %12
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = load i64, ptr @m, align 8, !tbaa !5
  %27 = sub nsw i64 %26, 1
  %28 = icmp ne i64 %25, %27
  br i1 %28, label %29, label %33

29:                                               ; preds = %24
  %30 = load i64, ptr %3, align 8, !tbaa !5
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = add nsw i64 %31, 1
  call void @_Z3dfsll(i64 noundef %30, i64 noundef %32)
  br label %47

33:                                               ; preds = %24, %12
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1hB5cxx11, i64 noundef %34)
  %36 = load i8, ptr %35, align 1, !tbaa !13
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 60
  br i1 %38, label %39, label %46

39:                                               ; preds = %33
  %40 = load i64, ptr %4, align 8, !tbaa !5
  %41 = icmp ne i64 %40, 0
  br i1 %41, label %42, label %46

42:                                               ; preds = %39
  %43 = load i64, ptr %3, align 8, !tbaa !5
  %44 = load i64, ptr %4, align 8, !tbaa !5
  %45 = sub nsw i64 %44, 1
  call void @_Z3dfsll(i64 noundef %43, i64 noundef %45)
  br label %46

46:                                               ; preds = %42, %39, %33
  br label %47

47:                                               ; preds = %46, %29
  %48 = load i64, ptr %4, align 8, !tbaa !5
  %49 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1vB5cxx11, i64 noundef %48)
  %50 = load i8, ptr %49, align 1, !tbaa !13
  %51 = sext i8 %50 to i32
  %52 = icmp eq i32 %51, 94
  br i1 %52, label %53, label %60

53:                                               ; preds = %47
  %54 = load i64, ptr %3, align 8, !tbaa !5
  %55 = icmp ne i64 %54, 0
  br i1 %55, label %56, label %60

56:                                               ; preds = %53
  %57 = load i64, ptr %3, align 8, !tbaa !5
  %58 = sub nsw i64 %57, 1
  %59 = load i64, ptr %4, align 8, !tbaa !5
  call void @_Z3dfsll(i64 noundef %58, i64 noundef %59)
  br label %76

60:                                               ; preds = %53, %47
  %61 = load i64, ptr %4, align 8, !tbaa !5
  %62 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1vB5cxx11, i64 noundef %61)
  %63 = load i8, ptr %62, align 1, !tbaa !13
  %64 = sext i8 %63 to i32
  %65 = icmp eq i32 %64, 118
  br i1 %65, label %66, label %75

66:                                               ; preds = %60
  %67 = load i64, ptr %3, align 8, !tbaa !5
  %68 = load i64, ptr @n, align 8, !tbaa !5
  %69 = sub nsw i64 %68, 1
  %70 = icmp ne i64 %67, %69
  br i1 %70, label %71, label %75

71:                                               ; preds = %66
  %72 = load i64, ptr %3, align 8, !tbaa !5
  %73 = add nsw i64 %72, 1
  %74 = load i64, ptr %4, align 8, !tbaa !5
  call void @_Z3dfsll(i64 noundef %73, i64 noundef %74)
  br label %75

75:                                               ; preds = %71, %66, %60
  br label %76

76:                                               ; preds = %75, %56, %11
  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) #1 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 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!7, !7, i64 0}


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

@vis = external dso_local local_unnamed_addr global [21 x [21 x i8]], align 16
@n = external dso_local local_unnamed_addr global i64, align 8
@m = external dso_local local_unnamed_addr global i64, align 8
@_Z1hB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_Z1vB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@t = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsll(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds [21 x [21 x i8]], ptr @vis, i64 0, i64 %0, i64 %1
  %4 = load i8, ptr %3, align 1, !tbaa !5, !range !9, !noundef !10
  %5 = trunc nuw i8 %4 to i1
  br i1 %5, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = add nsw i64 %1, 1
  %7 = icmp ne i64 %1, 0
  %8 = add nsw i64 %1, -1
  br label %9

9:                                                ; preds = %.lr.ph, %tailrecurse.backedge
  %10 = phi ptr [ %3, %.lr.ph ], [ %29, %tailrecurse.backedge ]
  %.tr27 = phi i64 [ %0, %.lr.ph ], [ %28, %tailrecurse.backedge ]
  store i8 1, ptr %10, align 1, !tbaa !5
  %11 = load i64, ptr @t, align 8, !tbaa !11
  %12 = add nsw i64 %11, 1
  store i64 %12, ptr @t, align 8, !tbaa !11
  %13 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1hB5cxx11, i64 noundef %.tr27)
  %14 = load i8, ptr %13, align 1, !tbaa !13
  %15 = icmp eq i8 %14, 62
  br i1 %15, label %16, label %19

16:                                               ; preds = %9
  %17 = load i64, ptr @m, align 8, !tbaa !11
  %18 = add nsw i64 %17, -1
  %.not = icmp eq i64 %18, %1
  br i1 %.not, label %19, label %.sink.split

19:                                               ; preds = %16, %9
  %20 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1hB5cxx11, i64 noundef %.tr27)
  %21 = load i8, ptr %20, align 1, !tbaa !13
  %22 = icmp eq i8 %21, 60
  %or.cond = and i1 %7, %22
  br i1 %or.cond, label %.sink.split, label %23

.sink.split:                                      ; preds = %19, %16
  %.sink = phi i64 [ %6, %16 ], [ %8, %19 ]
  tail call void @_Z3dfsll(i64 noundef %.tr27, i64 noundef %.sink)
  br label %23

23:                                               ; preds = %.sink.split, %19
  %24 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1vB5cxx11, i64 noundef %1)
  %25 = load i8, ptr %24, align 1, !tbaa !13
  %26 = icmp eq i8 %25, 94
  %27 = icmp ne i64 %.tr27, 0
  %or.cond3 = and i1 %27, %26
  br i1 %or.cond3, label %tailrecurse.backedge, label %32

tailrecurse.backedge:                             ; preds = %23, %36
  %.sink29 = phi i64 [ 1, %36 ], [ -1, %23 ]
  %28 = add nsw i64 %.tr27, %.sink29
  %29 = getelementptr inbounds [21 x [21 x i8]], ptr @vis, i64 0, i64 %28, i64 %1
  %30 = load i8, ptr %29, align 1, !tbaa !5, !range !9, !noundef !10
  %31 = trunc nuw i8 %30 to i1
  br i1 %31, label %._crit_edge, label %9

32:                                               ; preds = %23
  %33 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1vB5cxx11, i64 noundef %1)
  %34 = load i8, ptr %33, align 1, !tbaa !13
  %35 = icmp eq i8 %34, 118
  br i1 %35, label %36, label %._crit_edge

36:                                               ; preds = %32
  %37 = load i64, ptr @n, align 8, !tbaa !11
  %38 = add nsw i64 %37, -1
  %.not25 = icmp eq i64 %38, %.tr27
  br i1 %.not25, label %._crit_edge, label %tailrecurse.backedge

._crit_edge:                                      ; preds = %tailrecurse.backedge, %36, %32, %2
  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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass