; LLVM IR from tangjz/acm-icpc :: 51nod/1647.ll (Z3dfsi)

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

@f = external dso_local global [2000003 x i32], align 16
@mx = external dso_local global i32, align 4
@lnk = external dso_local global [2000003 x i32], align 16
@st = external dso_local global [21 x [2000003 x i32]], align 16
@e = external dso_local global [2000003 x %struct.Edge], 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: 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 @_Z3dfsi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [2000003 x i32], ptr @lnk, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %10, ptr %3, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %79, %1
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %85

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [2000003 x %struct.Edge], ptr @e, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.Edge, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %20, ptr %5, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [2000003 x i32], ptr @st, i64 0, i64 %23
  store i32 %21, ptr %24, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %66, %15
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = sub nsw i32 %26, 1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [21 x [2000003 x i32]], ptr @st, i64 0, i64 %28
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2000003 x i32], ptr %29, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %36, label %35

35:                                               ; preds = %25
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %68

36:                                               ; preds = %25
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [21 x [2000003 x i32]], ptr @st, i64 0, i64 %39
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sub nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [21 x [2000003 x i32]], ptr @st, i64 0, i64 %43
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [2000003 x i32], ptr %44, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [2000003 x i32], ptr %40, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [21 x [2000003 x i32]], ptr @st, i64 0, i64 %53
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [2000003 x i32], ptr %54, i64 0, i64 %56
  store i32 %51, ptr %57, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %36
  %59 = load i32, ptr @mx, align 4, !tbaa !5
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %6, align 4, !tbaa !5
  %62 = icmp slt i32 %59, %61
  br i1 %62, label %63, label %66

63:                                               ; preds = %58
  %64 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %64, ptr @mx, align 4, !tbaa !5
  %65 = icmp ne i32 %64, 0
  br label %66

66:                                               ; preds = %63, %58
  %67 = phi i1 [ false, %58 ], [ %65, %63 ]
  br label %25, !llvm.loop !11

68:                                               ; preds = %35
  %69 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef %69)
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [2000003 x i32], ptr @f, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [2000003 x i32], ptr @f, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = add nsw i32 %77, %73
  store i32 %78, ptr %76, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %79

79:                                               ; preds = %68
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [2000003 x %struct.Edge], ptr @e, i64 0, i64 %81
  %83 = getelementptr inbounds %struct.Edge, ptr %82, i32 0, i32 0
  %84 = load i32, ptr %83, align 8, !tbaa !13
  store i32 %84, ptr %3, align 4, !tbaa !5
  br label %11, !llvm.loop !14

85:                                               ; preds = %14
  ret void
}

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 = { 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 4}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !6, i64 0}
!14 = distinct !{!14, !12}


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

@f = external dso_local local_unnamed_addr global [2000003 x i32], align 16
@mx = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [2000003 x i32], align 16
@st = external dso_local local_unnamed_addr global [21 x [2000003 x i32]], align 16
@e = external dso_local local_unnamed_addr global [2000003 x %struct.Edge], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [2000003 x i32], ptr @lnk, i64 0, i64 %2
  %.01825 = load i32, ptr %3, align 4, !tbaa !5
  %.not26 = icmp eq i32 %.01825, 0
  br i1 %.not26, label %._crit_edge30, label %.lr.ph29

.lr.ph29:                                         ; preds = %1
  %4 = getelementptr inbounds [2000003 x i32], ptr @f, i64 0, i64 %2
  %.not2123 = icmp eq i32 %0, 0
  br label %5

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

5:                                                ; preds = %.lr.ph29, %._crit_edge
  %.01827 = phi i32 [ %.01825, %.lr.ph29 ], [ %.018, %._crit_edge ]
  %6 = sext i32 %.01827 to i64
  %7 = getelementptr inbounds [2000003 x %struct.Edge], ptr @e, i64 0, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [2000003 x i32], ptr @st, i64 0, i64 %10
  store i32 %0, ptr %11, align 4, !tbaa !5
  br i1 %.not2123, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %mx.promoted = load i32, ptr @mx, align 4, !tbaa !5
  br label %.lr.ph

._crit_edge:                                      ; preds = %26, %5
  tail call void @_Z3dfsi(i32 noundef %9)
  %12 = getelementptr inbounds [2000003 x i32], ptr @f, i64 0, i64 %10
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = add nsw i32 %14, %13
  store i32 %15, ptr %4, align 4, !tbaa !5
  %.018 = load i32, ptr %7, align 8, !tbaa !5
  %.not = icmp eq i32 %.018, 0
  br i1 %.not, label %._crit_edge30, label %5, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph.preheader, %26
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %26 ]
  %16 = phi i32 [ %0, %.lr.ph.preheader ], [ %21, %26 ]
  %17 = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv, %26 ]
  %18 = phi i32 [ %mx.promoted, %.lr.ph.preheader ], [ %27, %26 ]
  %19 = sext i32 %16 to i64
  %20 = getelementptr inbounds [21 x [2000003 x i32]], ptr @st, i64 0, i64 %17, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = getelementptr inbounds [21 x [2000003 x i32]], ptr @st, i64 0, i64 %indvars.iv, i64 %10
  store i32 %21, ptr %22, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = sext i32 %18 to i64
  %.not22 = icmp slt i64 %indvars.iv, %23
  br i1 %.not22, label %26, label %24

24:                                               ; preds = %.lr.ph
  %25 = trunc nuw i64 %indvars.iv.next to i32
  store i32 %25, ptr @mx, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %24, %.lr.ph
  %27 = phi i32 [ %25, %24 ], [ %18, %.lr.ph ]
  %.not21 = icmp eq i32 %21, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph, !llvm.loop !13
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 4}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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