; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2018-19/Dec 2018/Plat/gathering.ll (Z7genEdgev)

; 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.LCA = type { i32, i32, i32, [100001 x %"class.std::vector"], [17 x [100001 x i32]], [100001 x i32] }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.Topo = type { i32, [100001 x i32], [100001 x i32], %"class.std::vector", [100001 x %"class.std::vector"] }

@N = external dso_local global i32, align 4
@dir = external dso_local global [100001 x i32], align 16
@L = external dso_local global %struct.LCA, align 8
@T = external dso_local global %struct.Topo, align 8

; 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
declare dso_local void @_Z4dfs0i(i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4dfs1i(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7genEdgev() #1 {
  %1 = alloca i32, align 4
  call void @_Z4dfs0i(i32 noundef 1)
  call void @_Z4dfs1i(i32 noundef 1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 2, ptr %1, align 4, !tbaa !5
  br label %2

2:                                                ; preds = %34, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = load i32, ptr @N, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  %6 = icmp slt i32 %3, %5
  br i1 %6, label %8, label %7

7:                                                ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %37

8:                                                ; preds = %2
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100001 x i32], ptr @dir, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %14, label %20

14:                                               ; preds = %8
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100001 x i32], ptr getelementptr inbounds (%struct.LCA, ptr @L, i32 0, i32 4), i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  call void @_ZN4TopoILi100001EE7addEdgeEii(ptr noundef nonnull align 8 dereferenceable(3200064) @T, i32 noundef %15, i32 noundef %19)
  br label %33

20:                                               ; preds = %8
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100001 x i32], ptr @dir, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 1
  br i1 %25, label %26, label %32

26:                                               ; preds = %20
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100001 x i32], ptr getelementptr inbounds (%struct.LCA, ptr @L, i32 0, i32 4), i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load i32, ptr %1, align 4, !tbaa !5
  call void @_ZN4TopoILi100001EE7addEdgeEii(ptr noundef nonnull align 8 dereferenceable(3200064) @T, i32 noundef %30, i32 noundef %31)
  br label %32

32:                                               ; preds = %26, %20
  br label %33

33:                                               ; preds = %32, %14
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %1, align 4, !tbaa !5
  br label %2, !llvm.loop !9

37:                                               ; preds = %7
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4TopoILi100001EE7addEdgeEii(ptr noundef nonnull align 8 dereferenceable(3200064), i32 noundef, i32 noundef) #1 align 2

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 = distinct !{!9, !10}
!10 = !{!"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.LCA = type { i32, i32, i32, [100001 x %"class.std::vector"], [17 x [100001 x i32]], [100001 x i32] }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.Topo = type { i32, [100001 x i32], [100001 x i32], %"class.std::vector", [100001 x %"class.std::vector"] }

@N = external dso_local local_unnamed_addr global i32, align 4
@dir = external dso_local local_unnamed_addr global [100001 x i32], align 16
@L = external dso_local local_unnamed_addr global %struct.LCA, align 8
@T = external dso_local global %struct.Topo, align 8

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7genEdgev() local_unnamed_addr #0 {
  tail call void @_Z4dfs0i(i32 noundef 1)
  tail call void @_Z4dfs1i(i32 noundef 1)
  %1 = load i32, ptr @N, align 4, !tbaa !5
  %.not9 = icmp slt i32 %1, 2
  br i1 %.not9, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %12, %0
  ret void

.lr.ph:                                           ; preds = %0, %12
  %indvars.iv = phi i64 [ %indvars.iv.next, %12 ], [ 2, %0 ]
  %2 = getelementptr inbounds [100001 x i32], ptr @dir, i64 0, i64 %indvars.iv
  %3 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %3, label %12 [
    i32 -1, label %4
    i32 1, label %8
  ]

4:                                                ; preds = %.lr.ph
  %5 = getelementptr inbounds [100001 x i32], ptr getelementptr inbounds (i8, ptr @L, i64 2400040), i64 0, i64 %indvars.iv
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_ZN4TopoILi100001EE7addEdgeEii(ptr noundef nonnull align 8 dereferenceable(3200064) @T, i32 noundef %7, i32 noundef %6)
  br label %12

8:                                                ; preds = %.lr.ph
  %9 = getelementptr inbounds [100001 x i32], ptr getelementptr inbounds (i8, ptr @L, i64 2400040), i64 0, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @_ZN4TopoILi100001EE7addEdgeEii(ptr noundef nonnull align 8 dereferenceable(3200064) @T, i32 noundef %10, i32 noundef %11)
  br label %12

12:                                               ; preds = %.lr.ph, %4, %8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = load i32, ptr @N, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %.not.not = icmp slt i64 %indvars.iv, %14
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4TopoILi100001EE7addEdgeEii(ptr noundef nonnull align 8 dereferenceable(3200064), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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