; LLVM IR from stan-dev/math :: lib/boost_1.84.0/libs/timer/src/cpu_timer.ll (ZNK5boost5timer9cpu_timer7elapsedEv)

; 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.boost::timer::cpu_times" = type { i64, i64, i64 }
%"class.boost::timer::cpu_timer" = type <{ %"struct.boost::timer::cpu_times", i8, [7 x i8] }>

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN12_GLOBAL__N_113get_cpu_timesERN5boost5timer9cpu_timesE(ptr noundef nonnull align 8 dereferenceable(24)) #0

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5boost5timer9cpu_timer10is_stoppedEv(ptr noundef nonnull align 8 dereferenceable(25)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZNK5boost5timer9cpu_timer7elapsedEv(ptr dead_on_unwind noalias writable sret(%"struct.boost::timer::cpu_times") align 8 %0, ptr noundef nonnull align 8 dereferenceable(25) %1) #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8
  %5 = call noundef zeroext i1 @_ZNK5boost5timer9cpu_timer10is_stoppedEv(ptr noundef nonnull align 8 dereferenceable(25) %4) #4
  br i1 %5, label %6, label %8

6:                                                ; preds = %2
  %7 = getelementptr inbounds %"class.boost::timer::cpu_timer", ptr %4, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %7, i64 24, i1 false), !tbaa.struct !9
  br label %28

8:                                                ; preds = %2
  invoke void @_ZN12_GLOBAL__N_113get_cpu_timesERN5boost5timer9cpu_timesE(ptr noundef nonnull align 8 dereferenceable(24) %0)
          to label %9 unwind label %29

9:                                                ; preds = %8
  %10 = getelementptr inbounds %"class.boost::timer::cpu_timer", ptr %4, i32 0, i32 0
  %11 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %10, i32 0, i32 0
  %12 = load i64, ptr %11, align 8, !tbaa !12
  %13 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %0, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !16
  %15 = sub nsw i64 %14, %12
  store i64 %15, ptr %13, align 8, !tbaa !16
  %16 = getelementptr inbounds %"class.boost::timer::cpu_timer", ptr %4, i32 0, i32 0
  %17 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !17
  %19 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %0, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !18
  %21 = sub nsw i64 %20, %18
  store i64 %21, ptr %19, align 8, !tbaa !18
  %22 = getelementptr inbounds %"class.boost::timer::cpu_timer", ptr %4, i32 0, i32 0
  %23 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %22, i32 0, i32 2
  %24 = load i64, ptr %23, align 8, !tbaa !19
  %25 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %0, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !20
  %27 = sub nsw i64 %26, %24
  store i64 %27, ptr %25, align 8, !tbaa !20
  br label %28

28:                                               ; preds = %9, %6
  ret void

29:                                               ; preds = %8
  %30 = landingpad { ptr, i32 }
          catch ptr null
  %31 = extractvalue { ptr, i32 } %30, 0
  call void @__clang_call_terminate(ptr %31) #5
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { mustprogress 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 = { noinline noreturn nounwind uwtable "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 = { 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" }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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++ TBAA"}
!9 = !{i64 0, i64 8, !10, i64 8, i64 8, !10, i64 16, i64 8, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"_ZTSN5boost5timer9cpu_timerE", !14, i64 0, !15, i64 24}
!14 = !{!"_ZTSN5boost5timer9cpu_timesE", !11, i64 0, !11, i64 8, !11, i64 16}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !11, i64 0}
!17 = !{!13, !11, i64 8}
!18 = !{!14, !11, i64 8}
!19 = !{!13, !11, i64 16}
!20 = !{!14, !11, i64 16}


; 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.boost::timer::cpu_times" = type { i64, i64, i64 }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN12_GLOBAL__N_113get_cpu_timesERN5boost5timer9cpu_timesE(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5boost5timer9cpu_timer10is_stoppedEv(ptr noundef nonnull align 8 dereferenceable(25)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZNK5boost5timer9cpu_timer7elapsedEv(ptr dead_on_unwind noalias writable sret(%"struct.boost::timer::cpu_times") align 8 %0, ptr noundef nonnull align 8 dereferenceable(25) %1) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = tail call noundef zeroext i1 @_ZNK5boost5timer9cpu_timer10is_stoppedEv(ptr noundef nonnull align 8 dereferenceable(25) %1) #4
  br i1 %3, label %4, label %5

4:                                                ; preds = %2
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i64 24, i1 false), !tbaa.struct !5
  br label %15

5:                                                ; preds = %2
  invoke void @_ZN12_GLOBAL__N_113get_cpu_timesERN5boost5timer9cpu_timesE(ptr noundef nonnull align 8 dereferenceable(24) %0)
          to label %6 unwind label %16

6:                                                ; preds = %5
  %7 = load <2 x i64>, ptr %1, align 8, !tbaa !6
  %8 = load <2 x i64>, ptr %0, align 8, !tbaa !6
  %9 = sub nsw <2 x i64> %8, %7
  store <2 x i64> %9, ptr %0, align 8, !tbaa !6
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  %11 = load i64, ptr %10, align 8, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load i64, ptr %12, align 8, !tbaa !14
  %14 = sub nsw i64 %13, %11
  store i64 %14, ptr %12, align 8, !tbaa !14
  br label %15

15:                                               ; preds = %6, %4
  ret void

16:                                               ; preds = %5
  %17 = landingpad { ptr, i32 }
          catch ptr null
  %18 = extractvalue { ptr, i32 } %17, 0
  tail call void @__clang_call_terminate(ptr %18) #5
  unreachable
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { mustprogress 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 = { noinline noreturn nounwind uwtable "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 = { 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" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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 = !{i64 0, i64 8, !6, i64 8, i64 8, !6, i64 16, i64 8, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 16}
!11 = !{!"_ZTSN5boost5timer9cpu_timerE", !12, i64 0, !13, i64 24}
!12 = !{!"_ZTSN5boost5timer9cpu_timesE", !7, i64 0, !7, i64 8, !7, i64 16}
!13 = !{!"bool", !8, i64 0}
!14 = !{!12, !7, i64 16}


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