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

; 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] }>

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

declare i32 @__gxx_personality_v0(...)

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5boost5timer9cpu_timer4stopEv(ptr noundef nonnull align 8 dereferenceable(25) %0) #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca %"struct.boost::timer::cpu_times", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, 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 %7

6:                                                ; preds = %1
  br label %34

7:                                                ; preds = %1
  %8 = getelementptr inbounds %"class.boost::timer::cpu_timer", ptr %4, i32 0, i32 1
  store i8 1, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #4
  invoke void @_ZN12_GLOBAL__N_113get_cpu_timesERN5boost5timer9cpu_timesE(ptr noundef nonnull align 8 dereferenceable(24) %3)
          to label %9 unwind label %35

9:                                                ; preds = %7
  %10 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %3, i32 0, i32 0
  %11 = load i64, ptr %10, align 8, !tbaa !14
  %12 = getelementptr inbounds %"class.boost::timer::cpu_timer", ptr %4, i32 0, i32 0
  %13 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !15
  %15 = sub nsw i64 %11, %14
  %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 0
  store i64 %15, ptr %17, align 8, !tbaa !15
  %18 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %3, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !16
  %20 = getelementptr inbounds %"class.boost::timer::cpu_timer", ptr %4, i32 0, i32 0
  %21 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !17
  %23 = sub nsw i64 %19, %22
  %24 = getelementptr inbounds %"class.boost::timer::cpu_timer", ptr %4, i32 0, i32 0
  %25 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %24, i32 0, i32 1
  store i64 %23, ptr %25, align 8, !tbaa !17
  %26 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %3, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !18
  %28 = getelementptr inbounds %"class.boost::timer::cpu_timer", ptr %4, i32 0, i32 0
  %29 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %28, i32 0, i32 2
  %30 = load i64, ptr %29, align 8, !tbaa !19
  %31 = sub nsw i64 %27, %30
  %32 = getelementptr inbounds %"class.boost::timer::cpu_timer", ptr %4, i32 0, i32 0
  %33 = getelementptr inbounds %"struct.boost::timer::cpu_times", ptr %32, i32 0, i32 2
  store i64 %31, ptr %33, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #4
  br label %34

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

35:                                               ; preds = %7
  %36 = landingpad { ptr, i32 }
          catch ptr null
  %37 = extractvalue { ptr, i32 } %36, 0
  call void @__clang_call_terminate(ptr %37) #5
  unreachable
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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 #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 = !{!10, !13, i64 24}
!10 = !{!"_ZTSN5boost5timer9cpu_timerE", !11, i64 0, !13, i64 24}
!11 = !{!"_ZTSN5boost5timer9cpu_timesE", !12, i64 0, !12, i64 8, !12, i64 16}
!12 = !{!"long", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!11, !12, i64 0}
!15 = !{!10, !12, i64 0}
!16 = !{!11, !12, i64 8}
!17 = !{!10, !12, i64 8}
!18 = !{!11, !12, i64 16}
!19 = !{!10, !12, 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 }

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

declare i32 @__gxx_personality_v0(...)

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

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

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

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

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #4
  invoke void @_ZN12_GLOBAL__N_113get_cpu_timesERN5boost5timer9cpu_timesE(ptr noundef nonnull align 8 dereferenceable(24) %2)
          to label %6 unwind label %16

6:                                                ; preds = %4
  %7 = load <2 x i64>, ptr %2, align 16, !tbaa !12
  %8 = load <2 x i64>, ptr %0, align 8, !tbaa !12
  %9 = sub nsw <2 x i64> %7, %8
  store <2 x i64> %9, ptr %0, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %2, i64 16
  %11 = load i64, ptr %10, align 16, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load i64, ptr %12, align 8, !tbaa !14
  %14 = sub nsw i64 %11, %13
  store i64 %14, ptr %12, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #4
  br label %15

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

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

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

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


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