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

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

8:                                                ; preds = %49, %1
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %8
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = call noundef zeroext i1 @_Z5isVisi(i32 noundef %14)
  br i1 %15, label %16, label %17

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

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

18:                                               ; preds = %17, %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %40, %18
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = icmp slt i32 %20, 12
  br i1 %21, label %23, label %22

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

23:                                               ; preds = %19
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = add nsw i32 %24, 12
  %26 = srem i32 %25, 7
  %27 = icmp eq i32 %26, 4
  br i1 %27, label %28, label %31

28:                                               ; preds = %23
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !5
  br label %31

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

40:                                               ; preds = %31
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %7, align 4, !tbaa !5
  br label %19, !llvm.loop !9

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

49:                                               ; preds = %43
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !13

52:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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 @_Z7calcAddi(i32 noundef %0) local_unnamed_addr #0 {
  %.not19 = icmp slt i32 %0, 1
  br i1 %.not19, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  ret void

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.01321 = phi i32 [ %78, %.lr.ph ], [ 1, %1 ]
  %.01420 = phi i32 [ %74, %.lr.ph ], [ 0, %1 ]
  %2 = tail call noundef zeroext i1 @_Z5isVisi(i32 noundef %.01321)
  %. = select i1 %2, i32 29, i32 28
  store i32 %., ptr getelementptr inbounds (i8, ptr @month, i64 4), align 4, !tbaa !5
  %3 = add nsw i32 %.01420, 12
  %4 = urem i32 %3, 7
  %5 = icmp eq i32 %4, 4
  %6 = zext i1 %5 to i64
  %7 = load i32, ptr @month, align 16, !tbaa !5
  %8 = add nsw i32 %7, %.01420
  %9 = srem i32 %8, 7
  %10 = trunc nsw i32 %9 to i8
  %11 = add nsw i32 %., %9
  %.lhs.trunc23 = trunc nsw i32 %11 to i8
  %12 = urem i8 %.lhs.trunc23, 7
  %.zext24 = zext nneg i8 %12 to i32
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 8), align 8, !tbaa !5
  %14 = add nsw i32 %13, %.zext24
  %15 = srem i32 %14, 7
  %16 = trunc nsw i32 %15 to i8
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 12), align 4, !tbaa !5
  %18 = add nsw i32 %17, %15
  %19 = srem i32 %18, 7
  %20 = trunc nsw i32 %19 to i8
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 16), align 16, !tbaa !5
  %22 = add nsw i32 %21, %19
  %23 = srem i32 %22, 7
  %24 = trunc nsw i32 %23 to i8
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 20), align 4, !tbaa !5
  %26 = add nsw i32 %25, %23
  %27 = srem i32 %26, 7
  %28 = trunc nsw i32 %27 to i8
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 24), align 8, !tbaa !5
  %30 = add nsw i32 %29, %27
  %31 = srem i32 %30, 7
  %32 = trunc nsw i32 %31 to i8
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 28), align 4, !tbaa !5
  %34 = add nsw i32 %33, %31
  %35 = srem i32 %34, 7
  %36 = trunc nsw i32 %35 to i8
  %37 = insertelement <8 x i8> poison, i8 %10, i64 0
  %38 = insertelement <8 x i8> %37, i8 %12, i64 1
  %39 = insertelement <8 x i8> %38, i8 %16, i64 2
  %40 = insertelement <8 x i8> %39, i8 %20, i64 3
  %41 = insertelement <8 x i8> %40, i8 %24, i64 4
  %42 = insertelement <8 x i8> %41, i8 %28, i64 5
  %43 = insertelement <8 x i8> %42, i8 %32, i64 6
  %44 = insertelement <8 x i8> %43, i8 %36, i64 7
  %45 = add nsw <8 x i8> %44, <i8 12, i8 12, i8 12, i8 12, i8 12, i8 12, i8 12, i8 12>
  %46 = urem <8 x i8> %45, <i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7, i8 7>
  %47 = icmp eq <8 x i8> %46, <i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4>
  %48 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 32), align 16, !tbaa !5
  %49 = add nsw i32 %48, %35
  %50 = srem i32 %49, 7
  %51 = trunc nsw i32 %50 to i8
  %.lhs.trunc39 = add nsw i8 %51, 12
  %52 = urem i8 %.lhs.trunc39, 7
  %53 = icmp eq i8 %52, 4
  %54 = zext i1 %53 to i64
  %55 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 36), align 4, !tbaa !5
  %56 = add nsw i32 %55, %50
  %57 = srem i32 %56, 7
  %58 = trunc nsw i32 %57 to i8
  %.lhs.trunc41 = add nsw i8 %58, 12
  %59 = urem i8 %.lhs.trunc41, 7
  %60 = icmp eq i8 %59, 4
  %61 = zext i1 %60 to i64
  %62 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 40), align 8, !tbaa !5
  %63 = add nsw i32 %62, %57
  %64 = srem i32 %63, 7
  %65 = trunc nsw i32 %64 to i8
  %.lhs.trunc43 = add nsw i8 %65, 12
  %66 = urem i8 %.lhs.trunc43, 7
  %67 = icmp eq i8 %66, 4
  %68 = zext i1 %67 to i64
  %69 = bitcast <8 x i1> %47 to i8
  %70 = tail call range(i8 0, 9) i8 @llvm.ctpop.i8(i8 %69)
  %71 = zext nneg i8 %70 to i64
  %op.rdx = add nuw nsw i64 %71, %6
  %op.rdx45 = add nuw nsw i64 %54, %61
  %op.rdx46 = add nuw nsw i64 %op.rdx, %op.rdx45
  %op.rdx47 = add nuw nsw i64 %op.rdx46, %68
  %72 = load i32, ptr getelementptr inbounds (i8, ptr @month, i64 44), align 4, !tbaa !5
  %73 = add nsw i32 %72, %64
  %74 = srem i32 %73, 7
  %75 = getelementptr inbounds [13 x i64], ptr @ans, i64 0, i64 %op.rdx47
  %76 = load i64, ptr %75, align 8, !tbaa !9
  %77 = add nsw i64 %76, 1
  store i64 %77, ptr %75, align 8, !tbaa !9
  %78 = add nuw i32 %.01321, 1
  %exitcond.not = icmp eq i32 %.01321, %0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !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,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass