; LLVM IR from Water-Melon/Melon :: src (mln_tools)

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

%struct.utctime = type { i64, i64, i64, i64, i64, i64, i64 }

@mon_days = external dso_local global [2 x [12 x i64]], 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: inlinehint nounwind uwtable
declare hidden i32 @mln_is_leap(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @mln_utc2time(ptr noundef nonnull %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.utctime, ptr %7, i32 0, i32 0
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = sub nsw i64 %9, 1
  store i64 %10, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.utctime, ptr %11, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = sub nsw i64 %13, 2
  store i64 %14, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.utctime, ptr %15, i32 0, i32 0
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = call i32 @mln_is_leap(i64 noundef %17)
  store i32 %18, ptr %6, align 4, !tbaa !14
  br label %19

19:                                               ; preds = %31, %1
  %20 = load i64, ptr %4, align 8, !tbaa !9
  %21 = icmp sge i64 %20, 1970
  br i1 %21, label %22, label %34

22:                                               ; preds = %19
  %23 = load i64, ptr %4, align 8, !tbaa !9
  %24 = call i32 @mln_is_leap(i64 noundef %23)
  %25 = icmp ne i32 %24, 0
  %26 = zext i1 %25 to i64
  %27 = select i1 %25, i32 366, i32 365
  %28 = sext i32 %27 to i64
  %29 = load i64, ptr %3, align 8, !tbaa !9
  %30 = add nsw i64 %29, %28
  store i64 %30, ptr %3, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %22
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = add nsw i64 %32, -1
  store i64 %33, ptr %4, align 8, !tbaa !9
  br label %19, !llvm.loop !16

34:                                               ; preds = %19
  br label %35

35:                                               ; preds = %47, %34
  %36 = load i64, ptr %5, align 8, !tbaa !9
  %37 = icmp sge i64 %36, 0
  br i1 %37, label %38, label %50

38:                                               ; preds = %35
  %39 = load i32, ptr %6, align 4, !tbaa !14
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2 x [12 x i64]], ptr @mon_days, i64 0, i64 %40
  %42 = load i64, ptr %5, align 8, !tbaa !9
  %43 = getelementptr inbounds [12 x i64], ptr %41, i64 0, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !9
  %45 = load i64, ptr %3, align 8, !tbaa !9
  %46 = add nsw i64 %45, %44
  store i64 %46, ptr %3, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %38
  %48 = load i64, ptr %5, align 8, !tbaa !9
  %49 = add nsw i64 %48, -1
  store i64 %49, ptr %5, align 8, !tbaa !9
  br label %35, !llvm.loop !18

50:                                               ; preds = %35
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.utctime, ptr %51, i32 0, i32 2
  %53 = load i64, ptr %52, align 8, !tbaa !19
  %54 = sub nsw i64 %53, 1
  %55 = load i64, ptr %3, align 8, !tbaa !9
  %56 = add nsw i64 %55, %54
  store i64 %56, ptr %3, align 8, !tbaa !9
  %57 = load i64, ptr %3, align 8, !tbaa !9
  %58 = mul nsw i64 %57, 86400
  store i64 %58, ptr %3, align 8, !tbaa !9
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.utctime, ptr %59, i32 0, i32 3
  %61 = load i64, ptr %60, align 8, !tbaa !20
  %62 = mul nsw i64 %61, 3600
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.utctime, ptr %63, i32 0, i32 4
  %65 = load i64, ptr %64, align 8, !tbaa !21
  %66 = mul nsw i64 %65, 60
  %67 = add nsw i64 %62, %66
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.utctime, ptr %68, i32 0, i32 5
  %70 = load i64, ptr %69, align 8, !tbaa !22
  %71 = add nsw i64 %67, %70
  %72 = load i64, ptr %3, align 8, !tbaa !9
  %73 = add nsw i64 %72, %71
  store i64 %73, ptr %3, align 8, !tbaa !9
  %74 = load i64, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i64 %74
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"utctime", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!13 = !{!12, !10, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = !{!12, !10, i64 16}
!20 = !{!12, !10, i64 24}
!21 = !{!12, !10, i64 32}
!22 = !{!12, !10, i64 40}


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

@mon_days = external dso_local local_unnamed_addr global [2 x [12 x i64]], align 16

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mln_is_leap(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @mln_utc2time(ptr nocapture noundef nonnull readonly %0) local_unnamed_addr #1 {
  %2 = load i64, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !10
  %5 = add nsw i64 %4, -2
  %6 = tail call i32 @mln_is_leap(i64 noundef %2)
  %7 = icmp sgt i64 %2, 1970
  br i1 %7, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %1
  %.0.lcssa = phi i64 [ 0, %1 ], [ %21, %.lr.ph ]
  %8 = icmp sgt i64 %4, 1
  br i1 %8, label %.lr.ph25, label %._crit_edge

.lr.ph25:                                         ; preds = %.preheader
  %9 = sext i32 %6 to i64
  %10 = add nsw i64 %4, -1
  %min.iters.check = icmp ult i64 %4, 5
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph25
  %.124.ph = phi i64 [ %.0.lcssa, %.lr.ph25 ], [ %18, %middle.block ]
  %.01923.ph = phi i64 [ %5, %.lr.ph25 ], [ %ind.end, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph25
  %n.vec = and i64 %10, -4
  %ind.end = sub i64 %5, %n.vec
  %11 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %.0.lcssa, i64 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ %11, %vector.ph ], [ %15, %vector.body ]
  %vec.phi31 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %16, %vector.body ]
  %offset.idx = sub i64 %5, %index
  %12 = getelementptr inbounds [2 x [12 x i64]], ptr @mon_days, i64 0, i64 %9, i64 %offset.idx
  %13 = getelementptr inbounds i8, ptr %12, i64 -8
  %14 = getelementptr inbounds i8, ptr %12, i64 -24
  %wide.load = load <2 x i64>, ptr %13, align 8, !tbaa !11
  %reverse = shufflevector <2 x i64> %wide.load, <2 x i64> poison, <2 x i32> <i32 1, i32 0>
  %wide.load32 = load <2 x i64>, ptr %14, align 8, !tbaa !11
  %reverse33 = shufflevector <2 x i64> %wide.load32, <2 x i64> poison, <2 x i32> <i32 1, i32 0>
  %15 = add <2 x i64> %reverse, %vec.phi
  %16 = add <2 x i64> %reverse33, %vec.phi31
  %index.next = add nuw i64 %index, 4
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, label %middle.block, label %vector.body, !llvm.loop !12

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %16, %15
  %18 = tail call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %10, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.022 = phi i64 [ %21, %.lr.ph ], [ 0, %1 ]
  %.020.in21 = phi i64 [ %.020, %.lr.ph ], [ %2, %1 ]
  %.020 = add nsw i64 %.020.in21, -1
  %19 = tail call i32 @mln_is_leap(i64 noundef %.020)
  %.not = icmp eq i32 %19, 0
  %20 = select i1 %.not, i64 365, i64 366
  %21 = add nuw nsw i64 %20, %.022
  %22 = icmp ugt i64 %.020.in21, 1971
  br i1 %22, label %.lr.ph, label %.preheader, !llvm.loop !16

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.124 = phi i64 [ %25, %scalar.ph ], [ %.124.ph, %scalar.ph.preheader ]
  %.01923 = phi i64 [ %26, %scalar.ph ], [ %.01923.ph, %scalar.ph.preheader ]
  %23 = getelementptr inbounds [2 x [12 x i64]], ptr @mon_days, i64 0, i64 %9, i64 %.01923
  %24 = load i64, ptr %23, align 8, !tbaa !11
  %25 = add nsw i64 %24, %.124
  %26 = add nsw i64 %.01923, -1
  %.not29 = icmp eq i64 %.01923, 0
  br i1 %.not29, label %._crit_edge, label %scalar.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %.preheader
  %.1.lcssa = phi i64 [ %.0.lcssa, %.preheader ], [ %18, %middle.block ], [ %25, %scalar.ph ]
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  %28 = load i64, ptr %27, align 8, !tbaa !18
  %29 = add i64 %.1.lcssa, -1
  %30 = add i64 %29, %28
  %31 = mul nsw i64 %30, 86400
  %32 = getelementptr inbounds i8, ptr %0, i64 24
  %33 = load i64, ptr %32, align 8, !tbaa !19
  %34 = mul nsw i64 %33, 3600
  %35 = getelementptr inbounds i8, ptr %0, i64 32
  %36 = load i64, ptr %35, align 8, !tbaa !20
  %37 = mul nsw i64 %36, 60
  %38 = add nsw i64 %37, %34
  %39 = getelementptr inbounds i8, ptr %0, i64 40
  %40 = load i64, ptr %39, align 8, !tbaa !21
  %41 = add nsw i64 %38, %40
  %42 = add nsw i64 %41, %31
  ret i64 %42
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #2

attributes #0 = { inlinehint 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 = { 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 #2 = { 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, !7, i64 0}
!6 = !{!"utctime", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13, !14, !15}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13, !15, !14}
!18 = !{!6, !7, i64 16}
!19 = !{!6, !7, i64 24}
!20 = !{!6, !7, i64 32}
!21 = !{!6, !7, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass