; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/Dhcp6Dxe (SetElapsedTime)

; 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.EFI_TIME = type { i16, i8, i8, i8, i8, i8, i8, i32, i16, i8, i8 }
%struct.EFI_RUNTIME_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }
%struct._DHCP6_INSTANCE = type { i32, ptr, ptr, %struct._LIST_ENTRY, %struct._EFI_DHCP6_PROTOCOL, ptr, ptr, ptr, %struct._DHCP6_IA_CB, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, i8, ptr, i64, i8, i8, i64 }
%struct._EFI_DHCP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._DHCP6_IA_CB = type { ptr, i32, i32, i32, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }

@gRT = external global ptr, align 8

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

declare zeroext i16 @WriteUnaligned16(ptr noundef, i16 noundef zeroext) #1

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @SetElapsedTime(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.EFI_TIME, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load ptr, ptr @gRT, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.EFI_RUNTIME_SERVICES, ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = call i64 %10(ptr noundef %5, ptr noundef null)
  %12 = getelementptr inbounds %struct.EFI_TIME, ptr %5, i32 0, i32 0
  %13 = load i16, ptr %12, align 4, !tbaa !14
  %14 = zext i16 %13 to i32
  %15 = sub nsw i32 %14, 2000
  %16 = mul nsw i32 %15, 360
  %17 = getelementptr inbounds %struct.EFI_TIME, ptr %5, i32 0, i32 1
  %18 = load i8, ptr %17, align 2, !tbaa !17
  %19 = zext i8 %18 to i32
  %20 = sub nsw i32 %19, 1
  %21 = add nsw i32 %16, %20
  %22 = mul nsw i32 %21, 30
  %23 = getelementptr inbounds %struct.EFI_TIME, ptr %5, i32 0, i32 2
  %24 = load i8, ptr %23, align 1, !tbaa !18
  %25 = zext i8 %24 to i32
  %26 = sub nsw i32 %25, 1
  %27 = add nsw i32 %22, %26
  %28 = mul nsw i32 %27, 24
  %29 = getelementptr inbounds %struct.EFI_TIME, ptr %5, i32 0, i32 3
  %30 = load i8, ptr %29, align 4, !tbaa !19
  %31 = zext i8 %30 to i32
  %32 = add nsw i32 %28, %31
  %33 = mul nsw i32 %32, 60
  %34 = getelementptr inbounds %struct.EFI_TIME, ptr %5, i32 0, i32 4
  %35 = load i8, ptr %34, align 1, !tbaa !20
  %36 = zext i8 %35 to i32
  %37 = add nsw i32 %33, %36
  %38 = mul nsw i32 %37, 60
  %39 = getelementptr inbounds %struct.EFI_TIME, ptr %5, i32 0, i32 5
  %40 = load i8, ptr %39, align 2, !tbaa !21
  %41 = zext i8 %40 to i32
  %42 = add nsw i32 %38, %41
  %43 = mul nsw i32 %42, 100
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.EFI_TIME, ptr %5, i32 0, i32 7
  %46 = load i32, ptr %45, align 4, !tbaa !22
  %47 = zext i32 %46 to i64
  %48 = call i64 @DivU64x32(i64 noundef %47, i32 noundef 10000000)
  %49 = add i64 %44, %48
  store i64 %49, ptr %6, align 8, !tbaa !23
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %50, i32 0, i32 17
  %52 = load i64, ptr %51, align 8, !tbaa !24
  %53 = icmp eq i64 %52, 0
  br i1 %53, label %54, label %58

54:                                               ; preds = %2
  store i64 0, ptr %7, align 8, !tbaa !23
  %55 = load i64, ptr %6, align 8, !tbaa !23
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %56, i32 0, i32 17
  store i64 %55, ptr %57, align 8, !tbaa !24
  br label %68

58:                                               ; preds = %2
  %59 = load i64, ptr %6, align 8, !tbaa !23
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %60, i32 0, i32 17
  %62 = load i64, ptr %61, align 8, !tbaa !24
  %63 = sub i64 %59, %62
  store i64 %63, ptr %7, align 8, !tbaa !23
  %64 = load i64, ptr %7, align 8, !tbaa !23
  %65 = icmp ugt i64 %64, 65535
  br i1 %65, label %66, label %67

66:                                               ; preds = %58
  store i64 65535, ptr %7, align 8, !tbaa !23
  br label %67

67:                                               ; preds = %66, %58
  br label %68

68:                                               ; preds = %67, %54
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = load i64, ptr %7, align 8, !tbaa !23
  %71 = trunc i64 %70 to i16
  %72 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %71)
  %73 = call zeroext i16 @WriteUnaligned16(ptr noundef %69, i16 noundef zeroext %72)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  ret void
}

declare i64 @DivU64x32(i64 noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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, !6, i64 24}
!10 = !{!"", !11, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !16, i64 0}
!15 = !{!"", !16, i64 0, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !13, i64 8, !16, i64 12, !7, i64 14, !7, i64 15}
!16 = !{!"short", !7, i64 0}
!17 = !{!15, !7, i64 2}
!18 = !{!15, !7, i64 3}
!19 = !{!15, !7, i64 4}
!20 = !{!15, !7, i64 5}
!21 = !{!15, !7, i64 6}
!22 = !{!15, !13, i64 8}
!23 = !{!12, !12, i64 0}
!24 = !{!25, !12, i64 232}
!25 = !{!"_DHCP6_INSTANCE", !13, i64 0, !6, i64 8, !6, i64 16, !26, i64 24, !27, i64 40, !6, i64 112, !6, i64 120, !6, i64 128, !28, i64 136, !26, i64 160, !26, i64 176, !6, i64 192, !7, i64 200, !6, i64 208, !12, i64 216, !7, i64 224, !7, i64 225, !12, i64 232}
!26 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!27 = !{!"_EFI_DHCP6_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!28 = !{!"_DHCP6_IA_CB", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}


; 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.EFI_TIME = type { i16, i8, i8, i8, i8, i8, i8, i32, i16, i8, i8 }

@gRT = external local_unnamed_addr global ptr, align 8

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

declare zeroext i16 @WriteUnaligned16(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @SetElapsedTime(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.EFI_TIME, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %4 = load ptr, ptr @gRT, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = call i64 %6(ptr noundef nonnull %3, ptr noundef null) #4
  %8 = load i16, ptr %3, align 4, !tbaa !14
  %9 = zext i16 %8 to i64
  %10 = mul nuw nsw i64 %9, 360
  %11 = getelementptr inbounds i8, ptr %3, i64 2
  %12 = load i8, ptr %11, align 2, !tbaa !17
  %13 = zext i8 %12 to i64
  %14 = add nuw nsw i64 %10, %13
  %15 = mul nuw nsw i64 %14, 30
  %16 = getelementptr inbounds i8, ptr %3, i64 3
  %17 = load i8, ptr %16, align 1, !tbaa !18
  %18 = zext i8 %17 to i64
  %19 = add nuw nsw i64 %15, %18
  %20 = mul nuw nsw i64 %19, 24
  %21 = getelementptr inbounds i8, ptr %3, i64 4
  %22 = load i8, ptr %21, align 4, !tbaa !19
  %23 = zext i8 %22 to i64
  %24 = add nuw nsw i64 %23, -518400744
  %25 = add nsw i64 %24, %20
  %26 = mul nsw i64 %25, 60
  %27 = getelementptr inbounds i8, ptr %3, i64 5
  %28 = load i8, ptr %27, align 1, !tbaa !20
  %29 = zext i8 %28 to i64
  %30 = add nsw i64 %26, %29
  %31 = mul nsw i64 %30, 60
  %32 = getelementptr inbounds i8, ptr %3, i64 6
  %33 = load i8, ptr %32, align 2, !tbaa !21
  %34 = zext i8 %33 to i64
  %35 = add nsw i64 %31, %34
  %sext = mul i64 %35, 429496729600
  %36 = ashr exact i64 %sext, 32
  %37 = getelementptr inbounds i8, ptr %3, i64 8
  %38 = load i32, ptr %37, align 4, !tbaa !22
  %39 = zext i32 %38 to i64
  %40 = call i64 @DivU64x32(i64 noundef %39, i32 noundef 10000000) #4
  %41 = add i64 %36, %40
  %42 = getelementptr inbounds i8, ptr %1, i64 232
  %43 = load i64, ptr %42, align 8, !tbaa !23
  %44 = icmp eq i64 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %2
  store i64 %41, ptr %42, align 8, !tbaa !23
  br label %49

46:                                               ; preds = %2
  %47 = sub i64 %41, %43
  %spec.store.select = call i64 @llvm.umin.i64(i64 %47, i64 65535)
  %48 = trunc nuw i64 %spec.store.select to i16
  br label %49

49:                                               ; preds = %46, %45
  %.0 = phi i16 [ 0, %45 ], [ %48, %46 ]
  %50 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %.0) #4
  %51 = call zeroext i16 @WriteUnaligned16(ptr noundef %0, i16 noundef zeroext %50) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret void
}

declare i64 @DivU64x32(i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = !{!10, !6, i64 24}
!10 = !{!"", !11, i64 0, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !16, i64 0}
!15 = !{!"", !16, i64 0, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !7, i64 7, !13, i64 8, !16, i64 12, !7, i64 14, !7, i64 15}
!16 = !{!"short", !7, i64 0}
!17 = !{!15, !7, i64 2}
!18 = !{!15, !7, i64 3}
!19 = !{!15, !7, i64 4}
!20 = !{!15, !7, i64 5}
!21 = !{!15, !7, i64 6}
!22 = !{!15, !13, i64 8}
!23 = !{!24, !12, i64 232}
!24 = !{!"_DHCP6_INSTANCE", !13, i64 0, !6, i64 8, !6, i64 16, !25, i64 24, !26, i64 40, !6, i64 112, !6, i64 120, !6, i64 128, !27, i64 136, !25, i64 160, !25, i64 176, !6, i64 192, !7, i64 200, !6, i64 208, !12, i64 216, !7, i64 224, !7, i64 225, !12, i64 232}
!25 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!26 = !{!"_EFI_DHCP6_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!27 = !{!"_DHCP6_IA_CB", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}


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