; LLVM IR from tangjz/acm-icpc :: codeforces/complete/235C.ll (Z6appendi)

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

@rt = external dso_local global i32, align 4
@last = external dso_local global i32, align 4
@dep = external dso_local global [2000003 x i32], align 16
@par = external dso_local global [2000003 x i32], align 16
@son = external dso_local global [2000003 x [27 x i32]], align 16
@sz = external dso_local global [2000003 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7newNodei(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6appendi(i32 noundef %0) #0 {
  %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
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %7 = load i32, ptr @last, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [2000003 x i32], ptr @dep, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  %12 = call noundef i32 @_Z7newNodei(i32 noundef %11)
  store i32 %12, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %13 = load i32, ptr @last, align 4, !tbaa !5
  store i32 %13, ptr %4, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %30, %1
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %27

17:                                               ; preds = %14
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [2000003 x [27 x i32]], ptr @son, i64 0, i64 %19
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [27 x i32], ptr %20, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  %26 = xor i1 %25, true
  br label %27

27:                                               ; preds = %17, %14
  %28 = phi i1 [ false, %14 ], [ %26, %17 ]
  br i1 %28, label %29, label %42

29:                                               ; preds = %27
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2000003 x [27 x i32]], ptr @son, i64 0, i64 %33
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [27 x i32], ptr %34, i64 0, i64 %36
  store i32 %31, ptr %37, align 4, !tbaa !5
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  store i32 %41, ptr %4, align 4, !tbaa !5
  br label %14, !llvm.loop !9

42:                                               ; preds = %27
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %50, label %45

45:                                               ; preds = %42
  %46 = load i32, ptr @rt, align 4, !tbaa !5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %48
  store i32 %46, ptr %49, align 4, !tbaa !5
  br label %132

50:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [2000003 x [27 x i32]], ptr @son, i64 0, i64 %52
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [27 x i32], ptr %53, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  store i32 %57, ptr %5, align 4, !tbaa !5
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2000003 x i32], ptr @dep, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [2000003 x i32], ptr @dep, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = icmp eq i32 %61, %66
  br i1 %67, label %68, label %73

68:                                               ; preds = %50
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %71
  store i32 %69, ptr %72, align 4, !tbaa !5
  br label %131

73:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [2000003 x i32], ptr @dep, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  %79 = call noundef i32 @_Z7newNodei(i32 noundef %78)
  store i32 %79, ptr %6, align 4, !tbaa !5
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [2000003 x [27 x i32]], ptr @son, i64 0, i64 %81
  %83 = getelementptr inbounds [27 x i32], ptr %82, i64 0, i64 0
  %84 = load i32, ptr %5, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [2000003 x [27 x i32]], ptr @son, i64 0, i64 %85
  %87 = getelementptr inbounds [27 x i32], ptr %86, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %83, ptr align 4 %87, i64 108, i1 false)
  %88 = load i32, ptr %5, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = load i32, ptr %6, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %93
  store i32 %91, ptr %94, align 4, !tbaa !5
  %95 = load i32, ptr %6, align 4, !tbaa !5
  %96 = load i32, ptr %5, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %97
  store i32 %95, ptr %98, align 4, !tbaa !5
  %99 = load i32, ptr %3, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %100
  store i32 %95, ptr %101, align 4, !tbaa !5
  br label %102

102:                                              ; preds = %118, %73
  %103 = load i32, ptr %4, align 4, !tbaa !5
  %104 = icmp ne i32 %103, 0
  br i1 %104, label %105, label %115

105:                                              ; preds = %102
  %106 = load i32, ptr %4, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [2000003 x [27 x i32]], ptr @son, i64 0, i64 %107
  %109 = load i32, ptr %2, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [27 x i32], ptr %108, i64 0, i64 %110
  %112 = load i32, ptr %111, align 4, !tbaa !5
  %113 = load i32, ptr %5, align 4, !tbaa !5
  %114 = icmp eq i32 %112, %113
  br label %115

115:                                              ; preds = %105, %102
  %116 = phi i1 [ false, %102 ], [ %114, %105 ]
  br i1 %116, label %117, label %130

117:                                              ; preds = %115
  br label %118

118:                                              ; preds = %117
  %119 = load i32, ptr %6, align 4, !tbaa !5
  %120 = load i32, ptr %4, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [2000003 x [27 x i32]], ptr @son, i64 0, i64 %121
  %123 = load i32, ptr %2, align 4, !tbaa !5
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds [27 x i32], ptr %122, i64 0, i64 %124
  store i32 %119, ptr %125, align 4, !tbaa !5
  %126 = load i32, ptr %4, align 4, !tbaa !5
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %127
  %129 = load i32, ptr %128, align 4, !tbaa !5
  store i32 %129, ptr %4, align 4, !tbaa !5
  br label %102, !llvm.loop !11

130:                                              ; preds = %115
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %131

131:                                              ; preds = %130, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %132

132:                                              ; preds = %131, %45
  %133 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %133, ptr @last, align 4, !tbaa !5
  %134 = load i32, ptr @last, align 4, !tbaa !5
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [2000003 x i32], ptr @sz, i64 0, i64 %135
  %137 = load i32, ptr %136, align 4, !tbaa !5
  %138 = add nsw i32 %137, 1
  store i32 %138, ptr %136, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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"

@rt = external dso_local local_unnamed_addr global i32, align 4
@last = external dso_local local_unnamed_addr global i32, align 4
@dep = external dso_local local_unnamed_addr global [2000003 x i32], align 16
@par = external dso_local local_unnamed_addr global [2000003 x i32], align 16
@son = external dso_local local_unnamed_addr global [2000003 x [27 x i32]], align 16
@sz = external dso_local local_unnamed_addr global [2000003 x i32], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6appendi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @last, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [2000003 x i32], ptr @dep, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  %7 = tail call noundef i32 @_Z7newNodei(i32 noundef %6)
  %.041 = load i32, ptr @last, align 4, !tbaa !5
  %.not42 = icmp eq i32 %.041, 0
  br i1 %.not42, label %.critedge37, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %8 = sext i32 %0 to i64
  br label %9

9:                                                ; preds = %.lr.ph, %13
  %.043 = phi i32 [ %.041, %.lr.ph ], [ %.0, %13 ]
  %10 = sext i32 %.043 to i64
  %11 = getelementptr inbounds [2000003 x [27 x i32]], ptr @son, i64 0, i64 %10, i64 %8
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %.not35 = icmp eq i32 %12, 0
  br i1 %.not35, label %13, label %.critedge

13:                                               ; preds = %9
  store i32 %7, ptr %11, align 4, !tbaa !5
  %14 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %10
  %.0 = load i32, ptr %14, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %.critedge37, label %9, !llvm.loop !9

.critedge37:                                      ; preds = %13, %1
  %15 = load i32, ptr @rt, align 4, !tbaa !5
  br label %.critedge2.sink.split

.critedge:                                        ; preds = %9
  %16 = sext i32 %12 to i64
  %17 = getelementptr inbounds [2000003 x i32], ptr @dep, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = getelementptr inbounds [2000003 x i32], ptr @dep, i64 0, i64 %10
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  %22 = icmp eq i32 %18, %21
  br i1 %22, label %.critedge2.sink.split, label %23

23:                                               ; preds = %.critedge
  %24 = tail call noundef i32 @_Z7newNodei(i32 noundef %21)
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [2000003 x [27 x i32]], ptr @son, i64 0, i64 %25
  %27 = getelementptr inbounds [2000003 x [27 x i32]], ptr @son, i64 0, i64 %16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(108) %26, ptr noundef nonnull align 4 dereferenceable(108) %27, i64 108, i1 false)
  %28 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %16
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %25
  store i32 %29, ptr %30, align 4, !tbaa !5
  store i32 %24, ptr %28, align 4, !tbaa !5
  %31 = sext i32 %7 to i64
  %32 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %31
  store i32 %24, ptr %32, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %23, %38
  %.144 = phi i32 [ %.043, %23 ], [ %40, %38 ]
  %34 = sext i32 %.144 to i64
  %35 = getelementptr inbounds [2000003 x [27 x i32]], ptr @son, i64 0, i64 %34, i64 %8
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp eq i32 %36, %12
  br i1 %37, label %38, label %.critedge2

38:                                               ; preds = %33
  store i32 %24, ptr %35, align 4, !tbaa !5
  %39 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %34
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %.not36 = icmp eq i32 %40, 0
  br i1 %.not36, label %.critedge2, label %33, !llvm.loop !11

.critedge2.sink.split:                            ; preds = %.critedge, %.critedge37
  %.lcssa.sink = phi i32 [ %15, %.critedge37 ], [ %12, %.critedge ]
  %41 = sext i32 %7 to i64
  %42 = getelementptr inbounds [2000003 x i32], ptr @par, i64 0, i64 %41
  store i32 %.lcssa.sink, ptr %42, align 4, !tbaa !5
  br label %.critedge2

.critedge2:                                       ; preds = %38, %33, %.critedge2.sink.split
  %.pre-phi = phi i64 [ %41, %.critedge2.sink.split ], [ %31, %33 ], [ %31, %38 ]
  store i32 %7, ptr @last, align 4, !tbaa !5
  %43 = getelementptr inbounds [2000003 x i32], ptr @sz, i64 0, i64 %.pre-phi
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %43, align 4, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass