; LLVM IR from Tunghohin/Competitive_Coding :: Codeforces/cf1679_D.ll (Z4initi)

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

@n = external dso_local global i32, align 4
@val = external dso_local global [200010 x i32], align 16
@dg = external dso_local global [200010 x i32], align 16
@v = external dso_local global [200010 x i32], align 16
@vis = external dso_local global [200010 x i8], align 16
@e = external dso_local global [200010 x %struct.edge], align 16
@head = 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 nounwind uwtable
define dso_local void @_Z4initi(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
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %18, %1
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [200010 x i32], ptr @dg, i64 0, i64 %16
  store i32 0, ptr %17, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %14
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %3, align 4, !tbaa !5
  br label %9, !llvm.loop !9

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

22:                                               ; preds = %73, %21
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %22
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [200010 x i32], ptr @val, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %34, label %72

34:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [200010 x i32], ptr @head, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  store i32 %38, ptr %6, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %65, %34
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %43, label %42

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

43:                                               ; preds = %39
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.edge, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !11
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [200010 x i32], ptr @val, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = icmp sle i32 %51, %52
  br i1 %53, label %54, label %64

54:                                               ; preds = %43
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.edge, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !11
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [200010 x i32], ptr @dg, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %61, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %54, %43
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.edge, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !13
  store i32 %70, ptr %6, align 4, !tbaa !5
  br label %39, !llvm.loop !14

71:                                               ; preds = %42
  br label %72

72:                                               ; preds = %71, %27
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %4, align 4, !tbaa !5
  br label %22, !llvm.loop !15

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

77:                                               ; preds = %93, %76
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = load i32, ptr @n, align 4, !tbaa !5
  %80 = icmp sle i32 %78, %79
  br i1 %80, label %82, label %81

81:                                               ; preds = %77
  store i32 11, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %96

82:                                               ; preds = %77
  %83 = load i32, ptr %7, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [200010 x i32], ptr @val, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = load i32, ptr %2, align 4, !tbaa !5
  %88 = icmp sle i32 %86, %87
  %89 = zext i1 %88 to i32
  %90 = load i32, ptr %7, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [200010 x i32], ptr @v, i64 0, i64 %91
  store i32 %89, ptr %92, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %82
  %94 = load i32, ptr %7, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %7, align 4, !tbaa !5
  br label %77, !llvm.loop !16

96:                                               ; preds = %81
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %97

97:                                               ; preds = %106, %96
  %98 = load i32, ptr %8, align 4, !tbaa !5
  %99 = load i32, ptr @n, align 4, !tbaa !5
  %100 = icmp sle i32 %98, %99
  br i1 %100, label %102, label %101

101:                                              ; preds = %97
  store i32 14, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %109

102:                                              ; preds = %97
  %103 = load i32, ptr %8, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [200010 x i8], ptr @vis, i64 0, i64 %104
  store i8 0, ptr %105, align 1, !tbaa !17
  br label %106

106:                                              ; preds = %102
  %107 = load i32, ptr %8, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %8, align 4, !tbaa !5
  br label %97, !llvm.loop !19

109:                                              ; preds = %101
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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"}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 4}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = !{!18, !18, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = distinct !{!19, !10}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@val = external dso_local local_unnamed_addr global [200010 x i32], align 16
@dg = external dso_local local_unnamed_addr global [200010 x i32], align 16
@v = external dso_local local_unnamed_addr global [200010 x i32], align 16
@vis = external dso_local local_unnamed_addr global [200010 x i8], align 16
@e = external dso_local local_unnamed_addr global [200010 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [200010 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4initi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not34 = icmp slt i32 %2, 1
  br i1 %.not34, label %._crit_edge, label %.lr.ph42.preheader

.lr.ph42.preheader:                               ; preds = %1
  %3 = zext nneg i32 %2 to i64
  %4 = shl nuw nsw i64 %3, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @dg, i64 4), i8 0, i64 %4, i1 false), !tbaa !5
  %5 = add nuw i32 %2, 1
  %wide.trip.count = zext i32 %5 to i64
  br label %.lr.ph42

.preheader32:                                     ; preds = %.loopexit
  br i1 %.not34, label %._crit_edge, label %.lr.ph45.preheader

.lr.ph45.preheader:                               ; preds = %.preheader32
  %6 = add nuw i32 %2, 1
  %wide.trip.count54 = zext i32 %6 to i64
  %7 = zext nneg i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 8
  br i1 %min.iters.check, label %.lr.ph45.preheader60, label %vector.ph

.lr.ph45.preheader60:                             ; preds = %middle.block, %.lr.ph45.preheader
  %indvars.iv51.ph = phi i64 [ 1, %.lr.ph45.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph45

vector.ph:                                        ; preds = %.lr.ph45.preheader
  %n.vec = and i64 %7, 2147483640
  %ind.end = or disjoint i64 %n.vec, 1
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %0, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %8 = getelementptr inbounds [200010 x i32], ptr @val, i64 0, i64 %offset.idx
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %wide.load = load <4 x i32>, ptr %8, align 4, !tbaa !5
  %wide.load59 = load <4 x i32>, ptr %9, align 4, !tbaa !5
  %10 = icmp sle <4 x i32> %wide.load, %broadcast.splat
  %11 = icmp sle <4 x i32> %wide.load59, %broadcast.splat
  %12 = zext <4 x i1> %10 to <4 x i32>
  %13 = zext <4 x i1> %11 to <4 x i32>
  %14 = getelementptr inbounds [200010 x i32], ptr @v, i64 0, i64 %offset.idx
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  store <4 x i32> %12, ptr %14, align 4, !tbaa !5
  store <4 x i32> %13, ptr %15, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %7
  br i1 %cmp.n, label %.preheader, label %.lr.ph45.preheader60

.lr.ph42:                                         ; preds = %.lr.ph42.preheader, %.loopexit
  %indvars.iv = phi i64 [ 1, %.lr.ph42.preheader ], [ %indvars.iv.next, %.loopexit ]
  %17 = getelementptr inbounds [200010 x i32], ptr @val, i64 0, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not29 = icmp sgt i32 %18, %0
  br i1 %.not29, label %.loopexit, label %19

19:                                               ; preds = %.lr.ph42
  %20 = getelementptr inbounds [200010 x i32], ptr @head, i64 0, i64 %indvars.iv
  %.02236 = load i32, ptr %20, align 4, !tbaa !5
  %.not3037 = icmp eq i32 %.02236, 0
  br i1 %.not3037, label %.loopexit, label %.lr.ph39

.lr.ph39:                                         ; preds = %19, %31
  %.02238 = phi i32 [ %.022, %31 ], [ %.02236, %19 ]
  %21 = sext i32 %.02238 to i64
  %22 = getelementptr inbounds [200010 x %struct.edge], ptr @e, i64 0, i64 %21
  %23 = load i32, ptr %22, align 8, !tbaa !13
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [200010 x i32], ptr @val, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %.not31 = icmp sgt i32 %26, %0
  br i1 %.not31, label %31, label %27

27:                                               ; preds = %.lr.ph39
  %28 = getelementptr inbounds [200010 x i32], ptr @dg, i64 0, i64 %24
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %28, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %.lr.ph39, %27
  %32 = getelementptr inbounds i8, ptr %22, i64 4
  %.022 = load i32, ptr %32, align 4, !tbaa !5
  %.not30 = icmp eq i32 %.022, 0
  br i1 %.not30, label %.loopexit, label %.lr.ph39, !llvm.loop !15

.loopexit:                                        ; preds = %31, %19, %.lr.ph42
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.preheader32, label %.lr.ph42, !llvm.loop !16

.preheader:                                       ; preds = %.lr.ph45, %middle.block
  br i1 %.not34, label %._crit_edge, label %.lr.ph48.preheader

.lr.ph48.preheader:                               ; preds = %.preheader
  %33 = zext nneg i32 %2 to i64
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 getelementptr inbounds (i8, ptr @vis, i64 1), i8 0, i64 %33, i1 false), !tbaa !17
  br label %._crit_edge

.lr.ph45:                                         ; preds = %.lr.ph45.preheader60, %.lr.ph45
  %indvars.iv51 = phi i64 [ %indvars.iv.next52, %.lr.ph45 ], [ %indvars.iv51.ph, %.lr.ph45.preheader60 ]
  %34 = getelementptr inbounds [200010 x i32], ptr @val, i64 0, i64 %indvars.iv51
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp sle i32 %35, %0
  %37 = zext i1 %36 to i32
  %38 = getelementptr inbounds [200010 x i32], ptr @v, i64 0, i64 %indvars.iv51
  store i32 %37, ptr %38, align 4, !tbaa !5
  %indvars.iv.next52 = add nuw nsw i64 %indvars.iv51, 1
  %exitcond55.not = icmp eq i64 %indvars.iv.next52, %wide.trip.count54
  br i1 %exitcond55.not, label %.preheader, label %.lr.ph45, !llvm.loop !19

._crit_edge:                                      ; preds = %1, %.preheader32, %.lr.ph48.preheader, %.preheader
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse 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" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = !{!18, !18, i64 0}
!18 = !{!"bool", !7, i64 0}
!19 = distinct !{!19, !10, !12, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass