; LLVM IR from mitdbg/deneva :: system/txn_table.ll (ZN8TxnTable11restart_txnEmmm)

; 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.QWorkQueue = type { ptr, ptr, ptr, ptr, i64, ptr, i64 }
%class.TxnTable = type { i64, ptr }
%struct.pool_node = type { ptr, ptr, i8, i64, i64 }
%struct.txn_node = type { ptr, i64, i64, i64, ptr, ptr }

@g_node_cnt = external global i32, align 4
@g_node_id = external global i32, align 4
@work_queue = external global %class.QWorkQueue, 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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN8TxnTable20is_matching_txn_nodeEP8txn_nodemm(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i64 noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8TxnTable11restart_txnEmmm(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = getelementptr inbounds %class.TxnTable, ptr %11, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = urem i64 %12, %14
  store i64 %15, ptr %9, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %26, %4
  %17 = getelementptr inbounds %class.TxnTable, ptr %11, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = load i64, ptr %9, align 8, !tbaa !9
  %20 = getelementptr inbounds ptr, ptr %18, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.pool_node, ptr %21, i32 0, i32 2
  %23 = cmpxchg ptr %22, i8 0, i8 1 seq_cst seq_cst, align 8
  %24 = extractvalue { i8, i1 } %23, 1
  %25 = xor i1 %24, true
  br i1 %25, label %26, label %27

26:                                               ; preds = %16
  br label %16, !llvm.loop !14

27:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %28 = getelementptr inbounds %class.TxnTable, ptr %11, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = load i64, ptr %9, align 8, !tbaa !9
  %31 = getelementptr inbounds ptr, ptr %29, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.pool_node, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  store ptr %34, ptr %10, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %64, %27
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %68

38:                                               ; preds = %35
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = call noundef zeroext i1 @_ZN8TxnTable20is_matching_txn_nodeEP8txn_nodemm(ptr noundef nonnull align 8 dereferenceable(16) %11, ptr noundef %39, i64 noundef %40, i64 noundef %41)
  br i1 %42, label %43, label %64

43:                                               ; preds = %38
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = load i32, ptr @g_node_cnt, align 4, !tbaa !19
  %46 = zext i32 %45 to i64
  %47 = urem i64 %44, %46
  %48 = load i32, ptr @g_node_id, align 4, !tbaa !19
  %49 = zext i32 %48 to i64
  %50 = icmp eq i64 %47, %49
  br i1 %50, label %51, label %57

51:                                               ; preds = %43
  %52 = load i64, ptr %6, align 8, !tbaa !9
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.txn_node, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !21
  %56 = call noundef ptr @_ZN7Message14create_messageEP10TxnManager10RemReqType(ptr noundef %55, i32 noundef 14)
  call void @_ZN10QWorkQueue7enqueueEmP7Messageb(ptr noundef nonnull align 8 dereferenceable(56) @work_queue, i64 noundef %52, ptr noundef %56, i1 noundef zeroext false)
  br label %63

57:                                               ; preds = %43
  %58 = load i64, ptr %6, align 8, !tbaa !9
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.txn_node, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !21
  %62 = call noundef ptr @_ZN7Message14create_messageEP10TxnManager10RemReqType(ptr noundef %61, i32 noundef 5)
  call void @_ZN10QWorkQueue7enqueueEmP7Messageb(ptr noundef nonnull align 8 dereferenceable(56) @work_queue, i64 noundef %58, ptr noundef %62, i1 noundef zeroext false)
  br label %63

63:                                               ; preds = %57, %51
  br label %68

64:                                               ; preds = %38
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.txn_node, ptr %65, i32 0, i32 4
  %67 = load ptr, ptr %66, align 8, !tbaa !23
  store ptr %67, ptr %10, align 8, !tbaa !5
  br label %35, !llvm.loop !24

68:                                               ; preds = %63, %35
  %69 = getelementptr inbounds %class.TxnTable, ptr %11, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !13
  %71 = load i64, ptr %9, align 8, !tbaa !9
  %72 = getelementptr inbounds ptr, ptr %70, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.pool_node, ptr %73, i32 0, i32 2
  %75 = cmpxchg ptr %74, i8 1, i8 0 seq_cst seq_cst, align 8
  %76 = extractvalue { i8, i1 } %75, 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

declare void @_ZN10QWorkQueue7enqueueEmP7Messageb(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef, ptr noundef, i1 noundef zeroext) #2

declare noundef ptr @_ZN7Message14create_messageEP10TxnManager10RemReqType(ptr noundef, i32 noundef) #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 = { 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 0}
!12 = !{!"_ZTS8TxnTable", !10, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTS9pool_node", !6, i64 0, !6, i64 8, !18, i64 16, !10, i64 24, !10, i64 32}
!18 = !{!"bool", !7, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"int", !7, i64 0}
!21 = !{!22, !6, i64 0}
!22 = !{!"_ZTS8txn_node", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !6, i64 32, !6, i64 40}
!23 = !{!22, !6, i64 32}
!24 = distinct !{!24, !15}


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

@g_node_cnt = external local_unnamed_addr global i32, align 4
@g_node_id = external local_unnamed_addr global i32, align 4
@work_queue = external global %class.QWorkQueue, align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN8TxnTable20is_matching_txn_nodeEP8txn_nodemm(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8TxnTable11restart_txnEmmm(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 align 2 {
  %5 = load i64, ptr %0, align 8, !tbaa !5
  %6 = urem i64 %2, %5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  br label %8

8:                                                ; preds = %8, %4
  %9 = load ptr, ptr %7, align 8, !tbaa !11
  %10 = getelementptr inbounds ptr, ptr %9, i64 %6
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %13 = cmpxchg ptr %12, i8 0, i8 1 seq_cst seq_cst, align 8
  %14 = extractvalue { i8, i1 } %13, 1
  br i1 %14, label %15, label %8, !llvm.loop !13

15:                                               ; preds = %8
  %16 = load ptr, ptr %7, align 8, !tbaa !11
  %17 = getelementptr inbounds ptr, ptr %16, i64 %6
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %.015 = load ptr, ptr %18, align 8, !tbaa !12
  %.not16 = icmp eq ptr %.015, null
  br i1 %.not16, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %15, %28
  %.017 = phi ptr [ %.0, %28 ], [ %.015, %15 ]
  %19 = tail call noundef zeroext i1 @_ZN8TxnTable20is_matching_txn_nodeEP8txn_nodemm(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull %.017, i64 noundef %2, i64 noundef %3)
  br i1 %19, label %.loopexit.sink.split, label %28

.loopexit.sink.split:                             ; preds = %.lr.ph
  %20 = load i32, ptr @g_node_cnt, align 4, !tbaa !15
  %21 = zext i32 %20 to i64
  %22 = urem i64 %2, %21
  %23 = load i32, ptr @g_node_id, align 4, !tbaa !15
  %24 = zext i32 %23 to i64
  %25 = icmp eq i64 %22, %24
  %26 = load ptr, ptr %.017, align 8, !tbaa !17
  %. = select i1 %25, i32 14, i32 5
  %27 = tail call noundef ptr @_ZN7Message14create_messageEP10TxnManager10RemReqType(ptr noundef %26, i32 noundef %.)
  tail call void @_ZN10QWorkQueue7enqueueEmP7Messageb(ptr noundef nonnull align 8 dereferenceable(56) @work_queue, i64 noundef %1, ptr noundef %27, i1 noundef zeroext false)
  br label %.loopexit

28:                                               ; preds = %.lr.ph
  %29 = getelementptr inbounds i8, ptr %.017, i64 32
  %.0 = load ptr, ptr %29, align 8, !tbaa !12
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !19

.loopexit:                                        ; preds = %28, %.loopexit.sink.split, %15
  %30 = load ptr, ptr %7, align 8, !tbaa !11
  %31 = getelementptr inbounds ptr, ptr %30, i64 %6
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  %34 = cmpxchg ptr %33, i8 1, i8 0 seq_cst seq_cst, align 8
  ret void
}

declare void @_ZN10QWorkQueue7enqueueEmP7Messageb(ptr noundef nonnull align 8 dereferenceable(56), i64 noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #1

declare noundef ptr @_ZN7Message14create_messageEP10TxnManager10RemReqType(ptr noundef, i32 noundef) local_unnamed_addr #1

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

!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 = !{!"_ZTS8TxnTable", !7, i64 0, !10, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !8, i64 0}
!17 = !{!18, !10, i64 0}
!18 = !{!"_ZTS8txn_node", !10, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 40}
!19 = distinct !{!19, !14}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass