; 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.CHNYearString.dic = external hidden unnamed_addr constant [10 x i32], align 16
@morn_shu = external thread_local global [256 x i8], 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 nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #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: nounwind uwtable
define dso_local ptr @CHNYearString(i32 noundef %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca [10 x i32], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 3, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 40, ptr %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const.CHNYearString.dic, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %8 = call align 16 ptr @llvm.threadlocal.address.p0(ptr align 16 @morn_shu)
  %9 = getelementptr inbounds [256 x i8], ptr %8, i64 0, i64 0
  store ptr %9, ptr %7, align 8, !tbaa !9
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sdiv i32 %10, 1000
  store i32 %11, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %30

14:                                               ; preds = %1
  store i32 1, ptr %6, align 4, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !9
  %16 = getelementptr inbounds [10 x i32], ptr %4, i64 0, i64 0
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i32, ptr %16, i64 %18
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %15, ptr align 4 %19, i64 %21, i1 false)
  %22 = load ptr, ptr %7, align 8, !tbaa !9
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %22, i64 %24
  store ptr %25, ptr %7, align 8, !tbaa !9
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = mul nsw i32 %27, 1000
  %29 = sub nsw i32 %26, %28
  store i32 %29, ptr %2, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %14, %1
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sdiv i32 %31, 100
  store i32 %32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %38, label %35

35:                                               ; preds = %30
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %54

38:                                               ; preds = %35, %30
  store i32 1, ptr %6, align 4, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  %40 = getelementptr inbounds [10 x i32], ptr %4, i64 0, i64 0
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %40, i64 %42
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %39, ptr align 4 %43, i64 %45, i1 false)
  %46 = load ptr, ptr %7, align 8, !tbaa !9
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  store ptr %49, ptr %7, align 8, !tbaa !9
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = mul nsw i32 %51, 100
  %53 = sub nsw i32 %50, %52
  store i32 %53, ptr %2, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %38, %35
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sdiv i32 %55, 10
  store i32 %56, ptr %5, align 4, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = icmp sgt i32 %57, 0
  br i1 %58, label %62, label %59

59:                                               ; preds = %54
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = icmp eq i32 %60, 1
  br i1 %61, label %62, label %78

62:                                               ; preds = %59, %54
  store i32 1, ptr %6, align 4, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !9
  %64 = getelementptr inbounds [10 x i32], ptr %4, i64 0, i64 0
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %64, i64 %66
  %68 = load i32, ptr %3, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %63, ptr align 4 %67, i64 %69, i1 false)
  %70 = load ptr, ptr %7, align 8, !tbaa !9
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i8, ptr %70, i64 %72
  store ptr %73, ptr %7, align 8, !tbaa !9
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = load i32, ptr %5, align 4, !tbaa !5
  %76 = mul nsw i32 %75, 10
  %77 = sub nsw i32 %74, %76
  store i32 %77, ptr %2, align 4, !tbaa !5
  br label %78

78:                                               ; preds = %62, %59
  %79 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %79, ptr %5, align 4, !tbaa !5
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = icmp sgt i32 %80, 0
  br i1 %81, label %85, label %82

82:                                               ; preds = %78
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = icmp eq i32 %83, 1
  br i1 %84, label %85, label %97

85:                                               ; preds = %82, %78
  store i32 1, ptr %6, align 4, !tbaa !5
  %86 = load ptr, ptr %7, align 8, !tbaa !9
  %87 = getelementptr inbounds [10 x i32], ptr %4, i64 0, i64 0
  %88 = load i32, ptr %5, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds i32, ptr %87, i64 %89
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %86, ptr align 4 %90, i64 %92, i1 false)
  %93 = load ptr, ptr %7, align 8, !tbaa !9
  %94 = load i32, ptr %3, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds i8, ptr %93, i64 %95
  store ptr %96, ptr %7, align 8, !tbaa !9
  br label %97

97:                                               ; preds = %85, %82
  %98 = load ptr, ptr %7, align 8, !tbaa !9
  %99 = getelementptr inbounds i8, ptr %98, i64 0
  store i8 0, ptr %99, align 1, !tbaa !11
  %100 = call align 16 ptr @llvm.threadlocal.address.p0(ptr align 16 @morn_shu)
  %101 = getelementptr inbounds [256 x i8], ptr %100, i64 0, i64 0
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret ptr %101
}

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

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}


; 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.CHNYearString.dic = external hidden unnamed_addr constant [10 x i32], align 16
@morn_shu = external thread_local global [256 x i8], align 16

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0

; Function Attrs: mustprogress 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: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local nonnull ptr @CHNYearString(i32 noundef %0) local_unnamed_addr #2 {
  %2 = tail call align 16 ptr @llvm.threadlocal.address.p0(ptr align 16 @morn_shu)
  %3 = icmp sgt i32 %0, 999
  br i1 %3, label %.thread, label %9

.thread:                                          ; preds = %1
  %4 = udiv i32 %0, 1000
  %5 = zext nneg i32 %4 to i64
  %6 = getelementptr inbounds i32, ptr @__const.CHNYearString.dic, i64 %5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(3) %2, ptr noundef nonnull align 4 dereferenceable(3) %6, i64 3, i1 false)
  %7 = getelementptr inbounds i8, ptr %2, i64 3
  %.neg = mul nsw i32 %4, -1000
  %8 = add nsw i32 %.neg, %0
  br label %.thread58

9:                                                ; preds = %1
  %10 = icmp sgt i32 %0, 99
  br i1 %10, label %.thread58, label %16

.thread58:                                        ; preds = %9, %.thread
  %.055 = phi ptr [ %7, %.thread ], [ %2, %9 ]
  %.04554 = phi i32 [ %8, %.thread ], [ %0, %9 ]
  %11 = sdiv i32 %.04554, 100
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i32, ptr @__const.CHNYearString.dic, i64 %12
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) %.055, ptr noundef nonnull align 4 dereferenceable(3) %13, i64 3, i1 false)
  %14 = getelementptr inbounds i8, ptr %.055, i64 3
  %.neg49 = mul nsw i32 %11, -100
  %15 = add i32 %.neg49, %.04554
  br label %.thread67

16:                                               ; preds = %9
  %17 = icmp sgt i32 %0, 9
  br i1 %17, label %.thread67, label %23

.thread67:                                        ; preds = %16, %.thread58
  %.164 = phi ptr [ %14, %.thread58 ], [ %2, %16 ]
  %.14663 = phi i32 [ %15, %.thread58 ], [ %0, %16 ]
  %18 = sdiv i32 %.14663, 10
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i32, ptr @__const.CHNYearString.dic, i64 %19
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) %.164, ptr noundef nonnull align 4 dereferenceable(3) %20, i64 3, i1 false)
  %21 = getelementptr inbounds i8, ptr %.164, i64 3
  %.neg50 = mul nsw i32 %18, -10
  %22 = add i32 %.neg50, %.14663
  br label %25

23:                                               ; preds = %16
  %24 = icmp sgt i32 %0, 0
  br i1 %24, label %25, label %29

25:                                               ; preds = %.thread67, %23
  %.273 = phi ptr [ %21, %.thread67 ], [ %2, %23 ]
  %.24772 = phi i32 [ %22, %.thread67 ], [ %0, %23 ]
  %26 = sext i32 %.24772 to i64
  %27 = getelementptr inbounds i32, ptr @__const.CHNYearString.dic, i64 %26
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) %.273, ptr noundef nonnull align 4 dereferenceable(3) %27, i64 3, i1 false)
  %28 = getelementptr inbounds i8, ptr %.273, i64 3
  br label %29

29:                                               ; preds = %23, %25
  %.3 = phi ptr [ %28, %25 ], [ %2, %23 ]
  store i8 0, ptr %.3, align 1, !tbaa !5
  ret ptr %2
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass