; LLVM IR from abeaumont/competitive-programming :: uva/00893.ll (Z12offset2monthii)

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

@__const._Z12offset2monthii.days = external hidden unnamed_addr constant [12 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6isleapi(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: 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) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z12offset2monthii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca [12 x i32], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 48, ptr %6) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const._Z12offset2monthii.days, i64 48, i1 false)
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = call noundef i32 @_Z6isleapi(i32 noundef %9)
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %16

12:                                               ; preds = %2
  %13 = getelementptr inbounds [12 x i32], ptr %6, i64 0, i64 1
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %13, align 4, !tbaa !5
  br label %16

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

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

20:                                               ; preds = %17
  store i32 2, ptr %8, align 4
  br label %41

21:                                               ; preds = %17
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [12 x i32], ptr %6, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp slt i32 %22, %26
  br i1 %27, label %28, label %31

28:                                               ; preds = %21
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %41

31:                                               ; preds = %21
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [12 x i32], ptr %6, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sub nsw i32 %36, %35
  store i32 %37, ptr %4, align 4, !tbaa !5
  br label %38

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

41:                                               ; preds = %28, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %42 = load i32, ptr %8, align 4
  switch i32 %42, label %44 [
    i32 2, label %43
  ]

43:                                               ; preds = %41
  store i32 12, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %44

44:                                               ; preds = %43, %41
  call void @llvm.lifetime.end.p0(i64 48, ptr %6) #3
  %45 = load i32, ptr %3, align 4
  ret i32 %45
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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"}


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

@__const._Z12offset2monthii.days = external hidden unnamed_addr constant [12 x i32], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z12offset2monthii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.sroa.0.0.copyload = load i32, ptr @__const._Z12offset2monthii.days, align 16
  %.sroa.4.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z12offset2monthii.days, i64 4), align 4
  %.sroa.7.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z12offset2monthii.days, i64 8), align 8
  %.sroa.8.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z12offset2monthii.days, i64 12), align 4
  %.sroa.9.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z12offset2monthii.days, i64 16), align 16
  %.sroa.10.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z12offset2monthii.days, i64 20), align 4
  %.sroa.11.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z12offset2monthii.days, i64 24), align 8
  %.sroa.12.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z12offset2monthii.days, i64 28), align 4
  %.sroa.13.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z12offset2monthii.days, i64 32), align 16
  %.sroa.14.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z12offset2monthii.days, i64 36), align 4
  %.sroa.15.0.copyload = load i32, ptr getelementptr inbounds (i8, ptr @__const._Z12offset2monthii.days, i64 40), align 8
  %3 = tail call noundef i32 @_Z6isleapi(i32 noundef %1)
  %.not = icmp ne i32 %3, 0
  %4 = zext i1 %.not to i32
  %spec.select20 = add nsw i32 %.sroa.4.0.copyload, %4
  %5 = icmp sgt i32 %.sroa.0.0.copyload, %0
  br i1 %5, label %.loopexit, label %6

6:                                                ; preds = %2
  %7 = sub nsw i32 %0, %.sroa.0.0.copyload
  %8 = icmp slt i32 %7, %spec.select20
  br i1 %8, label %.loopexit, label %9

9:                                                ; preds = %6
  %10 = sub nsw i32 %7, %spec.select20
  %11 = icmp slt i32 %10, %.sroa.7.0.copyload
  br i1 %11, label %.loopexit, label %12

12:                                               ; preds = %9
  %13 = sub nsw i32 %10, %.sroa.7.0.copyload
  %14 = icmp slt i32 %13, %.sroa.8.0.copyload
  br i1 %14, label %.loopexit, label %15

15:                                               ; preds = %12
  %16 = sub nsw i32 %13, %.sroa.8.0.copyload
  %17 = icmp slt i32 %16, %.sroa.9.0.copyload
  br i1 %17, label %.loopexit, label %18

18:                                               ; preds = %15
  %19 = sub nsw i32 %16, %.sroa.9.0.copyload
  %20 = icmp slt i32 %19, %.sroa.10.0.copyload
  br i1 %20, label %.loopexit, label %21

21:                                               ; preds = %18
  %22 = sub nsw i32 %19, %.sroa.10.0.copyload
  %23 = icmp slt i32 %22, %.sroa.11.0.copyload
  br i1 %23, label %.loopexit, label %24

24:                                               ; preds = %21
  %25 = sub nsw i32 %22, %.sroa.11.0.copyload
  %26 = icmp slt i32 %25, %.sroa.12.0.copyload
  br i1 %26, label %.loopexit, label %27

27:                                               ; preds = %24
  %28 = sub nsw i32 %25, %.sroa.12.0.copyload
  %29 = icmp slt i32 %28, %.sroa.13.0.copyload
  br i1 %29, label %.loopexit, label %30

30:                                               ; preds = %27
  %31 = sub nsw i32 %28, %.sroa.13.0.copyload
  %32 = icmp slt i32 %31, %.sroa.14.0.copyload
  br i1 %32, label %.loopexit, label %33

33:                                               ; preds = %30
  %34 = sub nsw i32 %31, %.sroa.14.0.copyload
  %35 = icmp slt i32 %34, %.sroa.15.0.copyload
  %spec.select21 = select i1 %35, i32 11, i32 12
  br label %.loopexit

.loopexit:                                        ; preds = %33, %2, %6, %9, %12, %15, %18, %21, %24, %27, %30
  %spec.select = phi i32 [ 1, %2 ], [ 2, %6 ], [ 3, %9 ], [ 4, %12 ], [ 5, %15 ], [ 6, %18 ], [ 7, %21 ], [ 8, %24 ], [ 9, %27 ], [ 10, %30 ], [ %spec.select21, %33 ]
  ret i32 %spec.select
}

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

!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)"}


; Effective O3 passes: ADCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass