; LLVM IR from wumo/vkg :: src/vkg/util/fps_meter.ll (ZN3vkg8FPSMeter6updateEd)

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

%"class.vkg::FPSMeter" = type { [128 x double], i64, double, double }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3vkg8FPSMeter6updateEd(ptr noundef nonnull align 8 dereferenceable(1048) %0, double noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = load double, ptr %4, align 8, !tbaa !9
  %7 = getelementptr inbounds %"class.vkg::FPSMeter", ptr %5, i32 0, i32 0
  %8 = getelementptr inbounds %"class.vkg::FPSMeter", ptr %5, i32 0, i32 1
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds [128 x double], ptr %7, i64 0, i64 %9
  %11 = load double, ptr %10, align 8, !tbaa !9
  %12 = fsub double %6, %11
  %13 = getelementptr inbounds %"class.vkg::FPSMeter", ptr %5, i32 0, i32 2
  %14 = load double, ptr %13, align 8, !tbaa !14
  %15 = fadd double %14, %12
  store double %15, ptr %13, align 8, !tbaa !14
  %16 = load double, ptr %4, align 8, !tbaa !9
  %17 = getelementptr inbounds %"class.vkg::FPSMeter", ptr %5, i32 0, i32 0
  %18 = getelementptr inbounds %"class.vkg::FPSMeter", ptr %5, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds [128 x double], ptr %17, i64 0, i64 %19
  store double %16, ptr %20, align 8, !tbaa !9
  %21 = getelementptr inbounds %"class.vkg::FPSMeter", ptr %5, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = add i64 %22, 1
  %24 = urem i64 %23, 128
  %25 = getelementptr inbounds %"class.vkg::FPSMeter", ptr %5, i32 0, i32 1
  store i64 %24, ptr %25, align 8, !tbaa !11
  %26 = getelementptr inbounds %"class.vkg::FPSMeter", ptr %5, i32 0, i32 2
  %27 = load double, ptr %26, align 8, !tbaa !14
  %28 = fcmp ogt double %27, 0.000000e+00
  br i1 %28, label %29, label %34

29:                                               ; preds = %2
  %30 = getelementptr inbounds %"class.vkg::FPSMeter", ptr %5, i32 0, i32 2
  %31 = load double, ptr %30, align 8, !tbaa !14
  %32 = fdiv double %31, 1.280000e+02
  %33 = fdiv double 1.000000e+03, %32
  br label %35

34:                                               ; preds = %2
  br label %35

35:                                               ; preds = %34, %29
  %36 = phi double [ %33, %29 ], [ 0x7FEFFFFFFFFFFFFF, %34 ]
  %37 = getelementptr inbounds %"class.vkg::FPSMeter", ptr %5, i32 0, i32 3
  store double %36, ptr %37, align 8, !tbaa !15
  ret void
}

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

!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 = !{!"double", !7, i64 0}
!11 = !{!12, !13, i64 1024}
!12 = !{!"_ZTSN3vkg8FPSMeterE", !7, i64 0, !13, i64 1024, !10, i64 1032, !10, i64 1040}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !10, i64 1032}
!15 = !{!12, !10, i64 1040}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @_ZN3vkg8FPSMeter6updateEd(ptr nocapture noundef nonnull align 8 dereferenceable(1048) %0, double noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 1024
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds [128 x double], ptr %0, i64 0, i64 %4
  %6 = load double, ptr %5, align 8, !tbaa !11
  %7 = fsub double %1, %6
  %8 = getelementptr inbounds i8, ptr %0, i64 1032
  %9 = load double, ptr %8, align 8, !tbaa !12
  %10 = fadd double %9, %7
  store double %10, ptr %8, align 8, !tbaa !12
  store double %1, ptr %5, align 8, !tbaa !11
  %11 = add i64 %4, 1
  %12 = and i64 %11, 127
  store i64 %12, ptr %3, align 8, !tbaa !5
  %13 = load double, ptr %8, align 8, !tbaa !12
  %14 = fcmp ogt double %13, 0.000000e+00
  %15 = fmul double %13, 7.812500e-03
  %16 = fdiv double 1.000000e+03, %15
  %17 = select i1 %14, double %16, double 0x7FEFFFFFFFFFFFFF
  %18 = getelementptr inbounds i8, ptr %0, i64 1040
  store double %17, ptr %18, align 8, !tbaa !13
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !9, i64 1024}
!6 = !{!"_ZTSN3vkg8FPSMeterE", !7, i64 0, !9, i64 1024, !10, i64 1032, !10, i64 1040}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !10, i64 1032}
!13 = !{!6, !10, i64 1040}


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