; LLVM IR from tangjz/acm-icpc :: hdu/2196.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<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@f = external dso_local global [20000 x i32], align 16
@ff = external dso_local global [20000 x i32], align 16
@pos = external dso_local global [20000 x i32], align 16
@w = external dso_local global [20000 x i32], align 16
@vis = external dso_local global [20000 x i8], align 16
@e = external dso_local global [20000 x %"class.std::vector"], 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_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
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [20000 x i8], ptr @vis, i64 0, i64 %9
  store i8 1, ptr %10, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [20000 x %"class.std::vector"], ptr @e, i64 0, i64 %12
  %14 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %13) #3
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %4, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %129, %1
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %132

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [20000 x %"class.std::vector"], ptr @e, i64 0, i64 %23
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %24, i64 noundef %26) #3
  store ptr %27, ptr %6, align 8, !tbaa !11
  %28 = load ptr, ptr %6, align 8, !tbaa !11
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [20000 x i8], ptr @vis, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !9, !range !13, !noundef !14
  %33 = trunc i8 %32 to i1
  br i1 %33, label %34, label %35

34:                                               ; preds = %21
  store i32 4, ptr %5, align 4
  br label %126

35:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [20000 x i32], ptr @pos, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !11
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp eq i32 %39, %41
  br i1 %42, label %43, label %47

43:                                               ; preds = %35
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [20000 x i32], ptr @ff, i64 0, i64 %45
  br label %51

47:                                               ; preds = %35
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [20000 x i32], ptr @f, i64 0, i64 %49
  br label %51

51:                                               ; preds = %47, %43
  %52 = phi ptr [ %46, %43 ], [ %50, %47 ]
  store ptr %52, ptr %7, align 8, !tbaa !11
  %53 = load ptr, ptr %6, align 8, !tbaa !11
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [20000 x i32], ptr @f, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !11
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = load ptr, ptr %6, align 8, !tbaa !11
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [20000 x i32], ptr @w, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = add nsw i32 %59, %64
  %66 = icmp slt i32 %57, %65
  br i1 %66, label %67, label %94

67:                                               ; preds = %51
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !11
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [20000 x i32], ptr @pos, i64 0, i64 %71
  store i32 %68, ptr %72, align 4, !tbaa !5
  %73 = load ptr, ptr %6, align 8, !tbaa !11
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [20000 x i32], ptr @f, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !11
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [20000 x i32], ptr @ff, i64 0, i64 %80
  store i32 %77, ptr %81, align 4, !tbaa !5
  %82 = load ptr, ptr %7, align 8, !tbaa !11
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = load ptr, ptr %6, align 8, !tbaa !11
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [20000 x i32], ptr @w, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = add nsw i32 %83, %88
  %90 = load ptr, ptr %6, align 8, !tbaa !11
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [20000 x i32], ptr @f, i64 0, i64 %92
  store i32 %89, ptr %93, align 4, !tbaa !5
  br label %123

94:                                               ; preds = %51
  %95 = load ptr, ptr %6, align 8, !tbaa !11
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [20000 x i32], ptr @ff, i64 0, i64 %97
  %99 = load i32, ptr %98, align 4, !tbaa !5
  %100 = load ptr, ptr %7, align 8, !tbaa !11
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = load ptr, ptr %6, align 8, !tbaa !11
  %103 = load i32, ptr %102, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [20000 x i32], ptr @w, i64 0, i64 %104
  %106 = load i32, ptr %105, align 4, !tbaa !5
  %107 = add nsw i32 %101, %106
  %108 = icmp slt i32 %99, %107
  br i1 %108, label %109, label %122

109:                                              ; preds = %94
  %110 = load ptr, ptr %7, align 8, !tbaa !11
  %111 = load i32, ptr %110, align 4, !tbaa !5
  %112 = load ptr, ptr %6, align 8, !tbaa !11
  %113 = load i32, ptr %112, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [20000 x i32], ptr @w, i64 0, i64 %114
  %116 = load i32, ptr %115, align 4, !tbaa !5
  %117 = add nsw i32 %111, %116
  %118 = load ptr, ptr %6, align 8, !tbaa !11
  %119 = load i32, ptr %118, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [20000 x i32], ptr @ff, i64 0, i64 %120
  store i32 %117, ptr %121, align 4, !tbaa !5
  br label %122

122:                                              ; preds = %109, %94
  br label %123

123:                                              ; preds = %122, %67
  %124 = load ptr, ptr %6, align 8, !tbaa !11
  %125 = load i32, ptr %124, align 4, !tbaa !5
  call void @_Z4dfs2i(i32 noundef %125)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  store i32 0, ptr %5, align 4
  br label %126

126:                                              ; preds = %123, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %127 = load i32, ptr %5, align 4
  switch i32 %127, label %133 [
    i32 0, label %128
    i32 4, label %129
  ]

128:                                              ; preds = %126
  br label %129

129:                                              ; preds = %128, %126
  %130 = load i32, ptr %3, align 4, !tbaa !5
  %131 = add nsw i32 %130, 1
  store i32 %131, ptr %3, align 4, !tbaa !5
  br label %16, !llvm.loop !15

132:                                              ; preds = %20
  ret void

133:                                              ; preds = %126
  unreachable
}

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 = !{!"any pointer", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

@f = external dso_local local_unnamed_addr global [20000 x i32], align 16
@ff = external dso_local local_unnamed_addr global [20000 x i32], align 16
@pos = external dso_local local_unnamed_addr global [20000 x i32], align 16
@w = external dso_local local_unnamed_addr global [20000 x i32], align 16
@vis = external dso_local local_unnamed_addr global [20000 x i8], align 16
@e = external dso_local global [20000 x %"class.std::vector"], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4dfs2i(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [20000 x i8], ptr @vis, i64 0, i64 %2
  store i8 1, ptr %3, align 1, !tbaa !5
  %4 = getelementptr inbounds [20000 x %"class.std::vector"], ptr @e, i64 0, i64 %2
  %5 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %4) #1
  %6 = trunc i64 %5 to i32
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %8 = getelementptr inbounds [20000 x i32], ptr @pos, i64 0, i64 %2
  %9 = getelementptr inbounds [20000 x i32], ptr @ff, i64 0, i64 %2
  %10 = getelementptr inbounds [20000 x i32], ptr @f, i64 0, i64 %2
  %wide.trip.count = and i64 %5, 2147483647
  br label %11

._crit_edge:                                      ; preds = %50, %1
  ret void

11:                                               ; preds = %.lr.ph, %50
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %50 ]
  %12 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %4, i64 noundef %indvars.iv) #1
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [20000 x i8], ptr @vis, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !5, !range !11, !noundef !12
  %17 = trunc nuw i8 %16 to i1
  br i1 %17, label %50, label %18

18:                                               ; preds = %11
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = icmp eq i32 %19, %13
  %21 = select i1 %20, ptr %9, ptr %10
  %22 = getelementptr inbounds [20000 x i32], ptr @f, i64 0, i64 %14
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = load i32, ptr %21, align 4, !tbaa !9
  %25 = getelementptr inbounds [20000 x i32], ptr @w, i64 0, i64 %14
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = add nsw i32 %26, %24
  %28 = icmp slt i32 %23, %27
  br i1 %28, label %29, label %43

29:                                               ; preds = %18
  %30 = getelementptr inbounds [20000 x i32], ptr @pos, i64 0, i64 %14
  store i32 %0, ptr %30, align 4, !tbaa !9
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [20000 x i32], ptr @f, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = getelementptr inbounds [20000 x i32], ptr @ff, i64 0, i64 %32
  store i32 %34, ptr %35, align 4, !tbaa !9
  %36 = load i32, ptr %21, align 4, !tbaa !9
  %37 = load i32, ptr %12, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [20000 x i32], ptr @w, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = add nsw i32 %40, %36
  %42 = getelementptr inbounds [20000 x i32], ptr @f, i64 0, i64 %38
  store i32 %41, ptr %42, align 4, !tbaa !9
  br label %48

43:                                               ; preds = %18
  %44 = getelementptr inbounds [20000 x i32], ptr @ff, i64 0, i64 %14
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = icmp slt i32 %45, %27
  br i1 %46, label %47, label %48

47:                                               ; preds = %43
  store i32 %27, ptr %44, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %43, %47, %29
  %49 = load i32, ptr %12, align 4, !tbaa !9
  tail call void @_Z4dfs2i(i32 noundef %49)
  br label %50

50:                                               ; preds = %11, %48
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %11, !llvm.loop !13
}

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


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