; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1034. Head of a Gang (30) .ll (Z3dfsiRiS_S_)

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

@idNumber = external dso_local global i32, align 4
@G = external dso_local global [2010 x [2010 x i32]], align 16
@weight = external dso_local global [2010 x i32], align 16
@vis = external dso_local global [2010 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiRiS_S_(i32 noundef %0, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [2010 x i8], ptr @vis, i64 0, i64 %11
  store i8 1, ptr %12, align 1, !tbaa !11
  %13 = load ptr, ptr %7, align 8, !tbaa !9
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %13, align 4, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [2010 x i32], ptr @weight, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2010 x i32], ptr @weight, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp sgt i32 %19, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %4
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %27, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %26, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %81, %29
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = load i32, ptr @idNumber, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

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

35:                                               ; preds = %30
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [2010 x [2010 x i32]], ptr @G, i64 0, i64 %37
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2010 x i32], ptr %38, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = icmp sgt i32 %42, 0
  br i1 %43, label %44, label %80

44:                                               ; preds = %35
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [2010 x [2010 x i32]], ptr @G, i64 0, i64 %46
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [2010 x i32], ptr %47, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !9
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %53, %51
  store i32 %54, ptr %52, align 4, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [2010 x [2010 x i32]], ptr @G, i64 0, i64 %56
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2010 x i32], ptr %57, i64 0, i64 %59
  store i32 0, ptr %60, align 4, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2010 x [2010 x i32]], ptr @G, i64 0, i64 %62
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [2010 x i32], ptr %63, i64 0, i64 %65
  store i32 0, ptr %66, align 4, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [2010 x i8], ptr @vis, i64 0, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !11, !range !13, !noundef !14
  %71 = trunc i8 %70 to i1
  %72 = zext i1 %71 to i32
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %79

74:                                               ; preds = %44
  %75 = load i32, ptr %9, align 4, !tbaa !5
  %76 = load ptr, ptr %6, align 8, !tbaa !9
  %77 = load ptr, ptr %7, align 8, !tbaa !9
  %78 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_Z3dfsiRiS_S_(i32 noundef %75, ptr noundef nonnull align 4 dereferenceable(4) %76, ptr noundef nonnull align 4 dereferenceable(4) %77, ptr noundef nonnull align 4 dereferenceable(4) %78)
  br label %79

79:                                               ; preds = %74, %44
  br label %80

80:                                               ; preds = %79, %35
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr %9, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %9, align 4, !tbaa !5
  br label %30, !llvm.loop !15

84:                                               ; preds = %34
  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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@idNumber = external dso_local local_unnamed_addr global i32, align 4
@G = external dso_local local_unnamed_addr global [2010 x [2010 x i32]], align 16
@weight = external dso_local local_unnamed_addr global [2010 x i32], align 16
@vis = external dso_local local_unnamed_addr global [2010 x i8], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsiRiS_S_(i32 noundef %0, ptr nocapture noundef nonnull align 4 dereferenceable(4) %1, ptr nocapture noundef nonnull align 4 dereferenceable(4) %2, ptr nocapture noundef nonnull align 4 dereferenceable(4) %3) local_unnamed_addr #0 {
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [2010 x i8], ptr @vis, i64 0, i64 %5
  store i8 1, ptr %6, align 1, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !9
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %2, align 4, !tbaa !9
  %9 = getelementptr inbounds [2010 x i32], ptr @weight, i64 0, i64 %5
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = load i32, ptr %1, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [2010 x i32], ptr @weight, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = icmp sgt i32 %10, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  store i32 %0, ptr %1, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %16, %4
  %18 = load i32, ptr @idNumber, align 4, !tbaa !9
  %19 = icmp sgt i32 %18, 1
  br i1 %19, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %32, %17
  ret void

.lr.ph:                                           ; preds = %17, %32
  %indvars.iv = phi i64 [ %indvars.iv.next, %32 ], [ 1, %17 ]
  %20 = getelementptr inbounds [2010 x [2010 x i32]], ptr @G, i64 0, i64 %5, i64 %indvars.iv
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %32

23:                                               ; preds = %.lr.ph
  %24 = load i32, ptr %3, align 4, !tbaa !9
  %25 = add nsw i32 %24, %21
  store i32 %25, ptr %3, align 4, !tbaa !9
  %26 = getelementptr inbounds [2010 x [2010 x i32]], ptr @G, i64 0, i64 %indvars.iv, i64 %5
  store i32 0, ptr %26, align 4, !tbaa !9
  store i32 0, ptr %20, align 4, !tbaa !9
  %27 = getelementptr inbounds [2010 x i8], ptr @vis, i64 0, i64 %indvars.iv
  %28 = load i8, ptr %27, align 1, !tbaa !5, !range !11, !noundef !12
  %29 = icmp eq i8 %28, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %23
  %31 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_Z3dfsiRiS_S_(i32 noundef %31, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  br label %32

32:                                               ; preds = %.lr.ph, %30, %23
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = load i32, ptr @idNumber, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = icmp slt i64 %indvars.iv.next, %34
  br i1 %35, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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