; LLVM IR from freakout42/macrocalc :: arx/src (mktime)

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

@mktime.months = external hidden global [12 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local i64 @mktime(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.tm, ptr %4, i32 0, i32 5
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = sext i32 %6 to i64
  %8 = mul nsw i64 %7, 365
  store i64 %8, ptr %3, align 8, !tbaa !13
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.tm, ptr %9, i32 0, i32 5
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = sub nsw i32 %11, 1
  %13 = sdiv i32 %12, 4
  %14 = sext i32 %13 to i64
  %15 = load i64, ptr %3, align 8, !tbaa !13
  %16 = add nsw i64 %15, %14
  store i64 %16, ptr %3, align 8, !tbaa !13
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.tm, ptr %17, i32 0, i32 4
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [12 x i32], ptr @mktime.months, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !15
  %23 = sext i32 %22 to i64
  %24 = load i64, ptr %3, align 8, !tbaa !13
  %25 = add nsw i64 %24, %23
  store i64 %25, ptr %3, align 8, !tbaa !13
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.tm, ptr %26, i32 0, i32 5
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = srem i32 %28, 4
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %36

31:                                               ; preds = %1
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tm, ptr %32, i32 0, i32 4
  %34 = load i32, ptr %33, align 8, !tbaa !14
  %35 = icmp sgt i32 %34, 1
  br label %36

36:                                               ; preds = %31, %1
  %37 = phi i1 [ false, %1 ], [ %35, %31 ]
  %38 = zext i1 %37 to i64
  %39 = select i1 %37, i32 1, i32 0
  %40 = sext i32 %39 to i64
  %41 = load i64, ptr %3, align 8, !tbaa !13
  %42 = add nsw i64 %41, %40
  store i64 %42, ptr %3, align 8, !tbaa !13
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.tm, ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 4, !tbaa !16
  %46 = sub nsw i32 %45, 1
  %47 = sext i32 %46 to i64
  %48 = load i64, ptr %3, align 8, !tbaa !13
  %49 = add nsw i64 %48, %47
  store i64 %49, ptr %3, align 8, !tbaa !13
  %50 = load i64, ptr %3, align 8, !tbaa !13
  %51 = mul nsw i64 %50, 86400
  store i64 %51, ptr %3, align 8, !tbaa !13
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.tm, ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 8, !tbaa !17
  %55 = sext i32 %54 to i64
  %56 = mul nsw i64 %55, 3600
  %57 = load i64, ptr %3, align 8, !tbaa !13
  %58 = add nsw i64 %57, %56
  store i64 %58, ptr %3, align 8, !tbaa !13
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.tm, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !18
  %62 = sext i32 %61 to i64
  %63 = mul nsw i64 %62, 60
  %64 = load i64, ptr %3, align 8, !tbaa !13
  %65 = add nsw i64 %64, %63
  store i64 %65, ptr %3, align 8, !tbaa !13
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.tm, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !19
  %69 = sext i32 %68 to i64
  %70 = load i64, ptr %3, align 8, !tbaa !13
  %71 = add nsw i64 %70, %69
  store i64 %71, ptr %3, align 8, !tbaa !13
  %72 = load i64, ptr %3, align 8, !tbaa !13
  %73 = sub nsw i64 %72, 2208988800
  store i64 %73, ptr %3, align 8, !tbaa !13
  %74 = load i64, ptr %3, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i64 %74
}

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

@mktime.months = external hidden local_unnamed_addr global [12 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local range(i64 -68148379291123328, 68148374841346868) i64 @mktime(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 20
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !12
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [12 x i32], ptr @mktime.months, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %9 = and i32 %3, 3
  %10 = icmp eq i32 %9, 0
  %11 = icmp sgt i32 %5, 1
  %narrow = and i1 %10, %11
  %12 = zext i1 %narrow to i64
  %13 = sext i32 %3 to i64
  %14 = mul nsw i64 %13, 365
  %15 = add nsw i32 %3, -1
  %16 = sdiv i32 %15, 4
  %17 = sext i32 %16 to i64
  %18 = add nsw i64 %14, %17
  %19 = sext i32 %8 to i64
  %20 = add nsw i64 %18, %19
  %21 = add nsw i64 %20, %12
  %22 = getelementptr inbounds i8, ptr %0, i64 12
  %23 = load i32, ptr %22, align 4, !tbaa !14
  %24 = add nsw i32 %23, -1
  %25 = sext i32 %24 to i64
  %26 = add nsw i64 %21, %25
  %27 = mul nsw i64 %26, 86400
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  %29 = load i32, ptr %28, align 8, !tbaa !15
  %30 = sext i32 %29 to i64
  %31 = mul nsw i64 %30, 3600
  %32 = getelementptr inbounds i8, ptr %0, i64 4
  %33 = load i32, ptr %32, align 4, !tbaa !16
  %34 = sext i32 %33 to i64
  %35 = mul nsw i64 %34, 60
  %36 = load i32, ptr %0, align 8, !tbaa !17
  %37 = sext i32 %36 to i64
  %38 = add nsw i64 %31, -2208988800
  %39 = add nsw i64 %38, %35
  %40 = add nsw i64 %39, %37
  %41 = add nsw i64 %40, %27
  ret i64 %41
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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, !7, i64 20}
!6 = !{!"tm", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !10, i64 40, !11, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 16}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !7, i64 12}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !7, i64 4}
!17 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass