; LLVM IR from Tudor67/Competitive-Programming :: ProjectEuler (#19_CountingSundays)

; 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 }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZL13days_of_month = external hidden global %"class.std::vector", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z12is_leap_yearRKi(ptr noundef nonnull align 4 dereferenceable(4)) #0

; 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

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

9:                                                ; preds = %69, %0
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp sle i32 %10, 2000
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %72

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

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

17:                                               ; preds = %14
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %68

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @_ZL13days_of_month, i64 noundef %20) #4
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = icmp eq i32 %23, 2
  br i1 %24, label %25, label %27

25:                                               ; preds = %18
  %26 = call noundef zeroext i1 @_Z12is_leap_yearRKi(ptr noundef nonnull align 4 dereferenceable(4) %4)
  br label %27

27:                                               ; preds = %25, %18
  %28 = phi i1 [ false, %18 ], [ %26, %25 ]
  %29 = zext i1 %28 to i32
  %30 = add nsw i32 %22, %29
  store i32 %30, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %61, %27
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = icmp sle i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %64

36:                                               ; preds = %31
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %3, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = icmp eq i32 %39, 7
  br i1 %40, label %41, label %55

41:                                               ; preds = %36
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 1
  br i1 %43, label %44, label %50

44:                                               ; preds = %41
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = icmp sle i32 1901, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %44
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = icmp sle i32 %48, 2000
  br label %50

50:                                               ; preds = %47, %44, %41
  %51 = phi i1 [ false, %44 ], [ false, %41 ], [ %49, %47 ]
  %52 = zext i1 %51 to i32
  %53 = load i32, ptr %2, align 4, !tbaa !5
  %54 = add nsw i32 %53, %52
  store i32 %54, ptr %2, align 4, !tbaa !5
  br label %60

55:                                               ; preds = %36
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = icmp sgt i32 %56, 7
  br i1 %57, label %58, label %59

58:                                               ; preds = %55
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %58, %55
  br label %60

60:                                               ; preds = %59, %50
  br label %61

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

64:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %6, align 4, !tbaa !5
  br label %14, !llvm.loop !11

68:                                               ; preds = %17
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %4, align 4, !tbaa !5
  br label %9, !llvm.loop !12

72:                                               ; preds = %12
  %73 = load i32, ptr %2, align 4, !tbaa !5
  %74 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %73)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %75 = load i32, ptr %1, align 4
  ret i32 %75
}

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

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { 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"

%"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 }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZL13days_of_month = external hidden global %"class.std::vector", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z12is_leap_yearRKi(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; 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: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  store i32 1900, ptr %1, align 4, !tbaa !5
  br label %.preheader

2:                                                ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %3 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %.219.lcssa)
  ret i32 0

4:                                                ; preds = %._crit_edge
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr %1, align 4, !tbaa !5
  %7 = icmp slt i32 %5, 2000
  br i1 %7, label %.preheader.backedge, label %2

.preheader:                                       ; preds = %.preheader.backedge, %0
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.be, %.preheader.backedge ]
  %.130 = phi i32 [ 0, %0 ], [ %.2.lcssa, %.preheader.backedge ]
  %.11829 = phi i32 [ 0, %0 ], [ %.219.lcssa, %.preheader.backedge ]
  %8 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @_ZL13days_of_month, i64 noundef %indvars.iv) #4
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = icmp eq i64 %indvars.iv, 2
  br i1 %10, label %11, label %13

11:                                               ; preds = %.preheader
  %12 = call noundef zeroext i1 @_Z12is_leap_yearRKi(ptr noundef nonnull align 4 dereferenceable(4) %1)
  br label %13

13:                                               ; preds = %11, %.preheader
  %14 = phi i1 [ false, %.preheader ], [ %12, %11 ]
  %15 = zext i1 %14 to i32
  %16 = add nsw i32 %9, %15
  %.not24 = icmp slt i32 %16, 1
  br i1 %.not24, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13
  %17 = add i32 %9, 1
  %18 = add i32 %17, %15
  %19 = add nsw i32 %.130, 1
  %20 = icmp eq i32 %19, 7
  br i1 %20, label %23, label %21

21:                                               ; preds = %.lr.ph
  %22 = icmp sgt i32 %.130, 6
  %spec.store.select.peel = select i1 %22, i32 1, i32 %19
  br label %29

23:                                               ; preds = %.lr.ph
  %24 = load i32, ptr %1, align 4
  %25 = add i32 %24, -1901
  %26 = icmp ult i32 %25, 100
  %27 = zext i1 %26 to i32
  %28 = add nsw i32 %.11829, %27
  br label %29

29:                                               ; preds = %23, %21
  %.320.peel = phi i32 [ %28, %23 ], [ %.11829, %21 ]
  %.3.peel = phi i32 [ 7, %23 ], [ %spec.store.select.peel, %21 ]
  %exitcond.peel.not = icmp eq i32 %18, 2
  br i1 %exitcond.peel.not, label %._crit_edge, label %.peel.next.preheader

.peel.next.preheader:                             ; preds = %29
  %30 = add i32 %9, -1
  %31 = add i32 %30, %15
  %32 = add i32 %9, -2
  %33 = add i32 %32, %15
  %xtraiter = and i32 %31, 3
  %34 = icmp ult i32 %33, 3
  br i1 %34, label %._crit_edge.loopexit.unr-lcssa, label %.peel.next.preheader.new

.peel.next.preheader.new:                         ; preds = %.peel.next.preheader
  %unroll_iter = and i32 %31, -4
  br label %.peel.next

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.peel.next, %.peel.next.preheader
  %.3.lcssa.ph = phi i32 [ poison, %.peel.next.preheader ], [ %.3.3, %.peel.next ]
  %.226.unr = phi i32 [ %.3.peel, %.peel.next.preheader ], [ %.3.3, %.peel.next ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.peel.next.epil

.peel.next.epil:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.peel.next.epil
  %.226.epil = phi i32 [ %.3.epil, %.peel.next.epil ], [ %.226.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.peel.next.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %35 = add nsw i32 %.226.epil, 1
  %36 = icmp eq i32 %35, 7
  %37 = icmp sgt i32 %.226.epil, 6
  %spec.store.select.epil = select i1 %37, i32 1, i32 %35
  %.3.epil = select i1 %36, i32 7, i32 %spec.store.select.epil
  %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 %._crit_edge, label %.peel.next.epil, !llvm.loop !9

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.peel.next.epil, %29, %13
  %.219.lcssa = phi i32 [ %.11829, %13 ], [ %.320.peel, %29 ], [ %.320.peel, %.peel.next.epil ], [ %.320.peel, %._crit_edge.loopexit.unr-lcssa ]
  %.2.lcssa = phi i32 [ %.130, %13 ], [ %.3.peel, %29 ], [ %.3.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.3.epil, %.peel.next.epil ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond36.not = icmp eq i64 %indvars.iv.next, 13
  br i1 %exitcond36.not, label %4, label %.preheader.backedge

.preheader.backedge:                              ; preds = %._crit_edge, %4
  %indvars.iv.be = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 1, %4 ]
  br label %.preheader, !llvm.loop !11

.peel.next:                                       ; preds = %.peel.next, %.peel.next.preheader.new
  %.226 = phi i32 [ %.3.peel, %.peel.next.preheader.new ], [ %.3.3, %.peel.next ]
  %niter = phi i32 [ 0, %.peel.next.preheader.new ], [ %niter.next.3, %.peel.next ]
  %38 = add nsw i32 %.226, 1
  %39 = icmp eq i32 %38, 7
  %40 = icmp sgt i32 %.226, 6
  %spec.store.select = select i1 %40, i32 1, i32 %38
  %.3 = select i1 %39, i32 7, i32 %spec.store.select
  %41 = add nsw i32 %.3, 1
  %42 = icmp eq i32 %41, 7
  %43 = icmp sgt i32 %.3, 6
  %spec.store.select.1 = select i1 %43, i32 1, i32 %41
  %.3.1 = select i1 %42, i32 7, i32 %spec.store.select.1
  %44 = add nsw i32 %.3.1, 1
  %45 = icmp eq i32 %44, 7
  %46 = icmp sgt i32 %.3.1, 6
  %spec.store.select.2 = select i1 %46, i32 1, i32 %44
  %.3.2 = select i1 %45, i32 7, i32 %spec.store.select.2
  %47 = add nsw i32 %.3.2, 1
  %48 = icmp eq i32 %47, 7
  %49 = icmp sgt i32 %.3.2, 6
  %spec.store.select.3 = select i1 %49, i32 1, i32 %47
  %.3.3 = select i1 %48, i32 7, i32 %spec.store.select.3
  %niter.next.3 = add i32 %niter, 4
  %niter.ncmp.3 = icmp eq i32 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.peel.next, !llvm.loop !13
}

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

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #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 = { 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 #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 = { 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}
!14 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass