; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/286 Division 1/Problem B/writer.ll (Z4dfs2i)

; 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@g = external dso_local global [100010 x %"class.std::vector"], align 16
@rg = external dso_local global [100010 x %"class.std::vector"], align 16
@used = external dso_local global [100010 x i8], align 16
@cmp = external dso_local global [100010 x i32], align 16
@cmpsize = external dso_local global [100010 x i32], align 16

; 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 nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z4dfs2i(i32 noundef %0) #2 {
  %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
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100010 x i8], ptr @used, i64 0, i64 %7
  store i8 1, ptr %8, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100010 x i32], ptr @cmp, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100010 x i32], ptr @cmpsize, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 1
  %17 = zext i1 %16 to i32
  store i32 %17, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %51, %1
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100010 x %"class.std::vector"], ptr @g, i64 0, i64 %21
  %23 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %22) #3
  %24 = trunc i64 %23 to i32
  %25 = icmp slt i32 %19, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %54

27:                                               ; preds = %18
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100010 x %"class.std::vector"], ptr @g, i64 0, i64 %29
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %32) #3
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds [100010 x i8], ptr @used, i64 0, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !9, !range !13, !noundef !14
  %37 = trunc i8 %36 to i1
  br i1 %37, label %50, label %38

38:                                               ; preds = %27
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100010 x %"class.std::vector"], ptr @g, i64 0, i64 %40
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %41, i64 noundef %43) #3
  %45 = load i64, ptr %44, align 8, !tbaa !11
  %46 = trunc i64 %45 to i32
  %47 = call noundef i32 @_Z4dfs2i(i32 noundef %46)
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = and i32 %48, %47
  store i32 %49, ptr %3, align 4, !tbaa !5
  br label %50

50:                                               ; preds = %38, %27
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %4, align 4, !tbaa !5
  br label %18, !llvm.loop !15

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

55:                                               ; preds = %88, %54
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [100010 x %"class.std::vector"], ptr @rg, i64 0, i64 %58
  %60 = call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %59) #3
  %61 = trunc i64 %60 to i32
  %62 = icmp slt i32 %56, %61
  br i1 %62, label %64, label %63

63:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %91

64:                                               ; preds = %55
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100010 x %"class.std::vector"], ptr @rg, i64 0, i64 %66
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %67, i64 noundef %69) #3
  %71 = load i64, ptr %70, align 8, !tbaa !11
  %72 = getelementptr inbounds [100010 x i8], ptr @used, i64 0, i64 %71
  %73 = load i8, ptr %72, align 1, !tbaa !9, !range !13, !noundef !14
  %74 = trunc i8 %73 to i1
  br i1 %74, label %87, label %75

75:                                               ; preds = %64
  %76 = load i32, ptr %2, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [100010 x %"class.std::vector"], ptr @rg, i64 0, i64 %77
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %78, i64 noundef %80) #3
  %82 = load i64, ptr %81, align 8, !tbaa !11
  %83 = trunc i64 %82 to i32
  %84 = call noundef i32 @_Z4dfs2i(i32 noundef %83)
  %85 = load i32, ptr %3, align 4, !tbaa !5
  %86 = and i32 %85, %84
  store i32 %86, ptr %3, align 4, !tbaa !5
  br label %87

87:                                               ; preds = %75, %64
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %5, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %5, align 4, !tbaa !5
  br label %55, !llvm.loop !17

91:                                               ; preds = %63
  %92 = load i32, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %92
}

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


; 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@g = external dso_local global [100010 x %"class.std::vector"], align 16
@rg = external dso_local global [100010 x %"class.std::vector"], align 16
@used = external dso_local local_unnamed_addr global [100010 x i8], align 16
@cmp = external dso_local local_unnamed_addr global [100010 x i32], align 16
@cmpsize = external dso_local local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z4dfs2i(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [100010 x i8], ptr @used, i64 0, i64 %2
  store i8 1, ptr %3, align 1, !tbaa !5
  %4 = getelementptr inbounds [100010 x i32], ptr @cmp, i64 0, i64 %2
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [100010 x i32], ptr @cmpsize, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 1
  %10 = zext i1 %9 to i32
  %11 = getelementptr inbounds [100010 x %"class.std::vector"], ptr @g, i64 0, i64 %2
  %12 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %11) #1
  %13 = trunc i64 %12 to i32
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %30, %1
  %.020.lcssa = phi i32 [ %10, %1 ], [ %.1, %30 ]
  %15 = getelementptr inbounds [100010 x %"class.std::vector"], ptr @rg, i64 0, i64 %2
  %16 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %15) #1
  %17 = trunc i64 %16 to i32
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph25, label %._crit_edge

.lr.ph:                                           ; preds = %1, %30
  %indvars.iv = phi i64 [ %indvars.iv.next, %30 ], [ 0, %1 ]
  %.02021 = phi i32 [ %.1, %30 ], [ %10, %1 ]
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %11, i64 noundef %indvars.iv) #1
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds [100010 x i8], ptr @used, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !5, !range !13, !noundef !14
  %23 = trunc nuw i8 %22 to i1
  br i1 %23, label %30, label %24

24:                                               ; preds = %.lr.ph
  %25 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %11, i64 noundef %indvars.iv) #1
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = trunc i64 %26 to i32
  %28 = tail call noundef i32 @_Z4dfs2i(i32 noundef %27)
  %29 = and i32 %28, %.02021
  br label %30

30:                                               ; preds = %.lr.ph, %24
  %.1 = phi i32 [ %.02021, %.lr.ph ], [ %29, %24 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %11) #1
  %sext = shl i64 %31, 32
  %32 = ashr exact i64 %sext, 32
  %33 = icmp slt i64 %indvars.iv.next, %32
  br i1 %33, label %.lr.ph, label %.preheader, !llvm.loop !15

._crit_edge:                                      ; preds = %45, %.preheader
  %.2.lcssa = phi i32 [ %.020.lcssa, %.preheader ], [ %.3, %45 ]
  ret i32 %.2.lcssa

.lr.ph25:                                         ; preds = %.preheader, %45
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %45 ], [ 0, %.preheader ]
  %.223 = phi i32 [ %.3, %45 ], [ %.020.lcssa, %.preheader ]
  %34 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %15, i64 noundef %indvars.iv28) #1
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds [100010 x i8], ptr @used, i64 0, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !5, !range !13, !noundef !14
  %38 = trunc nuw i8 %37 to i1
  br i1 %38, label %45, label %39

39:                                               ; preds = %.lr.ph25
  %40 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %15, i64 noundef %indvars.iv28) #1
  %41 = load i64, ptr %40, align 8, !tbaa !11
  %42 = trunc i64 %41 to i32
  %43 = tail call noundef i32 @_Z4dfs2i(i32 noundef %42)
  %44 = and i32 %43, %.223
  br label %45

45:                                               ; preds = %.lr.ph25, %39
  %.3 = phi i32 [ %.223, %.lr.ph25 ], [ %44, %39 ]
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %46 = tail call noundef i64 @_ZNKSt6vectorIxSaIxEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %15) #1
  %sext31 = shl i64 %46, 32
  %47 = ashr exact i64 %sext31, 32
  %48 = icmp slt i64 %indvars.iv.next29, %47
  br i1 %48, label %.lr.ph25, label %._crit_edge, !llvm.loop !17
}

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 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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