; LLVM IR from tangjz/acm-icpc :: lydsy (1543)

; 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, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@blk = external dso_local global i32, align 4
@dsu = external dso_local global [50001 x i32], align 16
@val = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@sum = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@e = external dso_local global [200003 x %struct.Edge], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z9dsu_mergeii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(i32 noundef, i32 noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %14, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr @m, align 4, !tbaa !5
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %12
  call void @_ZN4Edge4readEv(ptr noundef nonnull align 4 dereferenceable(12) %13)
  br label %14

14:                                               ; preds = %10
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

17:                                               ; preds = %9
  %18 = load i32, ptr @m, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds %struct.Edge, ptr @e, i64 %19
  call void @_ZSt4sortIP4EdgeEvT_S2_(ptr noundef @e, ptr noundef %20)
  store i32 1, ptr @ans, align 4, !tbaa !5
  %21 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %21, ptr @blk, align 4, !tbaa !5
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = mul i64 %23, 4
  call void @llvm.memset.p0.i64(ptr align 16 @dsu, i8 -1, i64 %24, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %73, %17
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = load i32, ptr @m, align 4, !tbaa !5
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %74

30:                                               ; preds = %25
  store i32 0, ptr @sum, align 4, !tbaa !5
  store i32 0, ptr @cnt, align 4, !tbaa !5
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.Edge, ptr %33, i32 0, i32 2
  %35 = load i32, ptr %34, align 4, !tbaa !11
  store i32 %35, ptr @val, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %36, i32 noundef 0)
  %37 = load i32, ptr @ans, align 4, !tbaa !5
  %38 = load i32, ptr @sum, align 4, !tbaa !5
  %39 = mul nsw i32 %37, %38
  %40 = srem i32 %39, 1000003
  store i32 %40, ptr @ans, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %70, %30
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = load i32, ptr @m, align 4, !tbaa !5
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %53

45:                                               ; preds = %41
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.Edge, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !11
  %51 = load i32, ptr @val, align 4, !tbaa !5
  %52 = icmp eq i32 %50, %51
  br label %53

53:                                               ; preds = %45, %41
  %54 = phi i1 [ false, %41 ], [ %52, %45 ]
  br i1 %54, label %55, label %73

55:                                               ; preds = %53
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.Edge, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 4, !tbaa !13
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.Edge, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 4, !tbaa !14
  %66 = call noundef zeroext i1 @_Z9dsu_mergeii(i32 noundef %60, i32 noundef %65)
  %67 = zext i1 %66 to i32
  %68 = load i32, ptr @blk, align 4, !tbaa !5
  %69 = sub nsw i32 %68, %67
  store i32 %69, ptr @blk, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %55
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %3, align 4, !tbaa !5
  br label %41, !llvm.loop !15

73:                                               ; preds = %53
  br label %25, !llvm.loop !16

74:                                               ; preds = %29
  %75 = load i32, ptr @blk, align 4, !tbaa !5
  %76 = icmp eq i32 %75, 1
  br i1 %76, label %77, label %79

77:                                               ; preds = %74
  %78 = load i32, ptr @ans, align 4, !tbaa !5
  br label %80

79:                                               ; preds = %74
  br label %80

80:                                               ; preds = %79, %77
  %81 = phi i32 [ %78, %77 ], [ 0, %79 ]
  %82 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %81)
  ret i32 0
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Edge4readEv(ptr noundef nonnull align 4 dereferenceable(12)) #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP4EdgeEvT_S2_(ptr noundef, ptr noundef) #4

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

declare i32 @printf(ptr noundef, ...) #3

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

%struct.Edge = type { i32, i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@blk = external dso_local local_unnamed_addr global i32, align 4
@dsu = external dso_local local_unnamed_addr global [50001 x i32], align 16
@val = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@sum = external dso_local local_unnamed_addr global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@e = external dso_local global [200003 x %struct.Edge], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z9dsu_mergeii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3dfsii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %2 = load i32, ptr @m, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre30 = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre30, %.._crit_edge_crit_edge ], [ %12, %.lr.ph ]
  %4 = getelementptr inbounds %struct.Edge, ptr @e, i64 %.pre-phi
  tail call void @_ZSt4sortIP4EdgeEvT_S2_(ptr noundef nonnull @e, ptr noundef nonnull %4)
  store i32 1, ptr @ans, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %5, ptr @blk, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = shl nsw i64 %6, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @dsu, i8 -1, i64 %7, i1 false)
  %8 = load i32, ptr @m, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph22, label %._crit_edge23

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %10 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %indvars.iv
  tail call void @_ZN4Edge4readEv(ptr noundef nonnull align 4 dereferenceable(12) %10)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @m, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge23.loopexit:                           ; preds = %.critedge
  %.pre = load i32, ptr @blk, align 4, !tbaa !5
  %.pre29 = load i32, ptr @ans, align 4
  br label %._crit_edge23

._crit_edge23:                                    ; preds = %._crit_edge23.loopexit, %._crit_edge
  %14 = phi i32 [ %.pre29, %._crit_edge23.loopexit ], [ 1, %._crit_edge ]
  %15 = phi i32 [ %.pre, %._crit_edge23.loopexit ], [ %5, %._crit_edge ]
  %16 = icmp eq i32 %15, 1
  %17 = select i1 %16, i32 %14, i32 0
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %17)
  ret i32 0

.lr.ph22:                                         ; preds = %._crit_edge, %.critedge
  %.020 = phi i32 [ %.1.lcssa, %.critedge ], [ 0, %._crit_edge ]
  store i32 0, ptr @sum, align 4, !tbaa !5
  store i32 0, ptr @cnt, align 4, !tbaa !5
  %19 = sext i32 %.020 to i64
  %20 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %19, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !11
  store i32 %21, ptr @val, align 4, !tbaa !5
  tail call void @_Z3dfsii(i32 noundef %.020, i32 noundef 0)
  %22 = load i32, ptr @ans, align 4, !tbaa !5
  %23 = load i32, ptr @sum, align 4, !tbaa !5
  %24 = mul nsw i32 %23, %22
  %25 = srem i32 %24, 1000003
  store i32 %25, ptr @ans, align 4, !tbaa !5
  %26 = load i32, ptr @m, align 4, !tbaa !5
  %27 = icmp slt i32 %.020, %26
  br i1 %27, label %.lr.ph16.preheader, label %.critedge

.lr.ph16.preheader:                               ; preds = %.lr.ph22
  %28 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %19
  %29 = getelementptr inbounds i8, ptr %28, i64 8
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = load i32, ptr @val, align 4, !tbaa !5
  %32 = icmp eq i32 %30, %31
  br i1 %32, label %.lr.ph32, label %.critedge.loopexit

.lr.ph16:                                         ; preds = %.lr.ph32
  %33 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %indvars.iv.next27
  %34 = getelementptr inbounds i8, ptr %33, i64 8
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = load i32, ptr @val, align 4, !tbaa !5
  %37 = icmp eq i32 %35, %36
  br i1 %37, label %.lr.ph32, label %.critedge.loopexit, !llvm.loop !13

.lr.ph32:                                         ; preds = %.lr.ph16.preheader, %.lr.ph16
  %38 = phi ptr [ %33, %.lr.ph16 ], [ %28, %.lr.ph16.preheader ]
  %indvars.iv2631 = phi i64 [ %indvars.iv.next27, %.lr.ph16 ], [ %19, %.lr.ph16.preheader ]
  %39 = load i32, ptr %38, align 4, !tbaa !14
  %40 = getelementptr inbounds i8, ptr %38, i64 4
  %41 = load i32, ptr %40, align 4, !tbaa !15
  %42 = tail call noundef zeroext i1 @_Z9dsu_mergeii(i32 noundef %39, i32 noundef %41)
  %.neg = sext i1 %42 to i32
  %43 = load i32, ptr @blk, align 4, !tbaa !5
  %44 = add i32 %43, %.neg
  store i32 %44, ptr @blk, align 4, !tbaa !5
  %indvars.iv.next27 = add nsw i64 %indvars.iv2631, 1
  %45 = load i32, ptr @m, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = icmp slt i64 %indvars.iv.next27, %46
  br i1 %47, label %.lr.ph16, label %.critedge.loopexit, !llvm.loop !13

.critedge.loopexit:                               ; preds = %.lr.ph16, %.lr.ph32, %.lr.ph16.preheader
  %48 = phi i32 [ %26, %.lr.ph16.preheader ], [ %45, %.lr.ph32 ], [ %45, %.lr.ph16 ]
  %.1.lcssa.ph.in = phi i64 [ %19, %.lr.ph16.preheader ], [ %indvars.iv.next27, %.lr.ph32 ], [ %indvars.iv.next27, %.lr.ph16 ]
  %.1.lcssa.ph = trunc i64 %.1.lcssa.ph.in to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph22
  %49 = phi i32 [ %26, %.lr.ph22 ], [ %48, %.critedge.loopexit ]
  %.1.lcssa = phi i32 [ %.020, %.lr.ph22 ], [ %.1.lcssa.ph, %.critedge.loopexit ]
  %50 = icmp slt i32 %.1.lcssa, %49
  br i1 %50, label %.lr.ph22, label %._crit_edge23.loopexit, !llvm.loop !16
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4Edge4readEv(ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP4EdgeEvT_S2_(ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

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 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 #2 = { 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 #3 = { inlinehint 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!12, !6, i64 8}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = distinct !{!13, !10}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !6, i64 4}
!16 = distinct !{!16, !10}


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