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

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

@m = 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
@e = external dso_local global [200003 x %struct.Edge], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z8dsu_findi(i32 noundef) #0

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

; 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 i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr @m, align 4, !tbaa !5
  %11 = icmp eq i32 %9, %10
  br i1 %11, label %20, label %12

12:                                               ; preds = %2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.Edge, ptr %15, i32 0, i32 2
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = load i32, ptr @val, align 4, !tbaa !5
  %19 = icmp ne i32 %17, %18
  br i1 %19, label %20, label %33

20:                                               ; preds = %12, %2
  %21 = load i32, ptr @cnt, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %25, ptr @cnt, align 4, !tbaa !5
  store i32 0, ptr @sum, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %24, %20
  %27 = load i32, ptr @cnt, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp eq i32 %27, %28
  %30 = zext i1 %29 to i32
  %31 = load i32, ptr @sum, align 4, !tbaa !5
  %32 = add nsw i32 %31, %30
  store i32 %32, ptr @sum, align 4, !tbaa !5
  br label %74

33:                                               ; preds = %12
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %35, i32 noundef %36)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.Edge, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = call noundef i32 @_Z8dsu_findi(i32 noundef %41)
  store i32 %42, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.Edge, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !12
  %48 = call noundef i32 @_Z8dsu_findi(i32 noundef %47)
  store i32 %48, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [50001 x i32], ptr @dsu, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  store i32 %52, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [50001 x i32], ptr @dsu, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  store i32 %56, ptr %8, align 4, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = call noundef zeroext i1 @_Z9dsu_mergeii(i32 noundef %57, i32 noundef %58)
  br i1 %59, label %60, label %73

60:                                               ; preds = %33
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  call void @_Z3dfsii(i32 noundef %62, i32 noundef %64)
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [50001 x i32], ptr @dsu, i64 0, i64 %67
  store i32 %65, ptr %68, align 4, !tbaa !5
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [50001 x i32], ptr @dsu, i64 0, i64 %71
  store i32 %69, ptr %72, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %60, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %74

74:                                               ; preds = %73, %26
  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: 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 = { 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 8}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 0}
!12 = !{!10, !6, i64 4}


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

@m = 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
@e = external dso_local local_unnamed_addr global [200003 x %struct.Edge], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @m, align 4, !tbaa !5
  %4 = icmp eq i32 %3, %0
  br i1 %4, label %11, label %5

5:                                                ; preds = %2
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [200003 x %struct.Edge], ptr @e, i64 0, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = load i32, ptr @val, align 4, !tbaa !5
  %.not = icmp eq i32 %9, %10
  br i1 %.not, label %21, label %11

11:                                               ; preds = %5, %2
  %12 = load i32, ptr @cnt, align 4, !tbaa !5
  %13 = icmp slt i32 %12, %1
  br i1 %13, label %14, label %._crit_edge

._crit_edge:                                      ; preds = %11
  %.pre = load i32, ptr @sum, align 4, !tbaa !5
  br label %15

14:                                               ; preds = %11
  store i32 %1, ptr @cnt, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %._crit_edge, %14
  %16 = phi i32 [ 0, %14 ], [ %.pre, %._crit_edge ]
  %17 = phi i32 [ %1, %14 ], [ %12, %._crit_edge ]
  %18 = icmp eq i32 %17, %1
  %19 = zext i1 %18 to i32
  %20 = add nsw i32 %16, %19
  store i32 %20, ptr @sum, align 4, !tbaa !5
  br label %common.ret20

21:                                               ; preds = %5
  %22 = add nsw i32 %0, 1
  tail call void @_Z3dfsii(i32 noundef %22, i32 noundef %1)
  %23 = load i32, ptr %7, align 4, !tbaa !11
  %24 = tail call noundef i32 @_Z8dsu_findi(i32 noundef %23)
  %25 = getelementptr inbounds i8, ptr %7, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %27 = tail call noundef i32 @_Z8dsu_findi(i32 noundef %26)
  %28 = sext i32 %24 to i64
  %29 = getelementptr inbounds [50001 x i32], ptr @dsu, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %27 to i64
  %32 = getelementptr inbounds [50001 x i32], ptr @dsu, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = tail call noundef zeroext i1 @_Z9dsu_mergeii(i32 noundef %24, i32 noundef %27)
  br i1 %34, label %35, label %common.ret20

common.ret20:                                     ; preds = %21, %15, %35
  ret void

35:                                               ; preds = %21
  %36 = add nsw i32 %1, 1
  tail call void @_Z3dfsii(i32 noundef %22, i32 noundef %36)
  store i32 %30, ptr %29, align 4, !tbaa !5
  store i32 %33, ptr %32, align 4, !tbaa !5
  br label %common.ret20
}

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

!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 8}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 0}
!12 = !{!10, !6, i64 4}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass