; LLVM IR from upupming/algorithm :: codeforces/1256-B.ll (Z4minSii)

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

@a = external dso_local global [110 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4minSii(i32 noundef %0, i32 noundef %1) #0 {
  %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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp sge i32 %9, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  br label %72

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1073741823, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %14 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %14, ptr %7, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %34, %13
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = icmp sle i32 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %37

20:                                               ; preds = %15
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %33

27:                                               ; preds = %20
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %6, align 4, !tbaa !5
  %32 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %32, ptr %5, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %27, %20
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %7, align 4, !tbaa !5
  br label %15, !llvm.loop !9

37:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %38 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %38, ptr %8, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %53, %37
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = icmp sgt i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %56

44:                                               ; preds = %39
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = sub nsw i32 %45, 1
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %51
  store i32 %49, ptr %52, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %44
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %8, align 4, !tbaa !5
  br label %39, !llvm.loop !11

56:                                               ; preds = %43
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %59
  store i32 %57, ptr %60, align 4, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = icmp eq i32 %61, %62
  br i1 %63, label %64, label %67

64:                                               ; preds = %56
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  br label %69

67:                                               ; preds = %56
  %68 = load i32, ptr %5, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %67, %64
  %70 = phi i32 [ %66, %64 ], [ %68, %67 ]
  %71 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z4minSii(i32 noundef %70, i32 noundef %71)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %72

72:                                               ; preds = %69, %12
  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 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}


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

@a = external dso_local local_unnamed_addr global [110 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4minSii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not38 = icmp slt i32 %0, %1
  br i1 %.not38, label %.preheader33, label %tailrecurse._crit_edge

.preheader33:                                     ; preds = %2, %tailrecurse
  %.tr39 = phi i32 [ %43, %tailrecurse ], [ %0, %2 ]
  %3 = sext i32 %.tr39 to i64
  %smax = tail call i32 @llvm.smax.i32(i32 %.tr39, i32 %1)
  %4 = add i32 %smax, 1
  %5 = sub i32 %4, %.tr39
  %6 = sub i32 %smax, %.tr39
  %xtraiter = and i32 %5, 3
  %7 = icmp ult i32 %6, 3
  br i1 %7, label %.preheader.unr-lcssa, label %.preheader33.new

.preheader33.new:                                 ; preds = %.preheader33
  %unroll_iter = and i32 %5, -4
  br label %23

.preheader.unr-lcssa:                             ; preds = %23, %.preheader33
  %spec.select.lcssa.ph = phi i32 [ poison, %.preheader33 ], [ %spec.select.3, %23 ]
  %spec.select31.lcssa.ph = phi i32 [ poison, %.preheader33 ], [ %spec.select31.3, %23 ]
  %indvars.iv.unr = phi i64 [ %3, %.preheader33 ], [ %indvars.iv.next.3, %23 ]
  %.02435.unr = phi i32 [ 1073741823, %.preheader33 ], [ %spec.select31.3, %23 ]
  %.02534.unr = phi i32 [ undef, %.preheader33 ], [ %spec.select.3, %23 ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.epil.preheader

.epil.preheader:                                  ; preds = %.preheader.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %.preheader.unr-lcssa ]
  %.02435.epil = phi i32 [ %spec.select31.epil, %.epil.preheader ], [ %.02435.unr, %.preheader.unr-lcssa ]
  %.02534.epil = phi i32 [ %spec.select.epil, %.epil.preheader ], [ %.02534.unr, %.preheader.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.epil.preheader ], [ 0, %.preheader.unr-lcssa ]
  %8 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %indvars.iv.epil
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = icmp slt i32 %9, %.02435.epil
  %11 = trunc nsw i64 %indvars.iv.epil to i32
  %spec.select.epil = select i1 %10, i32 %11, i32 %.02534.epil
  %spec.select31.epil = tail call i32 @llvm.smin.i32(i32 %9, i32 %.02435.epil)
  %indvars.iv.next.epil = add nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader, label %.epil.preheader, !llvm.loop !9

.preheader:                                       ; preds = %.epil.preheader, %.preheader.unr-lcssa
  %spec.select.lcssa = phi i32 [ %spec.select.lcssa.ph, %.preheader.unr-lcssa ], [ %spec.select.epil, %.epil.preheader ]
  %spec.select31.lcssa = phi i32 [ %spec.select31.lcssa.ph, %.preheader.unr-lcssa ], [ %spec.select31.epil, %.epil.preheader ]
  %12 = icmp sgt i32 %spec.select.lcssa, %.tr39
  br i1 %12, label %.lr.ph.preheader, label %tailrecurse

.lr.ph.preheader:                                 ; preds = %.preheader
  %13 = sext i32 %spec.select.lcssa to i64
  %14 = sub nsw i64 %13, %3
  %min.iters.check = icmp ult i64 %14, 8
  br i1 %min.iters.check, label %.lr.ph.preheader49, label %vector.ph

.lr.ph.preheader49:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv42.ph = phi i64 [ %13, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %14, -8
  %ind.end = sub nsw i64 %13, %n.vec
  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 %13, %index
  %15 = add nsw i64 %offset.idx, -1
  %16 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 -12
  %18 = getelementptr inbounds i8, ptr %16, i64 -28
  %wide.load = load <4 x i32>, ptr %17, align 4, !tbaa !5
  %wide.load45 = load <4 x i32>, ptr %18, align 4, !tbaa !5
  %19 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %offset.idx
  %20 = getelementptr inbounds i8, ptr %19, i64 -12
  %21 = getelementptr inbounds i8, ptr %19, i64 -28
  store <4 x i32> %wide.load, ptr %20, align 4, !tbaa !5
  store <4 x i32> %wide.load45, ptr %21, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %14, %n.vec
  br i1 %cmp.n, label %tailrecurse, label %.lr.ph.preheader49

23:                                               ; preds = %23, %.preheader33.new
  %indvars.iv = phi i64 [ %3, %.preheader33.new ], [ %indvars.iv.next.3, %23 ]
  %.02435 = phi i32 [ 1073741823, %.preheader33.new ], [ %spec.select31.3, %23 ]
  %.02534 = phi i32 [ undef, %.preheader33.new ], [ %spec.select.3, %23 ]
  %niter = phi i32 [ 0, %.preheader33.new ], [ %niter.next.3, %23 ]
  %24 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %indvars.iv
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp slt i32 %25, %.02435
  %27 = trunc nsw i64 %indvars.iv to i32
  %spec.select = select i1 %26, i32 %27, i32 %.02534
  %spec.select31 = tail call i32 @llvm.smin.i32(i32 %25, i32 %.02435)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %28 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %indvars.iv.next
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp slt i32 %29, %spec.select31
  %31 = trunc nsw i64 %indvars.iv.next to i32
  %spec.select.1 = select i1 %30, i32 %31, i32 %spec.select
  %spec.select31.1 = tail call i32 @llvm.smin.i32(i32 %29, i32 %spec.select31)
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %32 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %indvars.iv.next.1
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = icmp slt i32 %33, %spec.select31.1
  %35 = trunc nsw i64 %indvars.iv.next.1 to i32
  %spec.select.2 = select i1 %34, i32 %35, i32 %spec.select.1
  %spec.select31.2 = tail call i32 @llvm.smin.i32(i32 %33, i32 %spec.select31.1)
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, 3
  %36 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %indvars.iv.next.2
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = icmp slt i32 %37, %spec.select31.2
  %39 = trunc nsw i64 %indvars.iv.next.2 to i32
  %spec.select.3 = select i1 %38, i32 %39, i32 %spec.select.2
  %spec.select31.3 = tail call i32 @llvm.smin.i32(i32 %37, i32 %spec.select31.2)
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %niter.next.3 = add i32 %niter, 4
  %niter.ncmp.3 = icmp eq i32 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader.unr-lcssa, label %23, !llvm.loop !15

tailrecurse:                                      ; preds = %.lr.ph, %middle.block, %.preheader
  %40 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %3
  store i32 %spec.select31.lcssa, ptr %40, align 4, !tbaa !5
  %41 = icmp eq i32 %spec.select.lcssa, %.tr39
  %42 = zext i1 %41 to i32
  %43 = add nsw i32 %spec.select.lcssa, %42
  %.not = icmp slt i32 %43, %1
  br i1 %.not, label %.preheader33, label %tailrecurse._crit_edge

.lr.ph:                                           ; preds = %.lr.ph.preheader49, %.lr.ph
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %.lr.ph ], [ %indvars.iv42.ph, %.lr.ph.preheader49 ]
  %indvars.iv.next43 = add nsw i64 %indvars.iv42, -1
  %44 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %indvars.iv.next43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = getelementptr inbounds [110 x i32], ptr @a, i64 0, i64 %indvars.iv42
  store i32 %45, ptr %46, align 4, !tbaa !5
  %47 = icmp sgt i64 %indvars.iv.next43, %3
  br i1 %47, label %.lr.ph, label %tailrecurse, !llvm.loop !16

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  ret void
}

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

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

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" }
attributes #1 = { 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.unroll.disable"}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12, !14, !13}


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