; LLVM IR from yinqiwen/ardb :: src/common/util/time_helper.ll (ZN4ardb14get_current_tmEl)

; 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.tm = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, ptr }

@_ZN4ardbL22k_current_day_start_tsE = external hidden global i32, align 4
@_ZN4ardbL4k_tmE = external hidden global %struct.tm, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZN4ardb14get_current_tmEl(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = call noundef i32 @_ZN4ardbL7init_tmEl(i64 noundef %3)
  %5 = zext i32 %4 to i64
  store i64 %5, ptr %2, align 8, !tbaa !5
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = load i32, ptr @_ZN4ardbL22k_current_day_start_tsE, align 4, !tbaa !9
  %8 = zext i32 %7 to i64
  %9 = sub nsw i64 %6, %8
  %10 = sdiv i64 %9, 3600
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr getelementptr inbounds (%struct.tm, ptr @_ZN4ardbL4k_tmE, i32 0, i32 2), align 8, !tbaa !11
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = load i32, ptr @_ZN4ardbL22k_current_day_start_tsE, align 4, !tbaa !9
  %14 = zext i32 %13 to i64
  %15 = sub nsw i64 %12, %14
  %16 = srem i64 %15, 3600
  %17 = sdiv i64 %16, 60
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr getelementptr inbounds (%struct.tm, ptr @_ZN4ardbL4k_tmE, i32 0, i32 1), align 4, !tbaa !14
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = load i32, ptr @_ZN4ardbL22k_current_day_start_tsE, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = sub nsw i64 %19, %21
  %23 = srem i64 %22, 3600
  %24 = srem i64 %23, 60
  %25 = trunc i64 %24 to i32
  store i32 %25, ptr @_ZN4ardbL4k_tmE, align 8, !tbaa !15
  ret ptr @_ZN4ardbL4k_tmE
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN4ardbL7init_tmEl(i64 noundef) #0

attributes #0 = { mustprogress 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTS2tm", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !13, i64 48}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!12, !10, 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"

%struct.tm = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, ptr }

@_ZN4ardbL22k_current_day_start_tsE = external hidden local_unnamed_addr global i32, align 4
@_ZN4ardbL4k_tmE = external hidden global %struct.tm, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(56) ptr @_ZN4ardb14get_current_tmEl(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef i32 @_ZN4ardbL7init_tmEl(i64 noundef %0)
  %3 = zext i32 %2 to i64
  %4 = load i32, ptr @_ZN4ardbL22k_current_day_start_tsE, align 4, !tbaa !5
  %5 = zext i32 %4 to i64
  %6 = sub nsw i64 %3, %5
  %7 = sdiv i64 %6, 3600
  %8 = trunc nsw i64 %7 to i32
  store i32 %8, ptr getelementptr inbounds (i8, ptr @_ZN4ardbL4k_tmE, i64 8), align 8, !tbaa !9
  %9 = srem i64 %6, 3600
  %.lhs.trunc = trunc nsw i64 %9 to i16
  %10 = sdiv i16 %.lhs.trunc, 60
  %11 = sext i16 %10 to i32
  store i32 %11, ptr getelementptr inbounds (i8, ptr @_ZN4ardbL4k_tmE, i64 4), align 4, !tbaa !13
  %12 = srem i16 %.lhs.trunc, 60
  %13 = sext i16 %12 to i32
  store i32 %13, ptr @_ZN4ardbL4k_tmE, align 8, !tbaa !14
  ret ptr @_ZN4ardbL4k_tmE
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZN4ardbL7init_tmEl(i64 noundef) local_unnamed_addr #0

attributes #0 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS2tm", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !11, i64 40, !12, i64 48}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !6, i64 4}
!14 = !{!10, !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,TailCallElimPass