; LLVM IR from Tunghohin/Competitive_Coding :: Hdu/hdu4612.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 }

@e = external dso_local global [6000020 x %struct.edge], align 16
@head_bcc = external dso_local global [200010 x i32], align 16
@mx = external dso_local global [200010 x i32], align 16
@smx = external dso_local global [200010 x i32], 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 @_Z3dfsii(i32 noundef %0, i32 noundef %1) #1 {
  %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 = sext i32 %9 to i64
  %11 = getelementptr inbounds [200010 x i32], ptr @smx, i64 0, i64 %10
  store i32 0, ptr %11, align 4, !tbaa !5
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [200010 x i32], ptr @mx, i64 0, i64 %13
  store i32 0, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [200010 x i32], ptr @head_bcc, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  store i32 %18, ptr %5, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %76, %2
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [6000020 x %struct.edge], ptr @e, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.edge, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !9
  store i32 %28, ptr %7, align 4, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = icmp eq i32 %29, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %23
  store i32 4, ptr %6, align 4
  br label %73

33:                                               ; preds = %23
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %34, i32 noundef %35)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [200010 x i32], ptr @mx, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !5
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [200010 x i32], ptr @mx, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = icmp sge i32 %41, %45
  br i1 %46, label %47, label %59

47:                                               ; preds = %33
  %48 = load i32, ptr %3, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [200010 x i32], ptr @mx, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [200010 x i32], ptr @smx, i64 0, i64 %53
  store i32 %51, ptr %54, align 4, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [200010 x i32], ptr @mx, i64 0, i64 %57
  store i32 %55, ptr %58, align 4, !tbaa !5
  br label %72

59:                                               ; preds = %33
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [200010 x i32], ptr @smx, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = icmp sgt i32 %60, %64
  br i1 %65, label %66, label %71

66:                                               ; preds = %59
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [200010 x i32], ptr @smx, i64 0, i64 %69
  store i32 %67, ptr %70, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %66, %59
  br label %72

72:                                               ; preds = %71, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  store i32 0, ptr %6, align 4
  br label %73

73:                                               ; preds = %72, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %74 = load i32, ptr %6, align 4
  switch i32 %74, label %83 [
    i32 0, label %75
    i32 4, label %76
  ]

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75, %73
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [6000020 x %struct.edge], ptr @e, i64 0, i64 %78
  %80 = getelementptr inbounds %struct.edge, ptr %79, i32 0, i32 2
  %81 = load i32, ptr %80, align 4, !tbaa !11
  store i32 %81, ptr %5, align 4, !tbaa !5
  br label %19, !llvm.loop !12

82:                                               ; preds = %22
  ret void

83:                                               ; preds = %73
  unreachable
}

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


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

@e = external dso_local local_unnamed_addr global [6000020 x %struct.edge], align 16
@head_bcc = external dso_local local_unnamed_addr global [200010 x i32], align 16
@mx = external dso_local local_unnamed_addr global [200010 x i32], align 16
@smx = external dso_local local_unnamed_addr global [200010 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [200010 x i32], ptr @smx, i64 0, i64 %3
  store i32 0, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds [200010 x i32], ptr @mx, i64 0, i64 %3
  store i32 0, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds [200010 x i32], ptr @head_bcc, i64 0, i64 %3
  %.026 = load i32, ptr %6, align 4, !tbaa !5
  %.not27 = icmp eq i32 %.026, 0
  br i1 %.not27, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %21, %2
  ret void

.lr.ph:                                           ; preds = %2, %21
  %.028 = phi i32 [ %.0, %21 ], [ %.026, %2 ]
  %7 = sext i32 %.028 to i64
  %8 = getelementptr inbounds [6000020 x %struct.edge], ptr @e, i64 0, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp eq i32 %10, %1
  br i1 %11, label %21, label %12

12:                                               ; preds = %.lr.ph
  tail call void @_Z3dfsii(i32 noundef %10, i32 noundef %0)
  %13 = sext i32 %10 to i64
  %14 = getelementptr inbounds [200010 x i32], ptr @mx, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %.not24 = icmp slt i32 %16, %17
  br i1 %.not24, label %19, label %18

18:                                               ; preds = %12
  store i32 %17, ptr %4, align 4, !tbaa !5
  br label %.sink.split

19:                                               ; preds = %12
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %.not25 = icmp slt i32 %15, %20
  br i1 %.not25, label %21, label %.sink.split

.sink.split:                                      ; preds = %19, %18
  %.sink = phi ptr [ %5, %18 ], [ %4, %19 ]
  store i32 %16, ptr %.sink, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %.sink.split, %19, %.lr.ph
  %22 = getelementptr inbounds i8, ptr %8, i64 8
  %.0 = load i32, ptr %22, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11
}

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, !6, i64 8}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass