; LLVM IR from chensoft/libsocket :: lib/libchen/src/time/date.unix.ll (ZN4chen4dateC2Eb)

; 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 }
%struct.timeval = type { i64, i64 }
%"class.chen::date" = type { i32, i32, i32, i32, i32, i32, i32, i32, i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4chen4dateC2Eb(ptr noundef nonnull align 8 dereferenceable(40) %0, i1 noundef zeroext %1) unnamed_addr #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca %struct.tm, align 8
  %6 = alloca %struct.timeval, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = zext i1 %1 to i8
  store i8 %7, ptr %4, align 1, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 0
  store i32 0, ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 1
  store i32 0, ptr %10, align 4, !tbaa !15
  %11 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 2
  store i32 0, ptr %11, align 8, !tbaa !16
  %12 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 3
  store i32 0, ptr %12, align 4, !tbaa !17
  %13 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 4
  store i32 0, ptr %13, align 8, !tbaa !18
  %14 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 5
  store i32 0, ptr %14, align 4, !tbaa !19
  %15 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 6
  store i32 0, ptr %15, align 8, !tbaa !20
  %16 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 7
  store i32 0, ptr %16, align 4, !tbaa !21
  %17 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 8
  store i64 0, ptr %17, align 8, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 56, ptr %5) #4
  call void @llvm.memset.p0.i64(ptr align 8 %5, i8 0, i64 56, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  call void @llvm.memset.p0.i64(ptr align 8 %6, i8 0, i64 16, i1 false)
  %18 = call i32 @gettimeofday(ptr noundef %6, ptr noundef null) #4
  %19 = load i8, ptr %4, align 1, !tbaa !9, !range !23, !noundef !24
  %20 = trunc i8 %19 to i1
  br i1 %20, label %21, label %24

21:                                               ; preds = %2
  %22 = getelementptr inbounds %struct.timeval, ptr %6, i32 0, i32 0
  %23 = call ptr @gmtime_r(ptr noundef %22, ptr noundef %5) #4
  br label %27

24:                                               ; preds = %2
  %25 = getelementptr inbounds %struct.timeval, ptr %6, i32 0, i32 0
  %26 = call ptr @localtime_r(ptr noundef %25, ptr noundef %5) #4
  br label %27

27:                                               ; preds = %24, %21
  %28 = phi ptr [ %23, %21 ], [ %26, %24 ]
  %29 = getelementptr inbounds %struct.timeval, ptr %6, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !25
  %31 = trunc i64 %30 to i32
  %32 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 0
  store i32 %31, ptr %32, align 8, !tbaa !11
  %33 = getelementptr inbounds %struct.tm, ptr %5, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !27
  %35 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 1
  store i32 %34, ptr %35, align 4, !tbaa !15
  %36 = getelementptr inbounds %struct.tm, ptr %5, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !29
  %38 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 2
  store i32 %37, ptr %38, align 8, !tbaa !16
  %39 = getelementptr inbounds %struct.tm, ptr %5, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !30
  %41 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 3
  store i32 %40, ptr %41, align 4, !tbaa !17
  %42 = getelementptr inbounds %struct.tm, ptr %5, i32 0, i32 3
  %43 = load i32, ptr %42, align 4, !tbaa !31
  %44 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 4
  store i32 %43, ptr %44, align 8, !tbaa !18
  %45 = getelementptr inbounds %struct.tm, ptr %5, i32 0, i32 6
  %46 = load i32, ptr %45, align 8, !tbaa !32
  %47 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 5
  store i32 %46, ptr %47, align 4, !tbaa !19
  %48 = getelementptr inbounds %struct.tm, ptr %5, i32 0, i32 4
  %49 = load i32, ptr %48, align 8, !tbaa !33
  %50 = add nsw i32 %49, 1
  %51 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 6
  store i32 %50, ptr %51, align 8, !tbaa !20
  %52 = getelementptr inbounds %struct.tm, ptr %5, i32 0, i32 5
  %53 = load i32, ptr %52, align 4, !tbaa !34
  %54 = add nsw i32 %53, 1900
  %55 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 7
  store i32 %54, ptr %55, align 4, !tbaa !21
  %56 = getelementptr inbounds %struct.tm, ptr %5, i32 0, i32 9
  %57 = load i64, ptr %56, align 8, !tbaa !35
  %58 = getelementptr inbounds %"class.chen::date", ptr %8, i32 0, i32 8
  store i64 %57, ptr %58, align 8, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr %5) #4
  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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind
declare i32 @gettimeofday(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare ptr @gmtime_r(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind
declare ptr @localtime_r(ptr noundef, ptr noundef) #3

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN4chen4dateE", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !14, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !13, i64 4}
!16 = !{!12, !13, i64 8}
!17 = !{!12, !13, i64 12}
!18 = !{!12, !13, i64 16}
!19 = !{!12, !13, i64 20}
!20 = !{!12, !13, i64 24}
!21 = !{!12, !13, i64 28}
!22 = !{!12, !14, i64 32}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = !{!26, !14, i64 8}
!26 = !{!"_ZTS7timeval", !14, i64 0, !14, i64 8}
!27 = !{!28, !13, i64 0}
!28 = !{!"_ZTS2tm", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !14, i64 40, !6, i64 48}
!29 = !{!28, !13, i64 4}
!30 = !{!28, !13, i64 8}
!31 = !{!28, !13, i64 12}
!32 = !{!28, !13, i64 24}
!33 = !{!28, !13, i64 16}
!34 = !{!28, !13, i64 20}
!35 = !{!28, !14, 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"

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4chen4dateC2Eb(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(40) %0, i1 noundef zeroext %1) unnamed_addr #0 align 2 {
  %3 = alloca %struct.tm, align 16
  %4 = alloca %struct.timeval, align 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %0, i8 0, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %3) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(56) %3, i8 0, i64 56, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, i8 0, i64 16, i1 false)
  %5 = call i32 @gettimeofday(ptr noundef nonnull %4, ptr noundef null) #5
  br i1 %1, label %6, label %8

6:                                                ; preds = %2
  %7 = call ptr @gmtime_r(ptr noundef nonnull %4, ptr noundef nonnull %3) #5
  br label %10

8:                                                ; preds = %2
  %9 = call ptr @localtime_r(ptr noundef nonnull %4, ptr noundef nonnull %3) #5
  br label %10

10:                                               ; preds = %8, %6
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = getelementptr inbounds i8, ptr %0, i64 20
  %14 = getelementptr inbounds i8, ptr %0, i64 4
  %15 = getelementptr inbounds i8, ptr %4, i64 8
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %0, align 8, !tbaa !10
  %18 = load <4 x i32>, ptr %3, align 16, !tbaa !13
  store <4 x i32> %18, ptr %14, align 4, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %3, i64 24
  %20 = load i32, ptr %19, align 8, !tbaa !14
  store i32 %20, ptr %13, align 4, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %3, i64 16
  %22 = load <2 x i32>, ptr %21, align 16, !tbaa !13
  %23 = add nsw <2 x i32> %22, <i32 1, i32 1900>
  store <2 x i32> %23, ptr %12, align 8, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %3, i64 40
  %25 = load i64, ptr %24, align 8, !tbaa !18
  store i64 %25, ptr %11, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %3) #5
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nofree nounwind
declare noundef i32 @gettimeofday(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare ptr @gmtime_r(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind
declare ptr @localtime_r(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nofree nounwind "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 "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 #5 = { 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, !7, i64 8}
!6 = !{!"_ZTS7timeval", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"_ZTSN4chen4dateE", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !7, i64 32}
!12 = !{!"int", !8, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !12, i64 24}
!15 = !{!"_ZTS2tm", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !7, i64 40, !16, i64 48}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!11, !12, i64 20}
!18 = !{!15, !7, i64 40}
!19 = !{!11, !7, i64 32}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass