; LLVM IR from turi-code/SFrame :: oss_src/timer/timer.ll (ZN8graphlab25estimate_ticks_per_secondEv)

; 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.graphlab::mutex" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@_ZN8graphlabL25rtdsc_ticks_per_sec_mutexE = external hidden global %"class.graphlab::mutex", align 8
@_ZN8graphlabL19rtdsc_ticks_per_secE = external hidden global i64, align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8graphlab5timer5sleepEm(i64 noundef) #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN8graphlab25estimate_ticks_per_secondEv() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = load i64, ptr @_ZN8graphlabL19rtdsc_ticks_per_secE, align 8, !tbaa !5
  %4 = icmp eq i64 %3, 0
  br i1 %4, label %5, label %15

5:                                                ; preds = %0
  call void @_ZNK8graphlab5mutex4lockEv(ptr noundef nonnull align 8 dereferenceable(40) @_ZN8graphlabL25rtdsc_ticks_per_sec_mutexE)
  %6 = load i64, ptr @_ZN8graphlabL19rtdsc_ticks_per_secE, align 8, !tbaa !5
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %8, label %14

8:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %9 = call noundef i64 @_ZN8graphlab5rdtscEv()
  store i64 %9, ptr %1, align 8, !tbaa !5
  call void @_ZN8graphlab5timer5sleepEm(i64 noundef 1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %10 = call noundef i64 @_ZN8graphlab5rdtscEv()
  store i64 %10, ptr %2, align 8, !tbaa !5
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = load i64, ptr %1, align 8, !tbaa !5
  %13 = sub i64 %11, %12
  store i64 %13, ptr @_ZN8graphlabL19rtdsc_ticks_per_secE, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  br label %14

14:                                               ; preds = %8, %5
  call void @_ZNK8graphlab5mutex6unlockEv(ptr noundef nonnull align 8 dereferenceable(40) @_ZN8graphlabL25rtdsc_ticks_per_sec_mutexE)
  br label %15

15:                                               ; preds = %14, %0
  %16 = load i64, ptr @_ZN8graphlabL19rtdsc_ticks_per_secE, align 8, !tbaa !5
  ret i64 %16
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab5mutex4lockEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN8graphlab5rdtscEv() #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab5mutex6unlockEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { inlinehint 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 }

!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++ TBAA"}


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

%"class.graphlab::mutex" = type { %union.pthread_mutex_t }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@_ZN8graphlabL25rtdsc_ticks_per_sec_mutexE = external hidden global %"class.graphlab::mutex", align 8
@_ZN8graphlabL19rtdsc_ticks_per_secE = external hidden local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8graphlab5timer5sleepEm(i64 noundef) local_unnamed_addr #0 align 2

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

3:                                                ; preds = %0
  tail call void @_ZNK8graphlab5mutex4lockEv(ptr noundef nonnull align 8 dereferenceable(40) @_ZN8graphlabL25rtdsc_ticks_per_sec_mutexE)
  %4 = load i64, ptr @_ZN8graphlabL19rtdsc_ticks_per_secE, align 8, !tbaa !5
  %5 = icmp eq i64 %4, 0
  br i1 %5, label %6, label %10

6:                                                ; preds = %3
  %7 = tail call noundef i64 @_ZN8graphlab5rdtscEv()
  tail call void @_ZN8graphlab5timer5sleepEm(i64 noundef 1)
  %8 = tail call noundef i64 @_ZN8graphlab5rdtscEv()
  %9 = sub i64 %8, %7
  store i64 %9, ptr @_ZN8graphlabL19rtdsc_ticks_per_secE, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %6, %3
  tail call void @_ZNK8graphlab5mutex6unlockEv(ptr noundef nonnull align 8 dereferenceable(40) @_ZN8graphlabL25rtdsc_ticks_per_sec_mutexE)
  %.pre = load i64, ptr @_ZN8graphlabL19rtdsc_ticks_per_secE, align 8, !tbaa !5
  br label %11

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab5mutex4lockEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN8graphlab5rdtscEv() local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZNK8graphlab5mutex6unlockEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

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


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