; LLVM IR from mitdbg/deneva :: concurrency_control/row_maat.ll (ZN8Row_maat6accessE8access_tP10TxnManager)

; 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.TxnManager = type { ptr, ptr, ptr, i8, ptr, i32, i8, i32, i32, i8, i64, i64, i64, i64, ptr, ptr, ptr, i64, i8, i8, ptr, ptr, i64, i64, i64, %class.TxnStats, i32, i32, i32, i8, i32, %class.Array, i32, ptr, ptr, i32, %union.sem_t }
%class.TxnStats = type { i64, i64, i64, i64, i64, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, i64, i64, double, double, double, double, double, double, double, double }
%class.Array = type { ptr, i64, i64 }
%union.sem_t = type { i64, [24 x i8] }

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN8Row_maat6accessE8access_tP10TxnManager(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1, ptr noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = call noundef i64 @_Z13get_sys_clockv()
  store i64 %10, ptr %7, align 8, !tbaa !11
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %16

13:                                               ; preds = %3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = call noundef i32 @_ZN8Row_maat4readEP10TxnManager(ptr noundef nonnull align 8 dereferenceable(48) %9, ptr noundef %14)
  br label %16

16:                                               ; preds = %13, %3
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call noundef i32 @_ZN8Row_maat8prewriteEP10TxnManager(ptr noundef nonnull align 8 dereferenceable(48) %9, ptr noundef %20)
  br label %22

22:                                               ; preds = %19, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %23 = call noundef i64 @_Z13get_sys_clockv()
  %24 = load i64, ptr %7, align 8, !tbaa !11
  %25 = sub i64 %23, %24
  store i64 %25, ptr %8, align 8, !tbaa !11
  %26 = load i64, ptr %8, align 8, !tbaa !11
  %27 = uitofp i64 %26 to double
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %class.TxnManager, ptr %28, i32 0, i32 25
  %30 = getelementptr inbounds %class.TxnStats, ptr %29, i32 0, i32 21
  %31 = load double, ptr %30, align 8, !tbaa !13
  %32 = fadd double %31, %27
  store double %32, ptr %30, align 8, !tbaa !13
  %33 = load i64, ptr %8, align 8, !tbaa !11
  %34 = uitofp i64 %33 to double
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %class.TxnManager, ptr %35, i32 0, i32 25
  %37 = getelementptr inbounds %class.TxnStats, ptr %36, i32 0, i32 26
  %38 = load double, ptr %37, align 8, !tbaa !21
  %39 = fadd double %38, %34
  store double %39, ptr %37, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret i32 0
}

declare noundef i64 @_Z13get_sys_clockv() #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8Row_maat4readEP10TxnManager(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8Row_maat8prewriteEP10TxnManager(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef) #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 = { "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 }

!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 = !{!"_ZTS8access_t", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !18, i64 344}
!14 = !{!"_ZTS10TxnManager", !6, i64 8, !6, i64 16, !15, i64 24, !6, i64 32, !16, i64 40, !15, i64 44, !16, i64 48, !16, i64 52, !15, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !12, i64 120, !15, i64 128, !15, i64 129, !6, i64 136, !6, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !17, i64 176, !16, i64 432, !16, i64 436, !16, i64 440, !15, i64 444, !19, i64 448, !20, i64 456, !16, i64 480, !6, i64 488, !6, i64 496, !10, i64 504, !7, i64 512}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!"_ZTS8TxnStats", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !18, i64 40, !18, i64 48, !18, i64 56, !18, i64 64, !18, i64 72, !18, i64 80, !18, i64 88, !18, i64 96, !18, i64 104, !18, i64 112, !18, i64 120, !18, i64 128, !18, i64 136, !18, i64 144, !18, i64 152, !18, i64 160, !18, i64 168, !12, i64 176, !12, i64 184, !18, i64 192, !18, i64 200, !18, i64 208, !18, i64 216, !18, i64 224, !18, i64 232, !18, i64 240, !18, i64 248}
!18 = !{!"double", !7, i64 0}
!19 = !{!"_ZTS12CALVIN_PHASE", !7, i64 0}
!20 = !{!"_ZTS5ArrayIP5row_tE", !6, i64 0, !12, i64 8, !12, i64 16}
!21 = !{!14, !18, i64 384}


; 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 uwtable
define dso_local noundef i32 @_ZN8Row_maat6accessE8access_tP10TxnManager(ptr noundef nonnull align 8 dereferenceable(48) %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef i64 @_Z13get_sys_clockv()
  switch i32 %1, label %9 [
    i32 0, label %5
    i32 1, label %7
  ]

5:                                                ; preds = %3
  %6 = tail call noundef i32 @_ZN8Row_maat4readEP10TxnManager(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %2)
  br label %9

7:                                                ; preds = %3
  %8 = tail call noundef i32 @_ZN8Row_maat8prewriteEP10TxnManager(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %2)
  br label %9

9:                                                ; preds = %5, %3, %7
  %10 = tail call noundef i64 @_Z13get_sys_clockv()
  %11 = sub i64 %10, %4
  %12 = uitofp i64 %11 to double
  %13 = getelementptr inbounds i8, ptr %2, i64 344
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = fadd double %14, %12
  store double %15, ptr %13, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %2, i64 384
  %17 = load double, ptr %16, align 8, !tbaa !18
  %18 = fadd double %17, %12
  store double %18, ptr %16, align 8, !tbaa !18
  ret i32 0
}

declare noundef i64 @_Z13get_sys_clockv() local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8Row_maat4readEP10TxnManager(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN8Row_maat8prewriteEP10TxnManager(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef) local_unnamed_addr #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 = { "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" }

!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, !14, i64 344}
!6 = !{!"_ZTS10TxnManager", !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !11, i64 40, !10, i64 44, !11, i64 48, !11, i64 52, !10, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !12, i64 120, !10, i64 128, !10, i64 129, !7, i64 136, !7, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !13, i64 176, !11, i64 432, !11, i64 436, !11, i64 440, !10, i64 444, !15, i64 448, !16, i64 456, !11, i64 480, !7, i64 488, !7, i64 496, !17, i64 504, !8, i64 512}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!"_ZTS8TxnStats", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !14, i64 88, !14, i64 96, !14, i64 104, !14, i64 112, !14, i64 120, !14, i64 128, !14, i64 136, !14, i64 144, !14, i64 152, !14, i64 160, !14, i64 168, !12, i64 176, !12, i64 184, !14, i64 192, !14, i64 200, !14, i64 208, !14, i64 216, !14, i64 224, !14, i64 232, !14, i64 240, !14, i64 248}
!14 = !{!"double", !8, i64 0}
!15 = !{!"_ZTS12CALVIN_PHASE", !8, i64 0}
!16 = !{!"_ZTS5ArrayIP5row_tE", !7, i64 0, !12, i64 8, !12, i64 16}
!17 = !{!"_ZTS8access_t", !8, i64 0}
!18 = !{!6, !14, i64 384}


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