; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ (1678)

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %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
  %6 = alloca [20005 x i32], align 16
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 80020, ptr %6) #5
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %8

8:                                                ; preds = %48, %0
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr %2, align 4, !tbaa !5
  %11 = icmp ne i32 %9, 0
  br i1 %11, label %12, label %51

12:                                               ; preds = %8
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  store i32 0, ptr %5, align 4, !tbaa !5
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %23, %12
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = icmp sle i32 %15, %16
  br i1 %17, label %18, label %26

18:                                               ; preds = %14
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [20005 x i32], ptr %6, i64 0, i64 %20
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %21)
  br label %23

23:                                               ; preds = %18
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %4, align 4, !tbaa !5
  br label %14, !llvm.loop !9

26:                                               ; preds = %14
  %27 = getelementptr inbounds [20005 x i32], ptr %6, i64 0, i64 0
  %28 = getelementptr inbounds i32, ptr %27, i64 1
  %29 = getelementptr inbounds [20005 x i32], ptr %6, i64 0, i64 0
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %29, i64 %31
  %33 = getelementptr inbounds i32, ptr %32, i64 1
  call void @_ZSt4sortIPiPFbiiEEvT_S3_T0_(ptr noundef %28, ptr noundef %33, ptr noundef @_Z3cmpii)
  store i32 3, ptr %4, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %45, %26
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = icmp sle i32 %35, %36
  br i1 %37, label %38, label %48

38:                                               ; preds = %34
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [20005 x i32], ptr %6, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = add nsw i32 %43, %42
  store i32 %44, ptr %5, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %38
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = add nsw i32 %46, 3
  store i32 %47, ptr %4, align 4, !tbaa !5
  br label %34, !llvm.loop !11

48:                                               ; preds = %34
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %49)
  br label %8, !llvm.loop !12

51:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 80020, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbiiEEvT_S3_T0_(ptr noundef, ptr noundef, ptr noundef) #4

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

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

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [20005 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.start.p0(i64 80020, ptr nonnull %3) #6
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %invariant.gep = getelementptr inbounds i8, ptr %3, i64 4
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr %1, align 4, !tbaa !5
  %.not21 = icmp eq i32 %5, 0
  br i1 %.not21, label %._crit_edge24, label %.lr.ph23

.lr.ph23:                                         ; preds = %0, %._crit_edge19
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %.not1012 = icmp slt i32 %8, 1
  br i1 %.not1012, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %.lr.ph23
  %.pre = sext i32 %8 to i64
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph23, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.lr.ph23 ]
  %9 = getelementptr inbounds [20005 x i32], ptr %3, i64 0, i64 %indvars.iv
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %.not10.not = icmp slt i64 %indvars.iv, %12
  br i1 %.not10.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %12, %.lr.ph ]
  %gep = getelementptr i32, ptr %invariant.gep, i64 %.pre-phi
  call void @_ZSt4sortIPiPFbiiEEvT_S3_T0_(ptr noundef nonnull %invariant.gep, ptr noundef nonnull %gep, ptr noundef nonnull @_Z3cmpii)
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %.not1114 = icmp slt i32 %13, 3
  br i1 %.not1114, label %._crit_edge19, label %.lr.ph18.preheader

.lr.ph18.preheader:                               ; preds = %._crit_edge
  %14 = zext nneg i32 %13 to i64
  %15 = call i64 @llvm.umax.i64(i64 %14, i64 5)
  %16 = icmp ugt i32 %13, 5
  %umin.neg = sext i1 %16 to i64
  %17 = select i1 %16, i64 2, i64 1
  %18 = add nsw i64 %15, -5
  %19 = add nsw i64 %18, %umin.neg
  %20 = udiv i64 %19, 3
  %21 = add nuw nsw i64 %17, %20
  %min.iters.check = icmp ult i64 %21, 9
  br i1 %min.iters.check, label %.lr.ph18.preheader34, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph18.preheader
  %n.mod.vf = and i64 %21, 7
  %22 = icmp eq i64 %n.mod.vf, 0
  %23 = select i1 %22, i64 8, i64 %n.mod.vf
  %n.vec = sub nsw i64 %21, %23
  %24 = mul i64 %n.vec, 3
  %ind.end = add i64 %24, 3
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %57, %vector.body ]
  %vec.phi33 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %58, %vector.body ]
  %25 = mul i64 %index, 3
  %offset.idx = or disjoint i64 %25, 3
  %26 = or disjoint i64 %25, 6
  %27 = add i64 %25, 9
  %28 = add i64 %25, 12
  %29 = add i64 %25, 15
  %30 = add i64 %25, 18
  %31 = add i64 %25, 21
  %32 = add i64 %25, 24
  %33 = getelementptr inbounds [20005 x i32], ptr %3, i64 0, i64 %offset.idx
  %34 = getelementptr inbounds [20005 x i32], ptr %3, i64 0, i64 %26
  %35 = getelementptr inbounds [20005 x i32], ptr %3, i64 0, i64 %27
  %36 = getelementptr inbounds [20005 x i32], ptr %3, i64 0, i64 %28
  %37 = getelementptr inbounds [20005 x i32], ptr %3, i64 0, i64 %29
  %38 = getelementptr inbounds [20005 x i32], ptr %3, i64 0, i64 %30
  %39 = getelementptr inbounds [20005 x i32], ptr %3, i64 0, i64 %31
  %40 = getelementptr inbounds [20005 x i32], ptr %3, i64 0, i64 %32
  %41 = load i32, ptr %33, align 4, !tbaa !5
  %42 = load i32, ptr %34, align 8, !tbaa !5
  %43 = load i32, ptr %35, align 4, !tbaa !5
  %44 = load i32, ptr %36, align 16, !tbaa !5
  %45 = insertelement <4 x i32> poison, i32 %41, i64 0
  %46 = insertelement <4 x i32> %45, i32 %42, i64 1
  %47 = insertelement <4 x i32> %46, i32 %43, i64 2
  %48 = insertelement <4 x i32> %47, i32 %44, i64 3
  %49 = load i32, ptr %37, align 4, !tbaa !5
  %50 = load i32, ptr %38, align 8, !tbaa !5
  %51 = load i32, ptr %39, align 4, !tbaa !5
  %52 = load i32, ptr %40, align 16, !tbaa !5
  %53 = insertelement <4 x i32> poison, i32 %49, i64 0
  %54 = insertelement <4 x i32> %53, i32 %50, i64 1
  %55 = insertelement <4 x i32> %54, i32 %51, i64 2
  %56 = insertelement <4 x i32> %55, i32 %52, i64 3
  %57 = add <4 x i32> %48, %vec.phi
  %58 = add <4 x i32> %56, %vec.phi33
  %index.next = add nuw i64 %index, 8
  %59 = icmp eq i64 %index.next, %n.vec
  br i1 %59, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %58, %57
  %60 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  br label %.lr.ph18.preheader34

.lr.ph18.preheader34:                             ; preds = %middle.block, %.lr.ph18.preheader
  %indvars.iv28.ph = phi i64 [ 3, %.lr.ph18.preheader ], [ %ind.end, %middle.block ]
  %.016.ph = phi i32 [ 0, %.lr.ph18.preheader ], [ %60, %middle.block ]
  br label %.lr.ph18

.lr.ph18:                                         ; preds = %.lr.ph18.preheader34, %.lr.ph18
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %.lr.ph18 ], [ %indvars.iv28.ph, %.lr.ph18.preheader34 ]
  %.016 = phi i32 [ %63, %.lr.ph18 ], [ %.016.ph, %.lr.ph18.preheader34 ]
  %61 = getelementptr inbounds [20005 x i32], ptr %3, i64 0, i64 %indvars.iv28
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = add nsw i32 %62, %.016
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 3
  %.not11 = icmp ugt i64 %indvars.iv.next29, %14
  br i1 %.not11, label %._crit_edge19, label %.lr.ph18, !llvm.loop !14

._crit_edge19:                                    ; preds = %.lr.ph18, %._crit_edge
  %.0.lcssa = phi i32 [ 0, %._crit_edge ], [ %63, %.lr.ph18 ]
  %64 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.0.lcssa)
  %65 = load i32, ptr %1, align 4, !tbaa !5
  %66 = add nsw i32 %65, -1
  store i32 %66, ptr %1, align 4, !tbaa !5
  %.not = icmp eq i32 %65, 0
  br i1 %.not, label %._crit_edge24, label %.lr.ph23, !llvm.loop !15

._crit_edge24:                                    ; preds = %._crit_edge19, %0
  call void @llvm.lifetime.end.p0(i64 80020, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret i32 0
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiPFbiiEEvT_S3_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #5

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #5

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 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { inlinehint 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !10, !13, !12}
!15 = distinct !{!15, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,ReassociatePass,SROAPass,SimplifyCFGPass