; LLVM IR from lzyrapx/Competitive-Programming :: hihocoder (1038(dp))

; 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
@m = external dso_local global i32, align 4
@w = external dso_local global [505 x i32], align 16
@p = external dso_local global [505 x i32], align 16
@f = external dso_local global [100005 x i32], align 16
@i = external dso_local global i32, align 4
@j = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  store i32 0, ptr @i, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %15, %0
  %4 = load i32, ptr @i, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp slt i32 %4, %5
  br i1 %6, label %7, label %18

7:                                                ; preds = %3
  %8 = load i32, ptr @i, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [505 x i32], ptr @w, i64 0, i64 %9
  %11 = load i32, ptr @i, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [505 x i32], ptr @p, i64 0, i64 %12
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %10, ptr noundef %13)
  br label %15

15:                                               ; preds = %7
  %16 = load i32, ptr @i, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr @i, align 4, !tbaa !5
  br label %3, !llvm.loop !9

18:                                               ; preds = %3
  store i32 0, ptr @i, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %81, %18
  %20 = load i32, ptr @i, align 4, !tbaa !5
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %84

23:                                               ; preds = %19
  %24 = load i32, ptr @m, align 4, !tbaa !5
  store i32 %24, ptr @j, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %77, %23
  %26 = load i32, ptr @j, align 4, !tbaa !5
  %27 = load i32, ptr @i, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [505 x i32], ptr @w, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = icmp sge i32 %26, %30
  br i1 %31, label %32, label %80

32:                                               ; preds = %25
  %33 = load i32, ptr @j, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100005 x i32], ptr @f, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr @j, align 4, !tbaa !5
  %38 = load i32, ptr @i, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [505 x i32], ptr @w, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = sub nsw i32 %37, %41
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100005 x i32], ptr @f, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = load i32, ptr @i, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [505 x i32], ptr @p, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = add nsw i32 %45, %49
  %51 = icmp sgt i32 %36, %50
  br i1 %51, label %52, label %57

52:                                               ; preds = %32
  %53 = load i32, ptr @j, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100005 x i32], ptr @f, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  br label %72

57:                                               ; preds = %32
  %58 = load i32, ptr @j, align 4, !tbaa !5
  %59 = load i32, ptr @i, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [505 x i32], ptr @w, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = sub nsw i32 %58, %62
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [100005 x i32], ptr @f, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = load i32, ptr @i, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [505 x i32], ptr @p, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = add nsw i32 %66, %70
  br label %72

72:                                               ; preds = %57, %52
  %73 = phi i32 [ %56, %52 ], [ %71, %57 ]
  %74 = load i32, ptr @j, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [100005 x i32], ptr @f, i64 0, i64 %75
  store i32 %73, ptr %76, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %72
  %78 = load i32, ptr @j, align 4, !tbaa !5
  %79 = add nsw i32 %78, -1
  store i32 %79, ptr @j, align 4, !tbaa !5
  br label %25, !llvm.loop !11

80:                                               ; preds = %25
  br label %81

81:                                               ; preds = %80
  %82 = load i32, ptr @i, align 4, !tbaa !5
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr @i, align 4, !tbaa !5
  br label %19, !llvm.loop !12

84:                                               ; preds = %19
  %85 = load i32, ptr @m, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [100005 x i32], ptr @f, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %88)
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

declare i32 @printf(ptr noundef, ...) #1

attributes #0 = { mustprogress norecurse 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 = { "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"}
!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 global i32, align 4
@m = external dso_local global i32, align 4
@w = external dso_local global [505 x i32], align 16
@p = external dso_local global [505 x i32], align 16
@f = external dso_local local_unnamed_addr global [100005 x i32], align 16
@i = external dso_local local_unnamed_addr global i32, align 4
@j = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  store i32 0, ptr @i, align 4, !tbaa !5
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.preheader.thread

.preheader.thread:                                ; preds = %0
  %.pre25 = load i32, ptr @m, align 4, !tbaa !5
  br label %.preheader._crit_edge

.preheader:                                       ; preds = %.lr.ph
  %4 = icmp sgt i32 %16, 0
  %.pre = load i32, ptr @m, align 4, !tbaa !5
  br i1 %4, label %.lr.ph13, label %.preheader._crit_edge

.preheader._crit_edge:                            ; preds = %.preheader.thread, %.preheader
  %.pre26 = phi i32 [ %.pre25, %.preheader.thread ], [ %.pre, %.preheader ]
  %.pre23 = sext i32 %.pre26 to i64
  br label %54

.lr.ph13:                                         ; preds = %.preheader
  %5 = sext i32 %.pre to i64
  %wide.trip.count = zext nneg i32 %16 to i64
  %6 = shl nsw i64 %5, 2
  %scevgep = getelementptr i8, ptr @f, i64 %6
  %scevgep27 = getelementptr i8, ptr @f, i64 %6
  %7 = shl nsw i64 %5, 2
  %8 = add nsw i64 %7, 4
  %scevgep33 = getelementptr i8, ptr @f, i64 %8
  %scevgep34 = getelementptr i8, ptr @f, i64 %8
  %9 = add nsw i64 %5, 1
  %bound1 = icmp ugt ptr %scevgep33, @f
  br label %18

.lr.ph:                                           ; preds = %0, %.lr.ph
  %storemerge7 = phi i32 [ %15, %.lr.ph ], [ 0, %0 ]
  %10 = sext i32 %storemerge7 to i64
  %11 = getelementptr inbounds [505 x i32], ptr @w, i64 0, i64 %10
  %12 = getelementptr inbounds [505 x i32], ptr @p, i64 0, i64 %10
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %11, ptr noundef nonnull %12)
  %14 = load i32, ptr @i, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr @i, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %.lr.ph, label %.preheader, !llvm.loop !9

18:                                               ; preds = %.lr.ph13, %._crit_edge
  %indvars.iv20 = phi i64 [ 0, %.lr.ph13 ], [ %indvars.iv.next21, %._crit_edge ]
  %19 = getelementptr inbounds [505 x i32], ptr @w, i64 0, i64 %indvars.iv20
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %.not8 = icmp slt i32 %.pre, %20
  br i1 %.not8, label %._crit_edge, label %.lr.ph10

.lr.ph10:                                         ; preds = %18
  %21 = getelementptr inbounds [505 x i32], ptr @p, i64 0, i64 %indvars.iv20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sext i32 %20 to i64
  %24 = sub nsw i64 %9, %23
  %min.iters.check = icmp ult i64 %24, 24
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph10
  %25 = sub nsw i64 %5, %23
  %mul.result.neg = mul nsw i64 %25, -4
  %26 = getelementptr i8, ptr %scevgep, i64 %mul.result.neg
  %27 = icmp ugt ptr %26, %scevgep
  %28 = mul nsw i64 %23, -4
  %scevgep28 = getelementptr i8, ptr %scevgep27, i64 %28
  %mul.result30.neg = mul nsw i64 %25, -4
  %mul.overflow31 = icmp ugt i64 %25, 4611686018427387903
  %29 = getelementptr i8, ptr %scevgep28, i64 %mul.result30.neg
  %30 = icmp ugt ptr %29, %scevgep28
  %31 = or i1 %30, %mul.overflow31
  %32 = or i1 %27, %31
  br i1 %32, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %33 = shl nsw i64 %23, 2
  %scevgep32 = getelementptr i8, ptr @f, i64 %33
  %34 = mul nsw i64 %23, -4
  %scevgep35 = getelementptr i8, ptr %scevgep34, i64 %34
  %bound0 = icmp ult ptr %scevgep32, %scevgep35
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %24, -8
  %ind.end = sub nsw i64 %5, %n.vec
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %22, i64 0
  %35 = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  %36 = 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 = sub i64 %5, %index
  %37 = getelementptr inbounds [100005 x i32], ptr @f, i64 0, i64 %offset.idx
  %38 = getelementptr inbounds i8, ptr %37, i64 -12
  %39 = getelementptr inbounds i8, ptr %37, i64 -28
  %wide.load = load <4 x i32>, ptr %38, align 4, !tbaa !5, !alias.scope !11, !noalias !14
  %wide.load36 = load <4 x i32>, ptr %39, align 4, !tbaa !5, !alias.scope !11, !noalias !14
  %40 = sub nsw i64 %offset.idx, %23
  %41 = getelementptr inbounds [100005 x i32], ptr @f, i64 0, i64 %40
  %42 = getelementptr inbounds i8, ptr %41, i64 -12
  %43 = getelementptr inbounds i8, ptr %41, i64 -28
  %wide.load38 = load <4 x i32>, ptr %42, align 4, !tbaa !5, !alias.scope !14
  %wide.load40 = load <4 x i32>, ptr %43, align 4, !tbaa !5, !alias.scope !14
  %44 = add nsw <4 x i32> %35, %wide.load38
  %reverse42 = tail call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load, <4 x i32> %44)
  store <4 x i32> %reverse42, ptr %38, align 4, !tbaa !5, !alias.scope !11, !noalias !14
  %45 = add nsw <4 x i32> %36, %wide.load40
  %reverse43 = tail call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load36, <4 x i32> %45)
  store <4 x i32> %reverse43, ptr %39, align 4, !tbaa !5, !alias.scope !11, !noalias !14
  %index.next = add nuw i64 %index, 8
  %46 = icmp eq i64 %index.next, %n.vec
  br i1 %46, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %24, %n.vec
  br i1 %cmp.n, label %._crit_edge.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %vector.scevcheck, %.lr.ph10
  %indvars.iv.ph = phi i64 [ %5, %vector.memcheck ], [ %5, %vector.scevcheck ], [ %5, %.lr.ph10 ], [ %ind.end, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %47 = getelementptr inbounds [100005 x i32], ptr @f, i64 0, i64 %indvars.iv
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sub nsw i64 %indvars.iv, %23
  %50 = getelementptr inbounds [100005 x i32], ptr @f, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = add nsw i32 %22, %51
  %. = tail call i32 @llvm.smax.i32(i32 %48, i32 %52)
  store i32 %., ptr %47, align 4, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %.not.not = icmp sgt i64 %indvars.iv, %23
  br i1 %.not.not, label %scalar.ph, label %._crit_edge.loopexit, !llvm.loop !19

._crit_edge.loopexit:                             ; preds = %scalar.ph, %middle.block
  %indvars.iv.next.lcssa = phi i64 [ %ind.end, %middle.block ], [ %indvars.iv.next, %scalar.ph ]
  %53 = trunc nsw i64 %indvars.iv.next.lcssa to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %18
  %storemerge6.lcssa = phi i32 [ %.pre, %18 ], [ %53, %._crit_edge.loopexit ]
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next21, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge14, label %18, !llvm.loop !20

._crit_edge14:                                    ; preds = %._crit_edge
  store i32 %storemerge6.lcssa, ptr @j, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %.preheader._crit_edge, %._crit_edge14
  %.pre-phi = phi i64 [ %.pre23, %.preheader._crit_edge ], [ %5, %._crit_edge14 ]
  %storemerge5.lcssa = phi i32 [ 0, %.preheader._crit_edge ], [ %16, %._crit_edge14 ]
  store i32 %storemerge5.lcssa, ptr @i, align 4, !tbaa !5
  %55 = getelementptr inbounds [100005 x i32], ptr @f, i64 0, i64 %.pre-phi
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %56)
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.smax.v4i32(<4 x i32>, <4 x i32>) #2

attributes #0 = { mustprogress nofree norecurse 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 = { nofree nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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}
!12 = distinct !{!12, !13}
!13 = distinct !{!13, !"LVerDomain"}
!14 = !{!15}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !10, !17, !18}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = distinct !{!19, !10, !17}
!20 = distinct !{!20, !10}


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