; LLVM IR from eyangch/competitive-programming :: Codeforces/1486/d.ll (Z2oki)

; 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
@K = external dso_local global i32, align 4
@dp = external dso_local global [200000 x i32], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z2oki(i32 noundef %0) #1 {
  %2 = alloca i1, align 1
  %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
  %9 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %19, %1
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr @N, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %22

15:                                               ; preds = %10
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [200000 x i32], ptr @dp, i64 0, i64 %17
  store i32 0, ptr %18, align 4, !tbaa !5
  br label %19

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

22:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %34, %22
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = load i32, ptr @K, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %23
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = call noundef i32 @_Z2sfii(i32 noundef %29, i32 noundef %30)
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = add nsw i32 %32, %31
  store i32 %33, ptr %5, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %28
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %6, align 4, !tbaa !5
  br label %23, !llvm.loop !11

37:                                               ; preds = %27
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = load i32, ptr @K, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [200000 x i32], ptr @dp, i64 0, i64 %41
  store i32 %38, ptr %42, align 4, !tbaa !5
  %43 = load i32, ptr @K, align 4, !tbaa !5
  %44 = sub nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [200000 x i32], ptr @dp, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = icmp sgt i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %37
  store i1 true, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %96

50:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %51 = load i32, ptr @K, align 4, !tbaa !5
  store i32 %51, ptr %8, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %90, %50
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = load i32, ptr @N, align 4, !tbaa !5
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %52
  store i32 8, ptr %7, align 4
  br label %93

57:                                               ; preds = %52
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = call noundef i32 @_Z2sfii(i32 noundef %58, i32 noundef %59)
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = load i32, ptr @K, align 4, !tbaa !5
  %63 = sub nsw i32 %61, %62
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = call noundef i32 @_Z2sfii(i32 noundef %63, i32 noundef %64)
  %66 = sub nsw i32 %60, %65
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = add nsw i32 %67, %66
  store i32 %68, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = sub nsw i32 %69, 1
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [200000 x i32], ptr @dp, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = call noundef i32 @_Z2sfii(i32 noundef %74, i32 noundef %75)
  %77 = add nsw i32 %73, %76
  store i32 %77, ptr %9, align 4, !tbaa !5
  %78 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = load i32, ptr %8, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [200000 x i32], ptr @dp, i64 0, i64 %81
  store i32 %79, ptr %82, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %83 = load i32, ptr %8, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [200000 x i32], ptr @dp, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = icmp sgt i32 %86, 0
  br i1 %87, label %88, label %89

88:                                               ; preds = %57
  store i1 true, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %93

89:                                               ; preds = %57
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %8, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %8, align 4, !tbaa !5
  br label %52, !llvm.loop !12

93:                                               ; preds = %88, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %94 = load i32, ptr %7, align 4
  switch i32 %94, label %96 [
    i32 8, label %95
  ]

95:                                               ; preds = %93
  store i1 false, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %96

96:                                               ; preds = %95, %93, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %97 = load i1, ptr %2, align 1
  ret i1 %97
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { 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
@K = external dso_local local_unnamed_addr global i32, align 4
@dp = external dso_local local_unnamed_addr global [200000 x i32], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z2oki(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = load i32, ptr @N, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %1
  %6 = zext nneg i32 %4 to i64
  %7 = shl nuw nsw i64 %6, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @dp, i8 0, i64 %7, i1 false), !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %8 = load i32, ptr @K, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph28, label %._crit_edge29.thread

._crit_edge29.thread:                             ; preds = %._crit_edge
  store i32 0, ptr %2, align 4, !tbaa !5
  %10 = add nsw i32 %8, -1
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [200000 x i32], ptr @dp, i64 0, i64 %11
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %.preheader

._crit_edge29:                                    ; preds = %.lr.ph28
  store i32 %21, ptr %2, align 4, !tbaa !5
  %13 = add nsw i32 %23, -1
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [200000 x i32], ptr @dp, i64 0, i64 %14
  store i32 %21, ptr %15, align 4, !tbaa !5
  %16 = icmp sgt i32 %21, 0
  br i1 %16, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %._crit_edge29.thread, %._crit_edge29
  %.lcssa43 = phi i32 [ %8, %._crit_edge29.thread ], [ %23, %._crit_edge29 ]
  %17 = load i32, ptr @N, align 4, !tbaa !5
  %.not31 = icmp slt i32 %.lcssa43, %17
  br i1 %.not31, label %.lr.ph33.preheader, label %.loopexit

.lr.ph33.preheader:                               ; preds = %.preheader
  %18 = sext i32 %.lcssa43 to i64
  br label %.lr.ph33

.lr.ph28:                                         ; preds = %._crit_edge, %.lr.ph28
  %.02026 = phi i32 [ %22, %.lr.ph28 ], [ 0, %._crit_edge ]
  %19 = phi i32 [ %21, %.lr.ph28 ], [ 0, %._crit_edge ]
  %20 = tail call noundef i32 @_Z2sfii(i32 noundef %.02026, i32 noundef %0)
  %21 = add nsw i32 %19, %20
  %22 = add nuw nsw i32 %.02026, 1
  %23 = load i32, ptr @K, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %.lr.ph28, label %._crit_edge29, !llvm.loop !9

25:                                               ; preds = %.lr.ph33
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %26 = load i32, ptr @N, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %.not = icmp slt i64 %indvars.iv.next, %27
  br i1 %.not, label %.lr.ph33, label %.loopexit, !llvm.loop !11

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %25
  %indvars.iv = phi i64 [ %18, %.lr.ph33.preheader ], [ %indvars.iv.next, %25 ]
  %28 = trunc nsw i64 %indvars.iv to i32
  %29 = call noundef i32 @_Z2sfii(i32 noundef %28, i32 noundef %0)
  %30 = load i32, ptr @K, align 4, !tbaa !5
  %31 = sub nsw i32 %28, %30
  %32 = call noundef i32 @_Z2sfii(i32 noundef %31, i32 noundef %0)
  %33 = sub i32 %29, %32
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %33, %34
  store i32 %35, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %36 = add nsw i64 %indvars.iv, -1
  %37 = getelementptr inbounds [200000 x i32], ptr @dp, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = call noundef i32 @_Z2sfii(i32 noundef %28, i32 noundef %0)
  %40 = add nsw i32 %39, %38
  store i32 %40, ptr %3, align 4, !tbaa !5
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = getelementptr inbounds [200000 x i32], ptr @dp, i64 0, i64 %indvars.iv
  store i32 %42, ptr %43, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  %44 = icmp sgt i32 %42, 0
  br i1 %44, label %.loopexit, label %25

.loopexit:                                        ; preds = %.lr.ph33, %25, %.preheader, %._crit_edge29
  %.1 = phi i1 [ true, %._crit_edge29 ], [ false, %.preheader ], [ %44, %25 ], [ %44, %.lr.ph33 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  ret i1 %.1
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass