; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_time)

; 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.CHNYear.dic = external hidden unnamed_addr constant [11 x i32], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; 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) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @CHNYear(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca [11 x i32], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 3, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 44, ptr %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const.CHNYear.dic, i64 44, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %53, %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %10, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = sext i8 %14 to i32
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %18, label %17

17:                                               ; preds = %9
  store i32 2, ptr %7, align 4
  br label %57

18:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %42, %18
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 11
  br i1 %21, label %22, label %45

22:                                               ; preds = %19
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = getelementptr inbounds [11 x i32], ptr %4, i64 0, i64 0
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr %27, i64 %29
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = call i32 @memcmp(ptr noundef %26, ptr noundef %30, i64 noundef %32) #5
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %41

35:                                               ; preds = %22
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = mul nsw i32 %36, 10
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = srem i32 %38, 10
  %40 = add nsw i32 %37, %39
  store i32 %40, ptr %5, align 4, !tbaa !9
  br label %45

41:                                               ; preds = %22
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %8, align 4, !tbaa !9
  br label %19, !llvm.loop !12

45:                                               ; preds = %35, %19
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = icmp eq i32 %46, 11
  br i1 %47, label %48, label %49

48:                                               ; preds = %45
  store i32 2, ptr %7, align 4
  br label %50

49:                                               ; preds = %45
  store i32 0, ptr %7, align 4
  br label %50

50:                                               ; preds = %49, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %51 = load i32, ptr %7, align 4
  switch i32 %51, label %57 [
    i32 0, label %52
  ]

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %3, align 4, !tbaa !9
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = add nsw i32 %55, %54
  store i32 %56, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !14

57:                                               ; preds = %50, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 44, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %59
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind willreturn memory(read) "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 = { 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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.CHNYear.dic = external hidden unnamed_addr constant [11 x i32], align 16

; Function Attrs: nofree nounwind memory(argmem: read) uwtable
define dso_local i32 @CHNYear(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %.not23 = icmp eq i8 %2, 0
  br i1 %.not23, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %1, %.thread
  %indvars.iv = phi i64 [ %indvars.iv.next, %.thread ], [ 0, %1 ]
  %.01624 = phi i32 [ %26, %.thread ], [ 0, %1 ]
  %3 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %bcmp = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(3) %3, ptr noundef nonnull dereferenceable(3) @__const.CHNYear.dic, i64 3)
  %4 = icmp eq i32 %bcmp, 0
  br i1 %4, label %.thread, label %5

5:                                                ; preds = %.preheader
  %bcmp.1 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(3) %3, ptr noundef nonnull dereferenceable(3) getelementptr inbounds (i8, ptr @__const.CHNYear.dic, i64 4), i64 3)
  %6 = icmp eq i32 %bcmp.1, 0
  br i1 %6, label %.thread, label %7

7:                                                ; preds = %5
  %bcmp.2 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(3) %3, ptr noundef nonnull dereferenceable(3) getelementptr inbounds (i8, ptr @__const.CHNYear.dic, i64 8), i64 3)
  %8 = icmp eq i32 %bcmp.2, 0
  br i1 %8, label %.thread, label %9

9:                                                ; preds = %7
  %bcmp.3 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(3) %3, ptr noundef nonnull dereferenceable(3) getelementptr inbounds (i8, ptr @__const.CHNYear.dic, i64 12), i64 3)
  %10 = icmp eq i32 %bcmp.3, 0
  br i1 %10, label %.thread, label %11

11:                                               ; preds = %9
  %bcmp.4 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(3) %3, ptr noundef nonnull dereferenceable(3) getelementptr inbounds (i8, ptr @__const.CHNYear.dic, i64 16), i64 3)
  %12 = icmp eq i32 %bcmp.4, 0
  br i1 %12, label %.thread, label %13

13:                                               ; preds = %11
  %bcmp.5 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(3) %3, ptr noundef nonnull dereferenceable(3) getelementptr inbounds (i8, ptr @__const.CHNYear.dic, i64 20), i64 3)
  %14 = icmp eq i32 %bcmp.5, 0
  br i1 %14, label %.thread, label %15

15:                                               ; preds = %13
  %bcmp.6 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(3) %3, ptr noundef nonnull dereferenceable(3) getelementptr inbounds (i8, ptr @__const.CHNYear.dic, i64 24), i64 3)
  %16 = icmp eq i32 %bcmp.6, 0
  br i1 %16, label %.thread, label %17

17:                                               ; preds = %15
  %bcmp.7 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(3) %3, ptr noundef nonnull dereferenceable(3) getelementptr inbounds (i8, ptr @__const.CHNYear.dic, i64 28), i64 3)
  %18 = icmp eq i32 %bcmp.7, 0
  br i1 %18, label %.thread, label %19

19:                                               ; preds = %17
  %bcmp.8 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(3) %3, ptr noundef nonnull dereferenceable(3) getelementptr inbounds (i8, ptr @__const.CHNYear.dic, i64 32), i64 3)
  %20 = icmp eq i32 %bcmp.8, 0
  br i1 %20, label %.thread, label %21

21:                                               ; preds = %19
  %bcmp.9 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(3) %3, ptr noundef nonnull dereferenceable(3) getelementptr inbounds (i8, ptr @__const.CHNYear.dic, i64 36), i64 3)
  %22 = icmp eq i32 %bcmp.9, 0
  br i1 %22, label %.thread, label %23

23:                                               ; preds = %21
  %bcmp.10 = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(3) %3, ptr noundef nonnull dereferenceable(3) getelementptr inbounds (i8, ptr @__const.CHNYear.dic, i64 40), i64 3)
  %24 = icmp eq i32 %bcmp.10, 0
  br i1 %24, label %.thread, label %._crit_edge

.thread:                                          ; preds = %.preheader, %5, %7, %9, %11, %13, %15, %17, %19, %21, %23
  %.cmp.not = phi i32 [ 0, %.preheader ], [ 1, %5 ], [ 2, %7 ], [ 3, %9 ], [ 4, %11 ], [ 5, %13 ], [ 6, %15 ], [ 7, %17 ], [ 8, %19 ], [ 9, %21 ], [ 0, %23 ]
  %25 = mul nsw i32 %.01624, 10
  %26 = add nsw i32 %.cmp.not, %25
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 3
  %27 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %.not = icmp eq i8 %28, 0
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !8

._crit_edge:                                      ; preds = %.thread, %23, %1
  %.016.lcssa = phi i32 [ 0, %1 ], [ %.01624, %23 ], [ %26, %.thread ]
  ret i32 %.016.lcssa
}

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #1

attributes #0 = { nofree nounwind memory(argmem: read) 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 = { nofree nounwind willreturn memory(argmem: read) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass