; LLVM IR from mitdbg/deneva :: concurrency_control/row_mvcc.ll (ZN8Row_mvcc10buffer_reqE6TsTypeP10TxnManager)

; 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.MVReqEntry = type { ptr, i64, i64, ptr }
%class.Row_mvcc = type { ptr, i8, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64 }

@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__._ZN8Row_mvcc10buffer_reqE6TsTypeP10TxnManager = external hidden unnamed_addr constant [48 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; 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 dso_local noundef ptr @_ZN8Row_mvcc13get_req_entryEv(ptr noundef nonnull align 8 dereferenceable(104)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Row_mvcc10buffer_reqE6TsTypeP10TxnManager(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef %1, ptr noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, 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
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = call noundef ptr @_ZN8Row_mvcc13get_req_entryEv(ptr noundef nonnull align 8 dereferenceable(104) %8)
  store ptr %9, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  br label %15

13:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 98, ptr noundef @__PRETTY_FUNCTION__._ZN8Row_mvcc10buffer_reqE6TsTypeP10TxnManager) #5
  unreachable

14:                                               ; No predecessors!
  br label %15

15:                                               ; preds = %14, %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.MVReqEntry, ptr %17, i32 0, i32 0
  store ptr %16, ptr %18, align 8, !tbaa !11
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = call noundef i64 @_ZN10TxnManager13get_timestampEv(ptr noundef nonnull align 8 dereferenceable(544) %19)
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.MVReqEntry, ptr %21, i32 0, i32 1
  store i64 %20, ptr %22, align 8, !tbaa !14
  %23 = call noundef i64 @_Z13get_sys_clockv()
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MVReqEntry, ptr %24, i32 0, i32 2
  store i64 %23, ptr %25, align 8, !tbaa !15
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %38

28:                                               ; preds = %15
  %29 = getelementptr inbounds %class.Row_mvcc, ptr %8, i32 0, i32 11
  %30 = load i64, ptr %29, align 8, !tbaa !16
  %31 = add i64 %30, 1
  store i64 %31, ptr %29, align 8, !tbaa !16
  %32 = getelementptr inbounds %class.Row_mvcc, ptr %8, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !19
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.MVReqEntry, ptr %34, i32 0, i32 3
  store ptr %33, ptr %35, align 8, !tbaa !20
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %class.Row_mvcc, ptr %8, i32 0, i32 3
  store ptr %36, ptr %37, align 8, !tbaa !19
  br label %52

38:                                               ; preds = %15
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 2
  br i1 %40, label %41, label %51

41:                                               ; preds = %38
  %42 = getelementptr inbounds %class.Row_mvcc, ptr %8, i32 0, i32 12
  %43 = load i64, ptr %42, align 8, !tbaa !21
  %44 = add i64 %43, 1
  store i64 %44, ptr %42, align 8, !tbaa !21
  %45 = getelementptr inbounds %class.Row_mvcc, ptr %8, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !22
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.MVReqEntry, ptr %47, i32 0, i32 3
  store ptr %46, ptr %48, align 8, !tbaa !20
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %class.Row_mvcc, ptr %8, i32 0, i32 4
  store ptr %49, ptr %50, align 8, !tbaa !22
  br label %51

51:                                               ; preds = %41, %38
  br label %52

52:                                               ; preds = %51, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

declare noundef i64 @_ZN10TxnManager13get_timestampEv(ptr noundef nonnull align 8 dereferenceable(544)) #3

declare noundef i64 @_Z13get_sys_clockv() #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 = { "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, !10, i64 0}
!10 = !{!"_ZTS6TsType", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS10MVReqEntry", !6, i64 0, !13, i64 8, !13, i64 16, !6, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !13, i64 16}
!16 = !{!17, !13, i64 88}
!17 = !{!"_ZTS8Row_mvcc", !6, i64 0, !18, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !13, i64 96}
!18 = !{!"bool", !7, i64 0}
!19 = !{!17, !6, i64 24}
!20 = !{!12, !6, i64 24}
!21 = !{!17, !13, i64 96}
!22 = !{!17, !6, i64 32}


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

@.str.1 = external hidden unnamed_addr constant [80 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__._ZN8Row_mvcc10buffer_reqE6TsTypeP10TxnManager = external hidden unnamed_addr constant [48 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN8Row_mvcc13get_req_entryEv(ptr noundef nonnull align 8 dereferenceable(104)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Row_mvcc10buffer_reqE6TsTypeP10TxnManager(ptr noundef nonnull align 8 dereferenceable(104) %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 align 2 {
  %4 = tail call noundef ptr @_ZN8Row_mvcc13get_req_entryEv(ptr noundef nonnull align 8 dereferenceable(104) %0)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %6

5:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 98, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN8Row_mvcc10buffer_reqE6TsTypeP10TxnManager) #3
  unreachable

6:                                                ; preds = %3
  store ptr %2, ptr %4, align 8, !tbaa !5
  %7 = tail call noundef i64 @_ZN10TxnManager13get_timestampEv(ptr noundef nonnull align 8 dereferenceable(544) %2)
  %8 = getelementptr inbounds i8, ptr %4, i64 8
  store i64 %7, ptr %8, align 8, !tbaa !11
  %9 = tail call noundef i64 @_Z13get_sys_clockv()
  %10 = getelementptr inbounds i8, ptr %4, i64 16
  store i64 %9, ptr %10, align 8, !tbaa !12
  switch i32 %1, label %18 [
    i32 0, label %.sink.split
    i32 2, label %11
  ]

11:                                               ; preds = %6
  br label %.sink.split

.sink.split:                                      ; preds = %6, %11
  %.sink19 = phi i64 [ 96, %11 ], [ 88, %6 ]
  %.sink16 = phi i64 [ 32, %11 ], [ 24, %6 ]
  %12 = getelementptr inbounds i8, ptr %0, i64 %.sink19
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = add i64 %13, 1
  store i64 %14, ptr %12, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %0, i64 %.sink16
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr %16, ptr %17, align 8, !tbaa !15
  store ptr %4, ptr %15, align 8, !tbaa !14
  br label %18

18:                                               ; preds = %.sink.split, %6
  ret void
}

declare noundef i64 @_ZN10TxnManager13get_timestampEv(ptr noundef nonnull align 8 dereferenceable(544)) local_unnamed_addr #2

declare noundef i64 @_Z13get_sys_clockv() local_unnamed_addr #2

attributes #0 = { noreturn nounwind "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" }
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 = { 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, !7, i64 0}
!6 = !{!"_ZTS10MVReqEntry", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 16}
!13 = !{!10, !10, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !7, i64 24}


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