; LLVM IR from tangjz/acm-icpc :: 51nod (1076)

; 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"

%struct.Edge = type { i32, i32 }

@e = external dso_local global [100001 x %struct.Edge], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@deg = external dso_local global [50001 x i32], align 16
@lnk = external dso_local global [50001 x i32], align 16
@bcc = external dso_local global [50001 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

; 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 uwtable
declare dso_local void @_Z5solvev() #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %struct.Edge, align 4
  %6 = alloca %struct.Edge, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = mul i64 %11, 4
  call void @llvm.memset.p0.i64(ptr align 16 @lnk, i8 -1, i64 %12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %68, %0
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = load i32, ptr @m, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %71

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3, ptr noundef %4)
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = add nsw i32 %20, -1
  store i32 %21, ptr %3, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [50001 x i32], ptr @deg, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %26, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %29 = getelementptr inbounds %struct.Edge, ptr %5, i32 0, i32 0
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [50001 x i32], ptr @lnk, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr %29, align 4, !tbaa !9
  %34 = getelementptr inbounds %struct.Edge, ptr %5, i32 0, i32 1
  %35 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %35, ptr %34, align 4, !tbaa !11
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = shl i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100001 x %struct.Edge], ptr @e, i64 0, i64 %38
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %39, ptr align 4 %5, i64 8, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = shl i32 %40, 1
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [50001 x i32], ptr @lnk, i64 0, i64 %43
  store i32 %41, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [50001 x i32], ptr @deg, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %47, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %50 = getelementptr inbounds %struct.Edge, ptr %6, i32 0, i32 0
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [50001 x i32], ptr @lnk, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  store i32 %54, ptr %50, align 4, !tbaa !9
  %55 = getelementptr inbounds %struct.Edge, ptr %6, i32 0, i32 1
  %56 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %56, ptr %55, align 4, !tbaa !11
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = shl i32 %57, 1
  %59 = or i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100001 x %struct.Edge], ptr @e, i64 0, i64 %60
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %61, ptr align 4 %6, i64 8, i1 false), !tbaa.struct !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = shl i32 %62, 1
  %64 = or i32 %63, 1
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [50001 x i32], ptr @lnk, i64 0, i64 %66
  store i32 %64, ptr %67, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %68

68:                                               ; preds = %18
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !13

71:                                               ; preds = %17
  call void @_Z5solvev()
  %72 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @m)
  br label %73

73:                                               ; preds = %77, %71
  %74 = load i32, ptr @m, align 4, !tbaa !5
  %75 = add nsw i32 %74, -1
  store i32 %75, ptr @m, align 4, !tbaa !5
  %76 = icmp ne i32 %74, 0
  br i1 %76, label %77, label %95

77:                                               ; preds = %73
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %78 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %7, ptr noundef %8)
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = add nsw i32 %79, -1
  store i32 %80, ptr %7, align 4, !tbaa !5
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = add nsw i32 %81, -1
  store i32 %82, ptr %8, align 4, !tbaa !5
  %83 = load i32, ptr %7, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [50001 x i32], ptr @bcc, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = load i32, ptr %8, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [50001 x i32], ptr @bcc, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !5
  %91 = icmp eq i32 %86, %90
  %92 = zext i1 %91 to i64
  %93 = select i1 %91, ptr @.str.2, ptr @.str.3
  %94 = call i32 @puts(ptr noundef %93)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %73, !llvm.loop !15

95:                                               ; preds = %73
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #4

; 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) #5

declare i32 @puts(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress norecurse 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 = { "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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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, !6, i64 0}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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"

%struct.Edge = type { i32, i32 }

@e = external dso_local local_unnamed_addr global [100001 x %struct.Edge], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@deg = external dso_local local_unnamed_addr global [50001 x i32], align 16
@lnk = external dso_local local_unnamed_addr global [50001 x i32], align 16
@bcc = external dso_local local_unnamed_addr global [50001 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5solvev() local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = shl nsw i64 %7, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @lnk, i8 -1, i64 %8, i1 false)
  %9 = load i32, ptr @m, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  call void @_Z5solvev()
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @m)
  %12 = load i32, ptr @m, align 4, !tbaa !5
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr @m, align 4, !tbaa !5
  %.not9 = icmp eq i32 %12, 0
  br i1 %.not9, label %._crit_edge12, label %.lr.ph11

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = add nsw i32 %17, -1
  %19 = sext i32 %16 to i64
  %20 = getelementptr inbounds [50001 x i32], ptr @deg, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %20, align 4, !tbaa !5
  %23 = getelementptr inbounds [50001 x i32], ptr @lnk, i64 0, i64 %19
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = shl nuw i64 %indvars.iv, 1
  %26 = trunc nuw i64 %25 to i32
  %sext = shl i64 %indvars.iv, 33
  %27 = ashr exact i64 %sext, 32
  %28 = getelementptr inbounds [100001 x %struct.Edge], ptr @e, i64 0, i64 %27
  store i32 %24, ptr %28, align 16, !tbaa !5
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %28, i64 4
  store i32 %18, ptr %.sroa.42.0..sroa_idx, align 4, !tbaa !5
  store i32 %26, ptr %23, align 4, !tbaa !5
  %29 = sext i32 %18 to i64
  %30 = getelementptr inbounds [50001 x i32], ptr @deg, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %30, align 4, !tbaa !5
  %33 = getelementptr inbounds [50001 x i32], ptr @lnk, i64 0, i64 %29
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = trunc i64 %25 to i32
  %36 = or disjoint i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100001 x %struct.Edge], ptr @e, i64 0, i64 %37
  store i32 %34, ptr %38, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %38, i64 4
  store i32 %16, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  store i32 %36, ptr %33, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = load i32, ptr @m, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = icmp slt i64 %indvars.iv.next, %40
  br i1 %41, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.lr.ph11:                                         ; preds = %._crit_edge, %.lr.ph11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  %42 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = add nsw i32 %43, -1
  store i32 %44, ptr %3, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = add nsw i32 %45, -1
  store i32 %46, ptr %4, align 4, !tbaa !5
  %47 = sext i32 %44 to i64
  %48 = getelementptr inbounds [50001 x i32], ptr @bcc, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = sext i32 %46 to i64
  %51 = getelementptr inbounds [50001 x i32], ptr @bcc, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = icmp eq i32 %49, %52
  %54 = select i1 %53, ptr @.str.2, ptr @.str.3
  %55 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %54)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  %56 = load i32, ptr @m, align 4, !tbaa !5
  %57 = add nsw i32 %56, -1
  store i32 %57, ptr @m, align 4, !tbaa !5
  %.not = icmp eq i32 %56, 0
  br i1 %.not, label %._crit_edge12, label %.lr.ph11, !llvm.loop !11

._crit_edge12:                                    ; preds = %.lr.ph11, %._crit_edge
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #4

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass