; LLVM IR from Izaron/ACM-ICPC :: Russian Olympiad in Informatics/Regional Stage 2016/trains.ll (Z8buildWayv)

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

@n = external dso_local global i32, align 4
@go = external dso_local global [524293 x i32], align 16
@way = external dso_local global [524293 x [24 x i32]], align 16

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

6:                                                ; preds = %20, %0
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %6
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [524293 x i32], ptr @go, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %17
  %19 = getelementptr inbounds [24 x i32], ptr %18, i64 0, i64 0
  store i32 %15, ptr %19, align 16, !tbaa !5
  br label %20

20:                                               ; preds = %11
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !9

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

24:                                               ; preds = %61, %23
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = icmp slt i32 %25, 24
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %64

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

29:                                               ; preds = %57, %28
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %60

34:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %36
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = sub nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [24 x i32], ptr %37, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  store i32 %42, ptr %5, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %44
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sub nsw i32 %46, 1
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [24 x i32], ptr %45, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %52
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [24 x i32], ptr %53, i64 0, i64 %55
  store i32 %50, ptr %56, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %57

57:                                               ; preds = %34
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !5
  br label %29, !llvm.loop !11

60:                                               ; preds = %33
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %2, align 4, !tbaa !5
  br label %24, !llvm.loop !12

64:                                               ; preds = %27
  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 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 = { 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}
!12 = distinct !{!12, !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"

@n = external dso_local local_unnamed_addr global i32, align 4
@go = external dso_local local_unnamed_addr global [524293 x i32], align 16
@way = external dso_local local_unnamed_addr global [524293 x [24 x i32]], align 16

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

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %3 = icmp ult i32 %1, 4
  br i1 %3, label %.preheader16.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.preheader16.unr-lcssa:                           ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader16, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader16.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.preheader16.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader16.unr-lcssa ]
  %4 = getelementptr inbounds [524293 x i32], ptr @go, i64 0, i64 %indvars.iv.epil
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %indvars.iv.epil
  store i32 %5, ptr %6, align 16, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader16, label %.lr.ph.epil, !llvm.loop !9

.preheader16:                                     ; preds = %.lr.ph.epil, %.preheader16.unr-lcssa
  br i1 %2, label %.preheader.us.preheader, label %.split.us

.preheader.us.preheader:                          ; preds = %.preheader16
  %xtraiter32 = and i64 %wide.trip.count, 1
  %7 = icmp eq i32 %1, 1
  %unroll_iter35 = and i64 %wide.trip.count, 2147483646
  %lcmp.mod34.not = icmp eq i64 %xtraiter32, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv28 = phi i64 [ 1, %.preheader.us.preheader ], [ %indvars.iv.next29, %._crit_edge.us ]
  %8 = add nsw i64 %indvars.iv28, -1
  br i1 %7, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv23 = phi i64 [ %indvars.iv.next24.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter36 = phi i64 [ %niter36.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %9 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %indvars.iv23, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %11, i64 %8
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %indvars.iv23, i64 %indvars.iv28
  store i32 %13, ptr %14, align 4, !tbaa !5
  %indvars.iv.next24 = or disjoint i64 %indvars.iv23, 1
  %15 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %indvars.iv.next24, i64 %8
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %17, i64 %8
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %indvars.iv.next24, i64 %indvars.iv28
  store i32 %19, ptr %20, align 4, !tbaa !5
  %indvars.iv.next24.1 = add nuw nsw i64 %indvars.iv23, 2
  %niter36.next.1 = add i64 %niter36, 2
  %niter36.ncmp.1 = icmp eq i64 %niter36.next.1, %unroll_iter35
  br i1 %niter36.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !11

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %indvars.iv23.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next24.1, %.preheader.us.new ]
  br i1 %lcmp.mod34.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %21 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %indvars.iv23.unr, i64 %8
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %23, i64 %8
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %indvars.iv23.unr, i64 %indvars.iv28
  store i32 %25, ptr %26, align 4, !tbaa !5
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %exitcond31.not = icmp eq i64 %indvars.iv.next29, 24
  br i1 %exitcond31.not, label %.split.us, label %.preheader.us, !llvm.loop !13

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %27 = getelementptr inbounds [524293 x i32], ptr @go, i64 0, i64 %indvars.iv
  %28 = load i32, ptr %27, align 16, !tbaa !5
  %29 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %indvars.iv
  store i32 %28, ptr %29, align 16, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %30 = getelementptr inbounds [524293 x i32], ptr @go, i64 0, i64 %indvars.iv.next
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %indvars.iv.next
  store i32 %31, ptr %32, align 16, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %33 = getelementptr inbounds [524293 x i32], ptr @go, i64 0, i64 %indvars.iv.next.1
  %34 = load i32, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %indvars.iv.next.1
  store i32 %34, ptr %35, align 16, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %36 = getelementptr inbounds [524293 x i32], ptr @go, i64 0, i64 %indvars.iv.next.2
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = getelementptr inbounds [524293 x [24 x i32]], ptr @way, i64 0, i64 %indvars.iv.next.2
  store i32 %37, ptr %38, align 16, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader16.unr-lcssa, label %.lr.ph, !llvm.loop !14

.split.us:                                        ; preds = %._crit_edge.us, %0, %.preheader16
  ret void
}

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

!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.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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