; LLVM IR from tangjz/acm-icpc :: lydsy/4970.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"

@n = external dso_local global i32, align 4
@a = external dso_local global [1100001 x i32], align 16
@m = external dso_local global i32, align 4
@ch = external dso_local global [2 x [1100001 x i32]], align 16
@dep = external dso_local global [1100001 x i32], align 16
@pos = external dso_local global [2200003 x i32], align 16
@ans = external dso_local global [2 x [1100001 x i32]], 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 ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %7, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [1100001 x i32], ptr @a, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = add nsw i32 %11, %12
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sub nsw i32 %13, %14
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2200003 x i32], ptr @pos, i64 0, i64 %16
  store ptr %17, ptr %6, align 8, !tbaa !9
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1100001 x i32], ptr @ch, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %44

23:                                               ; preds = %2
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [1100001 x i32], ptr @dep, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1100001 x i32], ptr @ch, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1100001 x i32], ptr @dep, i64 0, i64 %33
  store i32 %28, ptr %34, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1100001 x i32], ptr @ch, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1100001 x i32], ptr @dep, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  call void @_Z3dfsii(i32 noundef %38, i32 noundef %43)
  br label %87

44:                                               ; preds = %2
  %45 = load ptr, ptr %6, align 8, !tbaa !9
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %85

48:                                               ; preds = %44
  %49 = load ptr, ptr %6, align 8, !tbaa !9
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [1100001 x i32], ptr @dep, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = icmp sge i32 %53, %54
  br i1 %55, label %56, label %85

56:                                               ; preds = %48
  %57 = load i32, ptr @m, align 4, !tbaa !5
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %59, label %74

59:                                               ; preds = %56
  %60 = load ptr, ptr %6, align 8, !tbaa !9
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr @m, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1100001 x i32], ptr @ans, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = icmp sle i32 %61, %65
  br i1 %66, label %67, label %74

67:                                               ; preds = %59
  %68 = load i32, ptr @m, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [1100001 x i32], ptr getelementptr inbounds ([2 x [1100001 x i32]], ptr @ans, i64 0, i64 1), i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = icmp sle i32 %71, %72
  br i1 %73, label %85, label %74

74:                                               ; preds = %67, %59, %56
  %75 = load ptr, ptr %6, align 8, !tbaa !9
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i32, ptr @m, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr @m, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [1100001 x i32], ptr @ans, i64 0, i64 %79
  store i32 %76, ptr %80, align 4, !tbaa !5
  %81 = load i32, ptr %3, align 4, !tbaa !5
  %82 = load i32, ptr @m, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [1100001 x i32], ptr getelementptr inbounds ([2 x [1100001 x i32]], ptr @ans, i64 0, i64 1), i64 0, i64 %83
  store i32 %81, ptr %84, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %74, %67, %48, %44
  %86 = load ptr, ptr %6, align 8, !tbaa !9
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %86, ptr noundef nonnull align 4 dereferenceable(4) %5) #3
  br label %87

87:                                               ; preds = %85, %23
  %88 = load i32, ptr %3, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [1100001 x i32], ptr getelementptr inbounds ([2 x [1100001 x i32]], ptr @ch, i64 0, i64 1), i64 0, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = icmp ne i32 %91, 0
  br i1 %92, label %93, label %110

93:                                               ; preds = %87
  %94 = load i32, ptr %3, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [1100001 x i32], ptr @dep, i64 0, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  %99 = load i32, ptr %3, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [1100001 x i32], ptr getelementptr inbounds ([2 x [1100001 x i32]], ptr @ch, i64 0, i64 1), i64 0, i64 %100
  %102 = load i32, ptr %101, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [1100001 x i32], ptr @dep, i64 0, i64 %103
  store i32 %98, ptr %104, align 4, !tbaa !5
  %105 = load i32, ptr %3, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [1100001 x i32], ptr getelementptr inbounds ([2 x [1100001 x i32]], ptr @ch, i64 0, i64 1), i64 0, i64 %106
  %108 = load i32, ptr %107, align 4, !tbaa !5
  %109 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %108, i32 noundef %109)
  br label %110

110:                                              ; preds = %93, %87
  %111 = load i32, ptr %3, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [1100001 x i32], ptr @ch, i64 0, i64 %112
  %114 = load i32, ptr %113, align 4, !tbaa !5
  %115 = icmp ne i32 %114, 0
  br i1 %115, label %118, label %116

116:                                              ; preds = %110
  %117 = load ptr, ptr %6, align 8, !tbaa !9
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %117, ptr noundef nonnull align 4 dereferenceable(4) %5) #3
  br label %118

118:                                              ; preds = %116, %110
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #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 = { 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 #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 = !{!"any pointer", !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"

@n = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [1100001 x i32], align 16
@m = external dso_local local_unnamed_addr global i32, align 4
@ch = external dso_local local_unnamed_addr global [2 x [1100001 x i32]], align 16
@dep = external dso_local local_unnamed_addr global [1100001 x i32], align 16
@pos = external dso_local global [2200003 x i32], align 16
@ans = external dso_local local_unnamed_addr global [2 x [1100001 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 %0, ptr %3, align 4, !tbaa !5
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [1100001 x i32], ptr @a, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = sub i32 %6, %0
  %9 = add i32 %8, %7
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [2200003 x i32], ptr @pos, i64 0, i64 %10
  %12 = getelementptr inbounds [1100001 x i32], ptr @ch, i64 0, i64 %4
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %22, label %14

14:                                               ; preds = %2
  %15 = getelementptr inbounds [1100001 x i32], ptr @dep, i64 0, i64 %4
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  %18 = sext i32 %13 to i64
  %19 = getelementptr inbounds [1100001 x i32], ptr @dep, i64 0, i64 %18
  store i32 %17, ptr %19, align 4, !tbaa !5
  %20 = load i32, ptr %15, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  tail call void @_Z3dfsii(i32 noundef %13, i32 noundef %21)
  br label %43

22:                                               ; preds = %2
  %23 = load i32, ptr %11, align 4, !tbaa !5
  %.not25 = icmp eq i32 %23, 0
  br i1 %.not25, label %42, label %24

24:                                               ; preds = %22
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds [1100001 x i32], ptr @dep, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not26 = icmp slt i32 %27, %1
  br i1 %.not26, label %42, label %28

28:                                               ; preds = %24
  %29 = load i32, ptr @m, align 4, !tbaa !5
  %.not27 = icmp eq i32 %29, 0
  br i1 %.not27, label %37, label %30

30:                                               ; preds = %28
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds [1100001 x i32], ptr @ans, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %.not28 = icmp sgt i32 %23, %33
  br i1 %.not28, label %37, label %34

34:                                               ; preds = %30
  %35 = getelementptr inbounds [1100001 x i32], ptr getelementptr inbounds (i8, ptr @ans, i64 4400004), i64 0, i64 %31
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %.not29 = icmp sgt i32 %36, %0
  br i1 %.not29, label %37, label %42

37:                                               ; preds = %34, %30, %28
  %38 = add nsw i32 %29, 1
  store i32 %38, ptr @m, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1100001 x i32], ptr @ans, i64 0, i64 %39
  store i32 %23, ptr %40, align 4, !tbaa !5
  %41 = getelementptr inbounds [1100001 x i32], ptr getelementptr inbounds (i8, ptr @ans, i64 4400004), i64 0, i64 %39
  store i32 %0, ptr %41, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %37, %34, %24, %22
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(4) %3) #3
  br label %43

43:                                               ; preds = %42, %14
  %44 = getelementptr inbounds [1100001 x i32], ptr getelementptr inbounds (i8, ptr @ch, i64 4400004), i64 0, i64 %4
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %.not30 = icmp eq i32 %45, 0
  br i1 %.not30, label %52, label %46

46:                                               ; preds = %43
  %47 = getelementptr inbounds [1100001 x i32], ptr @dep, i64 0, i64 %4
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  %50 = sext i32 %45 to i64
  %51 = getelementptr inbounds [1100001 x i32], ptr @dep, i64 0, i64 %50
  store i32 %49, ptr %51, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %45, i32 noundef %1)
  br label %52

52:                                               ; preds = %46, %43
  %53 = load i32, ptr %12, align 4, !tbaa !5
  %.not31 = icmp eq i32 %53, 0
  br i1 %.not31, label %54, label %55

54:                                               ; preds = %52
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(4) %3) #3
  br label %55

55:                                               ; preds = %54, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass