; LLVM IR from eyangch/competitive-programming :: Codeforces/1619/h.ll (Z3updx)

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

@S = external dso_local global i64, align 8
@P = external dso_local global [100000 x i64], align 16
@R = external dso_local global [100000 x i64], align 16
@J = external dso_local global [100000 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3updx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds [100000 x i64], ptr @J, i64 0, i64 %8
  store i64 %7, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %23, %1
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = load i64, ptr @S, align 8, !tbaa !5
  %13 = icmp slt i64 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %26

15:                                               ; preds = %10
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds [100000 x i64], ptr @J, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds [100000 x i64], ptr @P, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds [100000 x i64], ptr @J, i64 0, i64 %21
  store i64 %20, ptr %22, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %15
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = add nsw i64 %24, 1
  store i64 %25, ptr %3, align 8, !tbaa !5
  br label %10, !llvm.loop !9

26:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %27 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %27, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %28 = load i64, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds [100000 x i64], ptr @J, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !5
  store i64 %30, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %46, %26
  %32 = load i64, ptr %6, align 8, !tbaa !5
  %33 = load i64, ptr @S, align 8, !tbaa !5
  %34 = icmp slt i64 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %49

36:                                               ; preds = %31
  %37 = load i64, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !5
  store i64 %39, ptr %4, align 8, !tbaa !5
  %40 = load i64, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !5
  store i64 %42, ptr %5, align 8, !tbaa !5
  %43 = load i64, ptr %5, align 8, !tbaa !5
  %44 = load i64, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds [100000 x i64], ptr @J, i64 0, i64 %44
  store i64 %43, ptr %45, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %36
  %47 = load i64, ptr %6, align 8, !tbaa !5
  %48 = add nsw i64 %47, 1
  store i64 %48, ptr %6, align 8, !tbaa !5
  br label %31, !llvm.loop !11

49:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  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 = !{!"long long", !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"

@S = external dso_local local_unnamed_addr global i64, align 8
@P = external dso_local local_unnamed_addr global [100000 x i64], align 16
@R = external dso_local local_unnamed_addr global [100000 x i64], align 16
@J = external dso_local local_unnamed_addr global [100000 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3updx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds [100000 x i64], ptr @J, i64 0, i64 %0
  store i64 %0, ptr %2, align 8, !tbaa !5
  %3 = load i64, ptr @S, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph.preheader, label %._crit_edge24

.lr.ph.preheader:                                 ; preds = %1
  %xtraiter = and i64 %3, 7
  %5 = icmp ult i64 %3, 8
  br i1 %5, label %.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %3, 9223372036854775800
  br label %.lr.ph

.unr-lcssa:                                       ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %26, %.lr.ph ]
  %.unr = phi i64 [ %0, %.lr.ph.preheader ], [ %26, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.epilog-lcssa, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.unr-lcssa, %.lr.ph.epil
  %6 = phi i64 [ %8, %.lr.ph.epil ], [ %.unr, %.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.unr-lcssa ]
  %7 = getelementptr inbounds [100000 x i64], ptr @P, i64 0, i64 %6
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %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 %.epilog-lcssa, label %.lr.ph.epil, !llvm.loop !9

.epilog-lcssa:                                    ; preds = %.lr.ph.epil, %.unr-lcssa
  %.lcssa = phi i64 [ %.lcssa.ph, %.unr-lcssa ], [ %8, %.lr.ph.epil ]
  store i64 %.lcssa, ptr %2, align 8, !tbaa !5
  br i1 %4, label %.lr.ph23.preheader, label %._crit_edge24

.lr.ph23.preheader:                               ; preds = %.epilog-lcssa
  %xtraiter27 = and i64 %3, 3
  %9 = icmp ult i64 %3, 4
  br i1 %9, label %._crit_edge24.loopexit.unr-lcssa, label %.lr.ph23.preheader.new

.lr.ph23.preheader.new:                           ; preds = %.lr.ph23.preheader
  %unroll_iter30 = and i64 %3, 9223372036854775804
  br label %.lr.ph23

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %10 = phi i64 [ %0, %.lr.ph.preheader.new ], [ %26, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %11 = getelementptr inbounds [100000 x i64], ptr @P, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds [100000 x i64], ptr @P, i64 0, i64 %12
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds [100000 x i64], ptr @P, i64 0, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds [100000 x i64], ptr @P, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds [100000 x i64], ptr @P, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds [100000 x i64], ptr @P, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = getelementptr inbounds [100000 x i64], ptr @P, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds [100000 x i64], ptr @P, i64 0, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %niter.next.7 = add i64 %niter, 8
  %niter.ncmp.7 = icmp eq i64 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %.unr-lcssa, label %.lr.ph, !llvm.loop !11

._crit_edge24.loopexit.unr-lcssa:                 ; preds = %.lr.ph23, %.lr.ph23.preheader
  %.01420.unr = phi i64 [ %.lcssa, %.lr.ph23.preheader ], [ %50, %.lr.ph23 ]
  %.01519.unr = phi i64 [ %0, %.lr.ph23.preheader ], [ %48, %.lr.ph23 ]
  %lcmp.mod29.not = icmp eq i64 %xtraiter27, 0
  br i1 %lcmp.mod29.not, label %._crit_edge24, label %.lr.ph23.epil

.lr.ph23.epil:                                    ; preds = %._crit_edge24.loopexit.unr-lcssa, %.lr.ph23.epil
  %.01420.epil = phi i64 [ %30, %.lr.ph23.epil ], [ %.01420.unr, %._crit_edge24.loopexit.unr-lcssa ]
  %.01519.epil = phi i64 [ %28, %.lr.ph23.epil ], [ %.01519.unr, %._crit_edge24.loopexit.unr-lcssa ]
  %epil.iter28 = phi i64 [ %epil.iter28.next, %.lr.ph23.epil ], [ 0, %._crit_edge24.loopexit.unr-lcssa ]
  %27 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %.01519.epil
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %.01420.epil
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds [100000 x i64], ptr @J, i64 0, i64 %28
  store i64 %30, ptr %31, align 8, !tbaa !5
  %epil.iter28.next = add i64 %epil.iter28, 1
  %epil.iter28.cmp.not = icmp eq i64 %epil.iter28.next, %xtraiter27
  br i1 %epil.iter28.cmp.not, label %._crit_edge24, label %.lr.ph23.epil, !llvm.loop !13

._crit_edge24:                                    ; preds = %._crit_edge24.loopexit.unr-lcssa, %.lr.ph23.epil, %1, %.epilog-lcssa
  ret void

.lr.ph23:                                         ; preds = %.lr.ph23, %.lr.ph23.preheader.new
  %.01420 = phi i64 [ %.lcssa, %.lr.ph23.preheader.new ], [ %50, %.lr.ph23 ]
  %.01519 = phi i64 [ %0, %.lr.ph23.preheader.new ], [ %48, %.lr.ph23 ]
  %niter31 = phi i64 [ 0, %.lr.ph23.preheader.new ], [ %niter31.next.3, %.lr.ph23 ]
  %32 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %.01519
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %.01420
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds [100000 x i64], ptr @J, i64 0, i64 %33
  store i64 %35, ptr %36, align 8, !tbaa !5
  %37 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %33
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %35
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = getelementptr inbounds [100000 x i64], ptr @J, i64 0, i64 %38
  store i64 %40, ptr %41, align 8, !tbaa !5
  %42 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %38
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %40
  %45 = load i64, ptr %44, align 8, !tbaa !5
  %46 = getelementptr inbounds [100000 x i64], ptr @J, i64 0, i64 %43
  store i64 %45, ptr %46, align 8, !tbaa !5
  %47 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %43
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds [100000 x i64], ptr @R, i64 0, i64 %45
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = getelementptr inbounds [100000 x i64], ptr @J, i64 0, i64 %48
  store i64 %50, ptr %51, align 8, !tbaa !5
  %niter31.next.3 = add i64 %niter31, 4
  %niter31.ncmp.3 = icmp eq i64 %niter31.next.3, %unroll_iter30
  br i1 %niter31.ncmp.3, label %._crit_edge24.loopexit.unr-lcssa, label %.lr.ph23, !llvm.loop !14
}

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 = !{!"long long", !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, !10}
!14 = distinct !{!14, !12}


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