; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/ASC/1/Problem E/E.ll (Z4fastv)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@m = external dso_local global [32 x [32 x i32]], align 16
@ret = external dso_local global [32 x [32 x i32]], align 16
@n = external dso_local global i32, align 4
@exponent = external dso_local global %"class.std::vector", align 8

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3mulPA32_iS0_(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z9divideby2v() #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6vectorIiSaIiEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4fastv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %17, %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %10, label %9

9:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %20

10:                                               ; preds = %5
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [32 x [32 x i32]], ptr @ret, i64 0, i64 %12
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [32 x i32], ptr %13, i64 0, i64 %15
  store i32 1, ptr %16, align 4, !tbaa !5
  br label %17

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

20:                                               ; preds = %9
  br label %21

21:                                               ; preds = %30, %20
  %22 = call noundef zeroext i1 @_ZNKSt6vectorIiSaIiEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24) @exponent) #2
  %23 = xor i1 %22, true
  br i1 %23, label %24, label %31

24:                                               ; preds = %21
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @exponent, i64 noundef 0) #2
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = srem i32 %26, 2
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %24
  call void @_Z3mulPA32_iS0_(ptr noundef @ret, ptr noundef @m)
  br label %30

30:                                               ; preds = %29, %24
  call void @_Z3mulPA32_iS0_(ptr noundef @m, ptr noundef @m)
  call void @_Z9divideby2v()
  br label %21, !llvm.loop !11

31:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %61, %31
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  store i32 7, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %64

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

38:                                               ; preds = %57, %37
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 10, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %60

43:                                               ; preds = %38
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [32 x [32 x i32]], ptr @ret, i64 0, i64 %45
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [32 x i32], ptr %46, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [32 x [32 x i32]], ptr @m, i64 0, i64 %52
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [32 x i32], ptr %53, i64 0, i64 %55
  store i32 %50, ptr %56, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %43
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !5
  br label %38, !llvm.loop !12

60:                                               ; preds = %42
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %2, align 4, !tbaa !5
  br label %32, !llvm.loop !13

64:                                               ; preds = %36
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@m = external dso_local global [32 x [32 x i32]], align 16
@ret = external dso_local global [32 x [32 x i32]], align 16
@n = external dso_local local_unnamed_addr global i32, align 4
@exponent = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3mulPA32_iS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z9divideby2v() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt6vectorIiSaIiEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4fastv() local_unnamed_addr #0 {
  %1 = load i32, ptr @n, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph.preheader, label %.preheader15

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %3 = icmp ult i32 %1, 4
  br i1 %3, label %.preheader15.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  br label %.lr.ph

.preheader15.loopexit.unr-lcssa:                  ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader15, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader15.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.preheader15.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader15.loopexit.unr-lcssa ]
  %4 = getelementptr inbounds [32 x [32 x i32]], ptr @ret, i64 0, i64 %indvars.iv.epil, i64 %indvars.iv.epil
  store i32 1, ptr %4, align 4, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %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 %.preheader15, label %.lr.ph.epil, !llvm.loop !9

.preheader15:                                     ; preds = %.preheader15.loopexit.unr-lcssa, %.lr.ph.epil, %0
  %5 = tail call noundef zeroext i1 @_ZNKSt6vectorIiSaIiEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24) @exponent) #2
  br i1 %5, label %.preheader14, label %.lr.ph17

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %6 = getelementptr inbounds [32 x [32 x i32]], ptr @ret, i64 0, i64 %indvars.iv, i64 %indvars.iv
  store i32 1, ptr %6, align 16, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %7 = getelementptr inbounds [32 x [32 x i32]], ptr @ret, i64 0, i64 %indvars.iv.next, i64 %indvars.iv.next
  store i32 1, ptr %7, align 4, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %8 = getelementptr inbounds [32 x [32 x i32]], ptr @ret, i64 0, i64 %indvars.iv.next.1, i64 %indvars.iv.next.1
  store i32 1, ptr %8, align 8, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %9 = getelementptr inbounds [32 x [32 x i32]], ptr @ret, i64 0, i64 %indvars.iv.next.2, i64 %indvars.iv.next.2
  store i32 1, ptr %9, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader15.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !11

.preheader14:                                     ; preds = %23, %.preheader15
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.preheader.us.preheader, label %._crit_edge21

.preheader.us.preheader:                          ; preds = %.preheader14
  %12 = zext nneg i32 %10 to i64
  %13 = shl nuw nsw i64 %12, 2
  %xtraiter30 = and i64 %12, 3
  %14 = icmp ult i32 %10, 4
  br i1 %14, label %._crit_edge21.loopexit.unr-lcssa, label %.preheader.us.preheader.new

.preheader.us.preheader.new:                      ; preds = %.preheader.us.preheader
  %unroll_iter33 = and i64 %12, 2147483644
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us, %.preheader.us.preheader.new
  %indvar = phi i64 [ 0, %.preheader.us.preheader.new ], [ %indvar.next.3, %.preheader.us ]
  %niter34 = phi i64 [ 0, %.preheader.us.preheader.new ], [ %niter34.next.3, %.preheader.us ]
  %15 = shl nuw nsw i64 %indvar, 7
  %scevgep = getelementptr i8, ptr @m, i64 %15
  %scevgep23 = getelementptr i8, ptr @ret, i64 %15
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep, ptr align 16 %scevgep23, i64 %13, i1 false), !tbaa !5
  %indvar.next = shl i64 %indvar, 7
  %16 = or disjoint i64 %indvar.next, 128
  %scevgep.1 = getelementptr i8, ptr @m, i64 %16
  %scevgep23.1 = getelementptr i8, ptr @ret, i64 %16
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.1, ptr align 16 %scevgep23.1, i64 %13, i1 false), !tbaa !5
  %indvar.next.1 = shl i64 %indvar, 7
  %17 = or disjoint i64 %indvar.next.1, 256
  %scevgep.2 = getelementptr i8, ptr @m, i64 %17
  %scevgep23.2 = getelementptr i8, ptr @ret, i64 %17
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.2, ptr align 16 %scevgep23.2, i64 %13, i1 false), !tbaa !5
  %indvar.next.2 = shl i64 %indvar, 7
  %18 = or disjoint i64 %indvar.next.2, 384
  %scevgep.3 = getelementptr i8, ptr @m, i64 %18
  %scevgep23.3 = getelementptr i8, ptr @ret, i64 %18
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.3, ptr align 16 %scevgep23.3, i64 %13, i1 false), !tbaa !5
  %indvar.next.3 = add nuw nsw i64 %indvar, 4
  %niter34.next.3 = add i64 %niter34, 4
  %niter34.ncmp.3 = icmp eq i64 %niter34.next.3, %unroll_iter33
  br i1 %niter34.ncmp.3, label %._crit_edge21.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !13

.lr.ph17:                                         ; preds = %.preheader15, %23
  %19 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @exponent, i64 noundef 0) #2
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = and i32 %20, 1
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %23, label %22

22:                                               ; preds = %.lr.ph17
  tail call void @_Z3mulPA32_iS0_(ptr noundef nonnull @ret, ptr noundef nonnull @m)
  br label %23

23:                                               ; preds = %22, %.lr.ph17
  tail call void @_Z3mulPA32_iS0_(ptr noundef nonnull @m, ptr noundef nonnull @m)
  tail call void @_Z9divideby2v()
  %24 = tail call noundef zeroext i1 @_ZNKSt6vectorIiSaIiEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(24) @exponent) #2
  br i1 %24, label %.preheader14, label %.lr.ph17, !llvm.loop !14

._crit_edge21.loopexit.unr-lcssa:                 ; preds = %.preheader.us, %.preheader.us.preheader
  %indvar.unr = phi i64 [ 0, %.preheader.us.preheader ], [ %indvar.next.3, %.preheader.us ]
  %lcmp.mod32.not = icmp eq i64 %xtraiter30, 0
  br i1 %lcmp.mod32.not, label %._crit_edge21, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %._crit_edge21.loopexit.unr-lcssa, %.preheader.us.epil
  %indvar.epil = phi i64 [ %indvar.next.epil, %.preheader.us.epil ], [ %indvar.unr, %._crit_edge21.loopexit.unr-lcssa ]
  %epil.iter31 = phi i64 [ %epil.iter31.next, %.preheader.us.epil ], [ 0, %._crit_edge21.loopexit.unr-lcssa ]
  %25 = shl nuw nsw i64 %indvar.epil, 7
  %scevgep.epil = getelementptr i8, ptr @m, i64 %25
  %scevgep23.epil = getelementptr i8, ptr @ret, i64 %25
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 16 %scevgep.epil, ptr align 16 %scevgep23.epil, i64 %13, i1 false), !tbaa !5
  %indvar.next.epil = add nuw nsw i64 %indvar.epil, 1
  %epil.iter31.next = add i64 %epil.iter31, 1
  %epil.iter31.cmp.not = icmp eq i64 %epil.iter31.next, %xtraiter30
  br i1 %epil.iter31.cmp.not, label %._crit_edge21, label %.preheader.us.epil, !llvm.loop !15

._crit_edge21:                                    ; preds = %._crit_edge21.loopexit.unr-lcssa, %.preheader.us.epil, %.preheader14
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 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.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !10}


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