; LLVM IR from chirag-singhal/Coding-Interview-101 :: Miscellaneous/Codechef/feblong/5.ll (Z7findDayiii)

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z7findDayiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %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
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %14, label %17

14:                                               ; preds = %3
  store i32 13, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr %6, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %14, %3
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 2
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  store i32 14, ptr %5, align 4, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr %6, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %20, %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %24 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %24, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %25 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %25, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = srem i32 %26, 100
  store i32 %27, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sdiv i32 %28, 100
  store i32 %29, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  %33 = mul nsw i32 13, %32
  %34 = sdiv i32 %33, 5
  %35 = add nsw i32 %30, %34
  %36 = load i32, ptr %9, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  %38 = load i32, ptr %9, align 4, !tbaa !5
  %39 = sdiv i32 %38, 4
  %40 = add nsw i32 %37, %39
  %41 = load i32, ptr %10, align 4, !tbaa !5
  %42 = sdiv i32 %41, 4
  %43 = add nsw i32 %40, %42
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = mul nsw i32 5, %44
  %46 = add nsw i32 %43, %45
  store i32 %46, ptr %11, align 4, !tbaa !5
  %47 = load i32, ptr %11, align 4, !tbaa !5
  %48 = srem i32 %47, 7
  store i32 %48, ptr %11, align 4, !tbaa !5
  %49 = load i32, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %49
}

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


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef range(i32 -6, 7) i32 @_Z7findDayiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %1, 1
  %5 = sext i1 %4 to i32
  %spec.select = add nsw i32 %5, %2
  %spec.select19 = select i1 %4, i32 13, i32 %1
  %6 = icmp eq i32 %spec.select19, 2
  %7 = sext i1 %6 to i32
  %.117 = add nsw i32 %spec.select, %7
  %8 = mul i32 %spec.select19, 13
  %9 = srem i32 %.117, 100
  %10 = sdiv i32 %.117, 100
  %11 = add i32 %8, 13
  %12 = sdiv i32 %11, 5
  %13 = select i1 %6, i32 39, i32 %12
  %14 = add nsw i32 %13, %0
  %15 = add nsw i32 %14, %9
  %.lhs.trunc = trunc nsw i32 %9 to i8
  %16 = sdiv i8 %.lhs.trunc, 4
  %.sext = sext i8 %16 to i32
  %17 = sdiv i32 %.117, 400
  %18 = mul nsw i32 %10, 5
  %19 = add i32 %15, %17
  %20 = add i32 %19, %18
  %21 = add i32 %20, %.sext
  %22 = srem i32 %21, 7
  ret i32 %22
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass