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

@val = external dso_local global [100010 x i64], align 16
@dp = external dso_local global [100010 x [2 x i64]], align 16
@e = external dso_local global [100010 x %struct.edge], align 16
@head = external dso_local global [100010 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [100010 x [2 x i64]], ptr @dp, i64 0, i64 %6
  %8 = getelementptr inbounds [2 x i64], ptr %7, i64 0, i64 0
  store i64 0, ptr %8, align 16, !tbaa !9
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100010 x i64], ptr @val, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100010 x [2 x i64]], ptr @dp, i64 0, i64 %14
  %16 = getelementptr inbounds [2 x i64], ptr %15, i64 0, i64 1
  store i64 %12, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  store i32 %20, ptr %3, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %59, %1
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %25, label %24

24:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %65

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100010 x %struct.edge], ptr @e, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.edge, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !11
  store i32 %30, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3dfsi(i32 noundef %31)
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100010 x [2 x i64]], ptr @dp, i64 0, i64 %33
  %35 = getelementptr inbounds [2 x i64], ptr %34, i64 0, i64 0
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100010 x [2 x i64]], ptr @dp, i64 0, i64 %37
  %39 = getelementptr inbounds [2 x i64], ptr %38, i64 0, i64 1
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %35, ptr noundef nonnull align 8 dereferenceable(8) %39)
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100010 x [2 x i64]], ptr @dp, i64 0, i64 %43
  %45 = getelementptr inbounds [2 x i64], ptr %44, i64 0, i64 0
  %46 = load i64, ptr %45, align 16, !tbaa !9
  %47 = add nsw i64 %46, %41
  store i64 %47, ptr %45, align 16, !tbaa !9
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100010 x [2 x i64]], ptr @dp, i64 0, i64 %49
  %51 = getelementptr inbounds [2 x i64], ptr %50, i64 0, i64 0
  %52 = load i64, ptr %51, align 16, !tbaa !9
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100010 x [2 x i64]], ptr @dp, i64 0, i64 %54
  %56 = getelementptr inbounds [2 x i64], ptr %55, i64 0, i64 1
  %57 = load i64, ptr %56, align 8, !tbaa !9
  %58 = add nsw i64 %57, %52
  store i64 %58, ptr %56, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %59

59:                                               ; preds = %25
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100010 x %struct.edge], ptr @e, i64 0, i64 %61
  %63 = getelementptr inbounds %struct.edge, ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 4, !tbaa !13
  store i32 %64, ptr %3, align 4, !tbaa !5
  br label %21, !llvm.loop !14

65:                                               ; preds = %24
  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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

; 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 = { inlinehint mustprogress nounwind 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 = { 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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !15}
!15 = !{!"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 }

@val = external dso_local local_unnamed_addr global [100010 x i64], align 16
@dp = external dso_local global [100010 x [2 x i64]], align 16
@e = external dso_local local_unnamed_addr global [100010 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [100010 x [2 x i64]], ptr @dp, i64 0, i64 %2
  store i64 0, ptr %3, align 16, !tbaa !5
  %4 = getelementptr inbounds [100010 x i64], ptr @val, i64 0, i64 %2
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  store i64 %5, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds [100010 x i32], ptr @head, i64 0, i64 %2
  %.013 = load i32, ptr %7, align 4, !tbaa !9
  %.not14 = icmp eq i32 %.013, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  ret void

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.015 = phi i32 [ %.0, %.lr.ph ], [ %.013, %1 ]
  %8 = sext i32 %.015 to i64
  %9 = getelementptr inbounds [100010 x %struct.edge], ptr @e, i64 0, i64 %8
  %10 = load i32, ptr %9, align 8, !tbaa !11
  tail call void @_Z3dfsi(i32 noundef %10)
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100010 x [2 x i64]], ptr @dp, i64 0, i64 %11
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef nonnull align 8 dereferenceable(8) %13)
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = load i64, ptr %3, align 16, !tbaa !5
  %17 = add nsw i64 %16, %15
  store i64 %17, ptr %3, align 16, !tbaa !5
  %18 = load i64, ptr %12, align 16, !tbaa !5
  %19 = load i64, ptr %6, align 8, !tbaa !5
  %20 = add nsw i64 %19, %18
  store i64 %20, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %9, i64 4
  %.0 = load i32, ptr %21, align 4, !tbaa !9
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

attributes #0 = { mustprogress nounwind 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 = { inlinehint mustprogress nounwind 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS4edge", !10, i64 0, !10, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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