; LLVM IR from tangjz/acm-icpc :: codeforces/gym/101205E.ll (Z3dfsii)

; 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::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { [2 x i64] }

@n = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@seq = external dso_local global [77 x i32], align 16
@path = external dso_local global [77 x i32], align 16
@e = external dso_local global [77 x %"class.std::bitset"], align 16
@fin = external dso_local global { [2 x i64] }, align 8
@msk = external dso_local global [77 x %"class.std::bitset"], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"class.std::bitset", align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr @ans, align 4, !tbaa !5
  %10 = icmp sge i32 %8, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  br label %82

12:                                               ; preds = %2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [77 x %"class.std::bitset"], ptr @msk, i64 0, i64 %14
  %16 = call noundef zeroext i1 @_ZNKSt6bitsetILm77EEeqERKS0_(ptr noundef nonnull align 8 dereferenceable(16) %15, ptr noundef nonnull align 8 dereferenceable(16) @fin) #5
  br i1 %16, label %17, label %36

17:                                               ; preds = %12
  %18 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %18, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %19

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

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %35

24:                                               ; preds = %19
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [77 x i32], ptr @path, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [77 x i32], ptr @seq, i64 0, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !5
  br label %32

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

35:                                               ; preds = %23
  br label %82

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

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

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %82

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [77 x %"class.std::bitset"], ptr @msk, i64 0, i64 %45
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [77 x %"class.std::bitset"], ptr @e, i64 0, i64 %48
  %50 = call { i64, i64 } @_ZStorILm77EESt6bitsetIXT_EERKS1_S3_(ptr noundef nonnull align 8 dereferenceable(16) %46, ptr noundef nonnull align 8 dereferenceable(16) %49) #5
  %51 = getelementptr inbounds %"class.std::bitset", ptr %7, i32 0, i32 0
  %52 = getelementptr inbounds %"struct.std::_Base_bitset", ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds { i64, i64 }, ptr %52, i32 0, i32 0
  %54 = extractvalue { i64, i64 } %50, 0
  store i64 %54, ptr %53, align 8
  %55 = getelementptr inbounds { i64, i64 }, ptr %52, i32 0, i32 1
  %56 = extractvalue { i64, i64 } %50, 1
  store i64 %56, ptr %55, align 8
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [77 x %"class.std::bitset"], ptr @msk, i64 0, i64 %59
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %60, ptr align 8 %7, i64 16, i1 false)
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [77 x %"class.std::bitset"], ptr @msk, i64 0, i64 %63
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [77 x %"class.std::bitset"], ptr @msk, i64 0, i64 %66
  %68 = call noundef zeroext i1 @_ZNKSt6bitsetILm77EEeqERKS0_(ptr noundef nonnull align 8 dereferenceable(16) %64, ptr noundef nonnull align 8 dereferenceable(16) %67) #5
  br i1 %68, label %69, label %70

69:                                               ; preds = %43
  br label %79

70:                                               ; preds = %43
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [77 x i32], ptr @path, i64 0, i64 %73
  store i32 %71, ptr %74, align 4, !tbaa !5
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  call void @_Z3dfsii(i32 noundef %76, i32 noundef %78)
  br label %79

79:                                               ; preds = %70, %69
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %6, align 4, !tbaa !5
  br label %38, !llvm.loop !11

82:                                               ; preds = %42, %35, %11
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm77EEeqERKS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local { i64, i64 } @_ZStorILm77EESt6bitsetIXT_EERKS1_S3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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}


; 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::bitset" = type { %"struct.std::_Base_bitset" }
%"struct.std::_Base_bitset" = type { [2 x i64] }

@n = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@seq = external dso_local local_unnamed_addr global [77 x i32], align 16
@path = external dso_local local_unnamed_addr global [77 x i32], align 16
@e = external dso_local global [77 x %"class.std::bitset"], align 16
@fin = external dso_local global { [2 x i64] }, align 8
@msk = external dso_local global [77 x %"class.std::bitset"], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @ans, align 4, !tbaa !5
  %.not = icmp sgt i32 %3, %0
  br i1 %.not, label %4, label %.loopexit

4:                                                ; preds = %2
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [77 x %"class.std::bitset"], ptr @msk, i64 0, i64 %5
  %7 = tail call noundef zeroext i1 @_ZNKSt6bitsetILm77EEeqERKS0_(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(16) @fin) #3
  br i1 %7, label %15, label %.preheader

.preheader:                                       ; preds = %4
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, %1
  br i1 %9, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %10 = add nsw i32 %0, 1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [77 x %"class.std::bitset"], ptr @msk, i64 0, i64 %11
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %12, i64 8
  %13 = getelementptr inbounds [77 x i32], ptr @path, i64 0, i64 %5
  %14 = sext i32 %1 to i64
  br label %19

15:                                               ; preds = %4
  store i32 %0, ptr @ans, align 4, !tbaa !5
  %16 = icmp sgt i32 %0, 0
  br i1 %16, label %.lr.ph25.preheader, label %.loopexit

.lr.ph25.preheader:                               ; preds = %15
  %17 = zext nneg i32 %0 to i64
  %18 = shl nuw nsw i64 %17, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 @seq, ptr nonnull align 16 @path, i64 %18, i1 false), !tbaa !5
  br label %.loopexit

19:                                               ; preds = %.lr.ph, %29
  %indvars.iv = phi i64 [ %14, %.lr.ph ], [ %indvars.iv.next.pre-phi, %29 ]
  %20 = getelementptr inbounds [77 x %"class.std::bitset"], ptr @e, i64 0, i64 %indvars.iv
  %21 = tail call { i64, i64 } @_ZStorILm77EESt6bitsetIXT_EERKS1_S3_(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(16) %20) #3
  %22 = extractvalue { i64, i64 } %21, 0
  %23 = extractvalue { i64, i64 } %21, 1
  store i64 %22, ptr %12, align 16
  store i64 %23, ptr %.sroa.4.0..sroa_idx, align 8
  %24 = tail call noundef zeroext i1 @_ZNKSt6bitsetILm77EEeqERKS0_(ptr noundef nonnull align 8 dereferenceable(16) %12, ptr noundef nonnull align 8 dereferenceable(16) %6) #3
  br i1 %24, label %._crit_edge, label %25

._crit_edge:                                      ; preds = %19
  %.pre = add nsw i64 %indvars.iv, 1
  br label %29

25:                                               ; preds = %19
  %26 = trunc nsw i64 %indvars.iv to i32
  store i32 %26, ptr %13, align 4, !tbaa !5
  %27 = add nsw i64 %indvars.iv, 1
  %28 = trunc nsw i64 %27 to i32
  tail call void @_Z3dfsii(i32 noundef %10, i32 noundef %28)
  br label %29

29:                                               ; preds = %._crit_edge, %25
  %indvars.iv.next.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %27, %25 ]
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = icmp slt i64 %indvars.iv.next.pre-phi, %31
  br i1 %32, label %19, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %29, %.lr.ph25.preheader, %.preheader, %15, %2
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6bitsetILm77EEeqERKS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local { i64, i64 } @_ZStorILm77EESt6bitsetIXT_EERKS1_S3_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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" }
attributes #1 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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"}


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