; LLVM IR from mitdbg/deneva :: system/manager.ll (ZN7Manager10get_min_tsEm)

; 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.TxnTable = type { i64, ptr }
%class.Manager = type { %union.pthread_mutex_t, i64, [31 x %union.pthread_mutex_t], ptr, ptr, i64, i64 }
%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 }

@txn_table = external global %class.TxnTable, align 8

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

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

declare noundef i64 @_Z13get_sys_clockv() #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN7Manager10get_min_tsEm(ptr noundef nonnull align 8 dereferenceable(1320) %0, i64 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = call noundef i64 @_Z13get_sys_clockv()
  store i64 %8, ptr %5, align 8, !tbaa !9
  %9 = load i64, ptr %5, align 8, !tbaa !9
  %10 = getelementptr inbounds %class.Manager, ptr %7, i32 0, i32 5
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = sub i64 %9, %11
  %13 = icmp ugt i64 %12, 10000000
  br i1 %13, label %14, label %27

14:                                               ; preds = %2
  %15 = load i64, ptr %5, align 8, !tbaa !9
  %16 = getelementptr inbounds %class.Manager, ptr %7, i32 0, i32 5
  store i64 %15, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = call noundef i64 @_ZN8TxnTable10get_min_tsEm(ptr noundef nonnull align 8 dereferenceable(16) @txn_table, i64 noundef %17)
  store i64 %18, ptr %6, align 8, !tbaa !9
  %19 = load i64, ptr %6, align 8, !tbaa !9
  %20 = getelementptr inbounds %class.Manager, ptr %7, i32 0, i32 6
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = icmp ugt i64 %19, %21
  br i1 %22, label %23, label %26

23:                                               ; preds = %14
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = getelementptr inbounds %class.Manager, ptr %7, i32 0, i32 6
  store i64 %24, ptr %25, align 8, !tbaa !13
  br label %26

26:                                               ; preds = %23, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %27

27:                                               ; preds = %26, %2
  %28 = getelementptr inbounds %class.Manager, ptr %7, i32 0, i32 6
  %29 = load i64, ptr %28, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i64 %29
}

declare noundef i64 @_ZN8TxnTable10get_min_tsEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 1304}
!12 = !{!"_ZTS7Manager", !7, i64 0, !10, i64 40, !7, i64 48, !6, i64 1288, !6, i64 1296, !10, i64 1304, !10, i64 1312}
!13 = !{!12, !10, i64 1312}


; 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.TxnTable = type { i64, ptr }

@txn_table = external global %class.TxnTable, align 8

declare noundef i64 @_Z13get_sys_clockv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN7Manager10get_min_tsEm(ptr nocapture noundef nonnull align 8 dereferenceable(1320) %0, i64 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef i64 @_Z13get_sys_clockv()
  %4 = getelementptr inbounds i8, ptr %0, i64 1304
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = sub i64 %3, %5
  %7 = icmp ugt i64 %6, 10000000
  br i1 %7, label %8, label %._crit_edge

._crit_edge:                                      ; preds = %2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 1312
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !11
  br label %14

8:                                                ; preds = %2
  store i64 %3, ptr %4, align 8, !tbaa !5
  %9 = tail call noundef i64 @_ZN8TxnTable10get_min_tsEm(ptr noundef nonnull align 8 dereferenceable(16) @txn_table, i64 noundef %1)
  %10 = getelementptr inbounds i8, ptr %0, i64 1312
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = icmp ugt i64 %9, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %8
  store i64 %9, ptr %10, align 8, !tbaa !11
  br label %14

14:                                               ; preds = %._crit_edge, %8, %13
  %15 = phi i64 [ %.pre, %._crit_edge ], [ %11, %8 ], [ %9, %13 ]
  ret i64 %15
}

declare noundef i64 @_ZN8TxnTable10get_min_tsEm(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef) local_unnamed_addr #0

attributes #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 = { 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" }

!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 1304}
!6 = !{!"_ZTS7Manager", !7, i64 0, !9, i64 40, !7, i64 48, !10, i64 1288, !10, i64 1296, !9, i64 1304, !9, i64 1312}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!6, !9, i64 1312}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass