; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/PcAtChipsetPkg/Library (InternalGetPerformanceCounterFrequency)

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

@mPerformanceCounterFrequency = external dso_local global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @InternalGetPerformanceCounterFrequency() #0 {
  %1 = alloca i8, align 1
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %3 = load i64, ptr @mPerformanceCounterFrequency, align 8, !tbaa !5
  %4 = icmp eq i64 %3, 0
  br i1 %4, label %5, label %15

5:                                                ; preds = %0
  %6 = call zeroext i8 @SaveAndDisableInterrupts()
  store i8 %6, ptr %1, align 1, !tbaa !9
  %7 = call i64 @GetPerformanceCounter()
  store i64 %7, ptr %2, align 8, !tbaa !5
  %8 = call i64 @MicroSecondDelay(i64 noundef 100)
  %9 = call i64 @GetPerformanceCounter()
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = sub i64 %9, %10
  %12 = call i64 @MultU64x32(i64 noundef %11, i32 noundef 10000)
  store i64 %12, ptr @mPerformanceCounterFrequency, align 8, !tbaa !5
  %13 = load i8, ptr %1, align 1, !tbaa !9
  %14 = call zeroext i8 @SetInterruptState(i8 noundef zeroext %13)
  br label %15

15:                                               ; preds = %5, %0
  %16 = load i64, ptr @mPerformanceCounterFrequency, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #3
  ret i64 %16
}

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

declare zeroext i8 @SaveAndDisableInterrupts() #2

declare i64 @GetPerformanceCounter() #2

declare i64 @MicroSecondDelay(i64 noundef) #2

declare i64 @MultU64x32(i64 noundef, i32 noundef) #2

declare zeroext i8 @SetInterruptState(i8 noundef zeroext) #2

; 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 = { "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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !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"

@mPerformanceCounterFrequency = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @InternalGetPerformanceCounterFrequency() local_unnamed_addr #0 {
  %1 = load i64, ptr @mPerformanceCounterFrequency, align 8, !tbaa !5
  %2 = icmp eq i64 %1, 0
  br i1 %2, label %3, label %11

3:                                                ; preds = %0
  %4 = tail call zeroext i8 @SaveAndDisableInterrupts() #2
  %5 = tail call i64 @GetPerformanceCounter() #2
  %6 = tail call i64 @MicroSecondDelay(i64 noundef 100) #2
  %7 = tail call i64 @GetPerformanceCounter() #2
  %8 = sub i64 %7, %5
  %9 = tail call i64 @MultU64x32(i64 noundef %8, i32 noundef 10000) #2
  store i64 %9, ptr @mPerformanceCounterFrequency, align 8, !tbaa !5
  %10 = tail call zeroext i8 @SetInterruptState(i8 noundef zeroext %4) #2
  %.pre = load i64, ptr @mPerformanceCounterFrequency, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %3, %0
  %12 = phi i64 [ %.pre, %3 ], [ %1, %0 ]
  ret i64 %12
}

declare zeroext i8 @SaveAndDisableInterrupts() local_unnamed_addr #1

declare i64 @GetPerformanceCounter() local_unnamed_addr #1

declare i64 @MicroSecondDelay(i64 noundef) local_unnamed_addr #1

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

declare zeroext i8 @SetInterruptState(i8 noundef zeroext) local_unnamed_addr #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 = { "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 }

!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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,TailCallElimPass