; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 11/2048. History.ll (Z7calcAllv)

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

@month = external dso_local global [12 x i32], align 16
@ans = external dso_local global [13 x i64], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7calcAllv() #0 {
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %46, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp sle i32 %7, 400
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = call noundef zeroext i1 @_Z5isVisi(i32 noundef %11)
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  store i32 29, ptr getelementptr inbounds ([12 x i32], ptr @month, i64 0, i64 1), align 4, !tbaa !5
  br label %15

14:                                               ; preds = %10
  store i32 28, ptr getelementptr inbounds ([12 x i32], ptr @month, i64 0, i64 1), align 4, !tbaa !5
  br label %15

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

16:                                               ; preds = %37, %15
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 12
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %40

20:                                               ; preds = %16
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = add nsw i32 %21, 12
  %23 = srem i32 %22, 7
  %24 = icmp eq i32 %23, 4
  br i1 %24, label %25, label %28

25:                                               ; preds = %20
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %4, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %25, %20
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [12 x i32], ptr @month, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = add nsw i32 %33, %32
  store i32 %34, ptr %1, align 4, !tbaa !5
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = srem i32 %35, 7
  store i32 %36, ptr %1, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %28
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !5
  br label %16, !llvm.loop !9

40:                                               ; preds = %19
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [13 x i64], ptr @ans, i64 0, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !11
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %43, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %46

46:                                               ; preds = %40
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !13

49:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  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 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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!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"

@month = external dso_local local_unnamed_addr global [12 x i32], align 16
@ans = external dso_local local_unnamed_addr global [13 x i64], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7calcAllv() local_unnamed_addr #0 {
  br label %2

1:                                                ; preds = %2
  ret void

2:                                                ; preds = %0, %2
  %.01219 = phi i32 [ 1, %0 ], [ %79, %2 ]
  %.01318 = phi i32 [ 0, %0 ], [ %75, %2 ]
  %3 = tail call noundef zeroext i1 @_Z5isVisi(i32 noundef %.01219)
  %. = select i1 %3, i32 29, i32 28
  store i32 %., ptr getelementptr inbounds (i8, ptr @month, i64 4), align 4, !tbaa !5
  %4 = add nsw i32 %.01318, 12
  %5 = urem i32 %4, 7
  %6 = icmp eq i32 %5, 4
  %7 = zext i1 %6 to i64
  %8 = load i32, ptr @month, align 16, !tbaa !5
  %9 = add nsw i32 %8, %.01318
  %10 = srem i32 %9, 7
  %11 = trunc nsw i32 %10 to i8
  %12 = add nsw i32 %., %10
  %.lhs.trunc21 = trunc nsw i32 %12 to i8
  %13 = urem i8 %.lhs.trunc21, 7
  %.zext22 = zext nneg i8 %13 to i32
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 8), align 8, !tbaa !5
  %15 = add nsw i32 %14, %.zext22
  %16 = srem i32 %15, 7
  %17 = trunc nsw i32 %16 to i8
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 12), align 4, !tbaa !5
  %19 = add nsw i32 %18, %16
  %20 = srem i32 %19, 7
  %21 = trunc nsw i32 %20 to i8
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 16), align 16, !tbaa !5
  %23 = add nsw i32 %22, %20
  %24 = srem i32 %23, 7
  %25 = trunc nsw i32 %24 to i8
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 20), align 4, !tbaa !5
  %27 = add nsw i32 %26, %24
  %28 = srem i32 %27, 7
  %29 = trunc nsw i32 %28 to i8
  %30 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 24), align 8, !tbaa !5
  %31 = add nsw i32 %30, %28
  %32 = srem i32 %31, 7
  %33 = trunc nsw i32 %32 to i8
  %34 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 28), align 4, !tbaa !5
  %35 = add nsw i32 %34, %32
  %36 = srem i32 %35, 7
  %37 = trunc nsw i32 %36 to i8
  %38 = insertelement <8 x i8> poison, i8 %11, i64 0
  %39 = insertelement <8 x i8> %38, i8 %13, i64 1
  %40 = insertelement <8 x i8> %39, i8 %17, i64 2
  %41 = insertelement <8 x i8> %40, i8 %21, i64 3
  %42 = insertelement <8 x i8> %41, i8 %25, i64 4
  %43 = insertelement <8 x i8> %42, i8 %29, i64 5
  %44 = insertelement <8 x i8> %43, i8 %33, i64 6
  %45 = insertelement <8 x i8> %44, i8 %37, i64 7
  %46 = add nsw <8 x i8> %45, <i8 12, i8 12, i8 12, i8 12, i8 12, i8 12, i8 12, i8 12>
  %47 = urem <8 x i8> %46, <i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7>
  %48 = icmp eq <8 x i8> %47, <i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4>
  %49 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 32), align 16, !tbaa !5
  %50 = add nsw i32 %49, %36
  %51 = srem i32 %50, 7
  %52 = trunc nsw i32 %51 to i8
  %.lhs.trunc37 = add nsw i8 %52, 12
  %53 = urem i8 %.lhs.trunc37, 7
  %54 = icmp eq i8 %53, 4
  %55 = zext i1 %54 to i64
  %56 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 36), align 4, !tbaa !5
  %57 = add nsw i32 %56, %51
  %58 = srem i32 %57, 7
  %59 = trunc nsw i32 %58 to i8
  %.lhs.trunc39 = add nsw i8 %59, 12
  %60 = urem i8 %.lhs.trunc39, 7
  %61 = icmp eq i8 %60, 4
  %62 = zext i1 %61 to i64
  %63 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 40), align 8, !tbaa !5
  %64 = add nsw i32 %63, %58
  %65 = srem i32 %64, 7
  %66 = trunc nsw i32 %65 to i8
  %.lhs.trunc41 = add nsw i8 %66, 12
  %67 = urem i8 %.lhs.trunc41, 7
  %68 = icmp eq i8 %67, 4
  %69 = zext i1 %68 to i64
  %70 = bitcast <8 x i1> %48 to i8
  %71 = tail call range(i8 0, 9) i8 @llvm.ctpop.i8(i8 %70)
  %72 = zext nneg i8 %71 to i64
  %op.rdx = add nuw nsw i64 %72, %7
  %op.rdx43 = add nuw nsw i64 %55, %62
  %op.rdx44 = add nuw nsw i64 %op.rdx, %op.rdx43
  %op.rdx45 = add nuw nsw i64 %op.rdx44, %69
  %73 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 44), align 4, !tbaa !5
  %74 = add nsw i32 %73, %65
  %75 = srem i32 %74, 7
  %76 = getelementptr inbounds [13 x i64], ptr @ans, i64 0, i64 %op.rdx45
  %77 = load i64, ptr %76, align 8, !tbaa !9
  %78 = add nsw i64 %77, 1
  store i64 %78, ptr %76, align 8, !tbaa !9
  %79 = add nuw nsw i32 %.01219, 1
  %exitcond.not = icmp eq i32 %79, 401
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !11
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i8 @llvm.ctpop.i8(i8) #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 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,ReassociatePass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass