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

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

; 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 nounwind uwtable
define dso_local void @_ZN8TxnTable13update_min_tsEmmmm(ptr noundef nonnull align 8 dereferenceable(16) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  store i64 %4, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %13 = load i64, ptr %8, align 8, !tbaa !9
  %14 = getelementptr inbounds %class.TxnTable, ptr %12, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = urem i64 %13, %15
  store i64 %16, ptr %11, align 8, !tbaa !9
  br label %17

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

27:                                               ; preds = %17
  br label %17, !llvm.loop !14

28:                                               ; preds = %17
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = getelementptr inbounds %class.TxnTable, ptr %12, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = load i64, ptr %11, align 8, !tbaa !9
  %33 = getelementptr inbounds ptr, ptr %31, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.pool_node, ptr %34, i32 0, i32 4
  %36 = load i64, ptr %35, align 8, !tbaa !16
  %37 = icmp ult i64 %29, %36
  br i1 %37, label %38, label %46

38:                                               ; preds = %28
  %39 = load i64, ptr %10, align 8, !tbaa !9
  %40 = getelementptr inbounds %class.TxnTable, ptr %12, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = load i64, ptr %11, align 8, !tbaa !9
  %43 = getelementptr inbounds ptr, ptr %41, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.pool_node, ptr %44, i32 0, i32 4
  store i64 %39, ptr %45, align 8, !tbaa !16
  br label %46

46:                                               ; preds = %38, %28
  %47 = getelementptr inbounds %class.TxnTable, ptr %12, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load i64, ptr %11, align 8, !tbaa !9
  %50 = getelementptr inbounds ptr, ptr %48, i64 %49
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.pool_node, ptr %51, i32 0, i32 2
  %53 = cmpxchg ptr %52, i8 1, i8 0 seq_cst seq_cst, align 8
  %54 = extractvalue { i8, i1 } %53, 1
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !10, i64 32}
!17 = !{!"_ZTS9pool_node", !6, i64 0, !6, i64 8, !18, i64 16, !10, i64 24, !10, i64 32}
!18 = !{!"bool", !7, i64 0}


; 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 nofree norecurse nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN8TxnTable13update_min_tsEmmmm(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4) local_unnamed_addr #0 align 2 {
  %6 = load i64, ptr %0, align 8, !tbaa !5
  %7 = urem i64 %2, %6
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  br label %9

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

16:                                               ; preds = %9
  %17 = load ptr, ptr %8, align 8, !tbaa !11
  %18 = getelementptr inbounds ptr, ptr %17, i64 %7
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %19, i64 32
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = icmp ugt i64 %21, %4
  br i1 %22, label %23, label %24

23:                                               ; preds = %16
  store i64 %4, ptr %20, align 8, !tbaa !15
  br label %24

24:                                               ; preds = %23, %16
  %25 = getelementptr inbounds i8, ptr %19, i64 16
  %26 = cmpxchg ptr %25, i8 1, i8 0 seq_cst seq_cst, align 8
  ret void
}

attributes #0 = { mustprogress nofree norecurse nounwind memory(readwrite, inaccessiblemem: none) 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, !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, !7, i64 32}
!16 = !{!"_ZTS9pool_node", !10, i64 0, !10, i64 8, !17, i64 16, !7, i64 24, !7, i64 32}
!17 = !{!"bool", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass