; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (TimestampDriverInitialize)

; 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_TIMESTAMP_PROPERTIES = type { i64, i64 }
%struct._EFI_TIMESTAMP_PROTOCOL = type { ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

@mTimerLibStartValue = external dso_local global i64, align 8
@mTimerLibEndValue = external dso_local global i64, align 8
@mTimestampProperties = external dso_local global %struct.EFI_TIMESTAMP_PROPERTIES, align 8
@mTimestamp = external dso_local global %struct._EFI_TIMESTAMP_PROTOCOL, align 8
@.str = external hidden unnamed_addr constant [70 x i8], align 1
@gBS = external global ptr, align 8
@gEfiTimestampProtocolGuid = external global %struct.GUID, align 4
@.str.1 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [152 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

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

; 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 i64 @TimestampDriverInitialize(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, 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 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  %7 = call i64 @GetPerformanceCounterProperties(ptr noundef @mTimerLibStartValue, ptr noundef @mTimerLibEndValue)
  store i64 %7, ptr @mTimestampProperties, align 8, !tbaa !9
  %8 = load i64, ptr @mTimerLibEndValue, align 8, !tbaa !12
  %9 = load i64, ptr @mTimerLibStartValue, align 8, !tbaa !12
  %10 = icmp ugt i64 %8, %9
  br i1 %10, label %11, label %15

11:                                               ; preds = %2
  %12 = load i64, ptr @mTimerLibEndValue, align 8, !tbaa !12
  %13 = load i64, ptr @mTimerLibStartValue, align 8, !tbaa !12
  %14 = sub i64 %12, %13
  store i64 %14, ptr getelementptr inbounds (%struct.EFI_TIMESTAMP_PROPERTIES, ptr @mTimestampProperties, i32 0, i32 1), align 8, !tbaa !13
  br label %19

15:                                               ; preds = %2
  %16 = load i64, ptr @mTimerLibStartValue, align 8, !tbaa !12
  %17 = load i64, ptr @mTimerLibEndValue, align 8, !tbaa !12
  %18 = sub i64 %16, %17
  store i64 %18, ptr getelementptr inbounds (%struct.EFI_TIMESTAMP_PROPERTIES, ptr @mTimestampProperties, i32 0, i32 1), align 8, !tbaa !13
  br label %19

19:                                               ; preds = %15, %11
  br label %20

20:                                               ; preds = %19
  %21 = call zeroext i8 @DebugPrintEnabled()
  %22 = icmp ne i8 %21, 0
  br i1 %22, label %23, label %34

23:                                               ; preds = %20
  br label %24

24:                                               ; preds = %23
  %25 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64)
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %27, label %31

27:                                               ; preds = %24
  %28 = load i64, ptr @mTimestampProperties, align 8, !tbaa !9
  %29 = load i64, ptr @mTimerLibStartValue, align 8, !tbaa !12
  %30 = load i64, ptr @mTimerLibEndValue, align 8, !tbaa !12
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str, i64 noundef %28, i64 noundef %29, i64 noundef %30)
  br label %31

31:                                               ; preds = %27, %24
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33, %20
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr @gBS, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %37, i32 0, i32 39
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = call i64 (ptr, ...) %39(ptr noundef %6, ptr noundef @gEfiTimestampProtocolGuid, ptr noundef @mTimestamp, ptr noundef null)
  store i64 %40, ptr %5, align 8, !tbaa !12
  br label %41

41:                                               ; preds = %36
  %42 = call zeroext i8 @DebugAssertEnabled()
  %43 = icmp ne i8 %42, 0
  br i1 %43, label %44, label %64

44:                                               ; preds = %41
  %45 = load i64, ptr %5, align 8, !tbaa !12
  %46 = icmp slt i64 %45, 0
  br i1 %46, label %47, label %63

47:                                               ; preds = %44
  br label %48

48:                                               ; preds = %47
  %49 = call zeroext i8 @DebugPrintEnabled()
  %50 = icmp ne i8 %49, 0
  br i1 %50, label %51, label %60

51:                                               ; preds = %48
  br label %52

52:                                               ; preds = %51
  %53 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %54 = icmp ne i8 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %52
  %56 = load i64, ptr %5, align 8, !tbaa !12
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.1, i64 noundef %56)
  br label %57

57:                                               ; preds = %55, %52
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59, %48
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  call void @DebugAssert(ptr noundef @.str.2, i64 noundef 163, ptr noundef @.str.3)
  br label %63

63:                                               ; preds = %62, %44
  br label %64

64:                                               ; preds = %63, %41
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i64 0
}

declare i64 @GetPerformanceCounterProperties(ptr noundef, ptr noundef) #2

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #2

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!15, !6, i64 328}
!15 = !{!"", !16, 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, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!16 = !{!"", !11, i64 0, !17, i64 8, !17, i64 12, !17, i64 16, !17, i64 20}
!17 = !{!"int", !7, 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.EFI_TIMESTAMP_PROPERTIES = type { i64, i64 }
%struct._EFI_TIMESTAMP_PROTOCOL = type { ptr, ptr }
%struct.GUID = type { i32, i16, i16, [8 x i8] }

@mTimerLibStartValue = external dso_local global i64, align 8
@mTimerLibEndValue = external dso_local global i64, align 8
@mTimestampProperties = external dso_local local_unnamed_addr global %struct.EFI_TIMESTAMP_PROPERTIES, align 8
@mTimestamp = external dso_local global %struct._EFI_TIMESTAMP_PROTOCOL, align 8
@.str = external hidden unnamed_addr constant [70 x i8], align 1
@gBS = external local_unnamed_addr global ptr, align 8
@gEfiTimestampProtocolGuid = external global %struct.GUID, align 4
@.str.1 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [152 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

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

; 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 noundef i64 @TimestampDriverInitialize(ptr nocapture noundef readnone %0, ptr nocapture noundef readnone %1) local_unnamed_addr #1 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store ptr null, ptr %3, align 8, !tbaa !5
  %4 = tail call i64 @GetPerformanceCounterProperties(ptr noundef nonnull @mTimerLibStartValue, ptr noundef nonnull @mTimerLibEndValue) #3
  store i64 %4, ptr @mTimestampProperties, align 8, !tbaa !9
  %5 = load i64, ptr @mTimerLibEndValue, align 8, !tbaa !12
  %6 = load i64, ptr @mTimerLibStartValue, align 8, !tbaa !12
  %7 = icmp ugt i64 %5, %6
  %8 = sub i64 %6, %5
  %9 = sub i64 %5, %6
  %storemerge = select i1 %7, i64 %9, i64 %8
  store i64 %storemerge, ptr getelementptr inbounds (i8, ptr @mTimestampProperties, i64 8), align 8, !tbaa !13
  %10 = tail call zeroext i8 @DebugPrintEnabled() #3
  %.not = icmp eq i8 %10, 0
  br i1 %.not, label %17, label %11

11:                                               ; preds = %2
  %12 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #3
  %.not6 = icmp eq i8 %12, 0
  br i1 %.not6, label %17, label %13

13:                                               ; preds = %11
  %14 = load i64, ptr @mTimestampProperties, align 8, !tbaa !9
  %15 = load i64, ptr @mTimerLibStartValue, align 8, !tbaa !12
  %16 = load i64, ptr @mTimerLibEndValue, align 8, !tbaa !12
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str, i64 noundef %14, i64 noundef %15, i64 noundef %16) #3
  br label %17

17:                                               ; preds = %11, %13, %2
  %18 = load ptr, ptr @gBS, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 328
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = call i64 (ptr, ...) %20(ptr noundef nonnull %3, ptr noundef nonnull @gEfiTimestampProtocolGuid, ptr noundef nonnull @mTimestamp, ptr noundef null) #3
  %22 = call zeroext i8 @DebugAssertEnabled() #3
  %23 = icmp ne i8 %22, 0
  %24 = icmp slt i64 %21, 0
  %or.cond = select i1 %23, i1 %24, i1 false
  br i1 %or.cond, label %25, label %31

25:                                               ; preds = %17
  %26 = call zeroext i8 @DebugPrintEnabled() #3
  %.not7 = icmp eq i8 %26, 0
  br i1 %.not7, label %30, label %27

27:                                               ; preds = %25
  %28 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #3
  %.not8 = icmp eq i8 %28, 0
  br i1 %.not8, label %30, label %29

29:                                               ; preds = %27
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.1, i64 noundef %21) #3
  br label %30

30:                                               ; preds = %27, %29, %25
  call void @DebugAssert(ptr noundef nonnull @.str.2, i64 noundef 163, ptr noundef nonnull @.str.3) #3
  br label %31

31:                                               ; preds = %30, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i64 0
}

declare i64 @GetPerformanceCounterProperties(ptr noundef, ptr noundef) local_unnamed_addr #2

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #2

declare void @DebugPrint(i64 noundef, ptr noundef, ...) local_unnamed_addr #2

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 8}
!14 = !{!15, !6, i64 328}
!15 = !{!"", !16, 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, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!16 = !{!"", !11, i64 0, !17, i64 8, !17, i64 12, !17, i64 16, !17, i64 20}
!17 = !{!"int", !7, i64 0}


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