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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4ardb12init_timevalEmNS_8TimeUnitER7timeval(i64 noundef %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(16) %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !5
  %8 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %8, label %39 [
    i32 0, label %9
    i32 1, label %12
    i32 2, label %14
    i32 3, label %17
    i32 4, label %21
    i32 5, label %26
    i32 6, label %32
  ]

9:                                                ; preds = %3
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = udiv i64 %10, 1000
  store i64 %11, ptr %7, align 8, !tbaa !5
  br label %40

12:                                               ; preds = %3
  %13 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %13, ptr %7, align 8, !tbaa !5
  br label %40

14:                                               ; preds = %3
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = mul i64 %15, 1000
  store i64 %16, ptr %7, align 8, !tbaa !5
  br label %40

17:                                               ; preds = %3
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = mul i64 %18, 1000
  %20 = mul i64 %19, 1000
  store i64 %20, ptr %7, align 8, !tbaa !5
  br label %40

21:                                               ; preds = %3
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = mul i64 %22, 1000
  %24 = mul i64 %23, 1000
  %25 = mul i64 %24, 60
  store i64 %25, ptr %7, align 8, !tbaa !5
  br label %40

26:                                               ; preds = %3
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = mul i64 %27, 1000
  %29 = mul i64 %28, 1000
  %30 = mul i64 %29, 60
  %31 = mul i64 %30, 60
  store i64 %31, ptr %7, align 8, !tbaa !5
  br label %40

32:                                               ; preds = %3
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = mul i64 %33, 1000
  %35 = mul i64 %34, 1000
  %36 = mul i64 %35, 60
  %37 = mul i64 %36, 60
  %38 = mul i64 %37, 24
  store i64 %38, ptr %7, align 8, !tbaa !5
  br label %40

39:                                               ; preds = %3
  br label %40

40:                                               ; preds = %39, %32, %26, %21, %17, %14, %12, %9
  %41 = load i64, ptr %7, align 8, !tbaa !5
  %42 = icmp ult i64 %41, 1000000
  br i1 %42, label %43, label %49

43:                                               ; preds = %40
  %44 = load ptr, ptr %6, align 8, !tbaa !11
  %45 = getelementptr inbounds %struct.timeval, ptr %44, i32 0, i32 0
  store i64 0, ptr %45, align 8, !tbaa !13
  %46 = load i64, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !11
  %48 = getelementptr inbounds %struct.timeval, ptr %47, i32 0, i32 1
  store i64 %46, ptr %48, align 8, !tbaa !15
  br label %58

49:                                               ; preds = %40
  %50 = load i64, ptr %7, align 8, !tbaa !5
  %51 = udiv i64 %50, 1000000
  %52 = load ptr, ptr %6, align 8, !tbaa !11
  %53 = getelementptr inbounds %struct.timeval, ptr %52, i32 0, i32 0
  store i64 %51, ptr %53, align 8, !tbaa !13
  %54 = load i64, ptr %7, align 8, !tbaa !5
  %55 = urem i64 %54, 1000000
  %56 = load ptr, ptr %6, align 8, !tbaa !11
  %57 = getelementptr inbounds %struct.timeval, ptr %56, i32 0, i32 1
  store i64 %55, ptr %57, align 8, !tbaa !15
  br label %58

58:                                               ; preds = %49, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

; 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTSN4ardb8TimeUnitE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS7timeval", !6, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 8}


; 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(argmem: write) uwtable
define dso_local void @_ZN4ardb12init_timevalEmNS_8TimeUnitER7timeval(i64 noundef %0, i32 noundef %1, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(16) %2) local_unnamed_addr #0 {
  switch i32 %1, label %.thread [
    i32 0, label %4
    i32 1, label %16
    i32 2, label %6
    i32 3, label %8
    i32 4, label %10
    i32 5, label %12
    i32 6, label %14
  ]

4:                                                ; preds = %3
  %5 = udiv i64 %0, 1000
  br label %16

6:                                                ; preds = %3
  %7 = mul i64 %0, 1000
  br label %16

8:                                                ; preds = %3
  %9 = mul i64 %0, 1000000
  br label %16

10:                                               ; preds = %3
  %11 = mul i64 %0, 60000000
  br label %16

12:                                               ; preds = %3
  %13 = mul i64 %0, 3600000000
  br label %16

14:                                               ; preds = %3
  %15 = mul i64 %0, 86400000000
  br label %16

16:                                               ; preds = %3, %14, %12, %10, %8, %6, %4
  %.0 = phi i64 [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %8 ], [ %7, %6 ], [ %5, %4 ], [ %0, %3 ]
  %17 = icmp ult i64 %.0, 1000000
  br i1 %17, label %.thread, label %18

.thread:                                          ; preds = %3, %16
  %.016 = phi i64 [ %.0, %16 ], [ 0, %3 ]
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %21

18:                                               ; preds = %16
  %19 = udiv i64 %.0, 1000000
  store i64 %19, ptr %2, align 8, !tbaa !5
  %20 = urem i64 %.0, 1000000
  br label %21

21:                                               ; preds = %18, %.thread
  %.sink = phi i64 [ %20, %18 ], [ %.016, %.thread ]
  %22 = getelementptr inbounds i8, ptr %2, i64 8
  store i64 %.sink, ptr %22, align 8, !tbaa !10
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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, !7, i64 0}
!6 = !{!"_ZTS7timeval", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}


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