; LLVM IR from vczh/herodb :: Kernel/Source/Vlpp.ll (ZN2vl8SpinLock5EnterEv)

; 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.vl::SpinLock" = type { %"class.vl::Object", i64 }
%"class.vl::Object" = type { ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN2vl8SpinLock5EnterEv(ptr noundef nonnull align 8 dereferenceable(16) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  br label %4

4:                                                ; preds = %15, %1
  %5 = getelementptr inbounds %"class.vl::SpinLock", ptr %3, i32 0, i32 1
  %6 = cmpxchg ptr %5, i64 0, i64 1 seq_cst seq_cst, align 8
  %7 = extractvalue { i64, i1 } %6, 0
  %8 = icmp ne i64 %7, 0
  br i1 %8, label %9, label %16

9:                                                ; preds = %4
  br label %10

10:                                               ; preds = %14, %9
  %11 = getelementptr inbounds %"class.vl::SpinLock", ptr %3, i32 0, i32 1
  %12 = load volatile i64, ptr %11, align 8, !tbaa !9
  %13 = icmp ne i64 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  call void @llvm.x86.sse2.pause()
  br label %10, !llvm.loop !13

15:                                               ; preds = %10
  br label %4, !llvm.loop !15

16:                                               ; preds = %4
  ret void
}

; Function Attrs: nounwind
declare void @llvm.x86.sse2.pause() #1

attributes #0 = { 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 #1 = { 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, !12, i64 8}
!10 = !{!"_ZTSN2vl8SpinLockE", !11, i64 0, !12, i64 8}
!11 = !{!"_ZTSN2vl6ObjectE"}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nounwind uwtable
define dso_local void @_ZN2vl8SpinLock5EnterEv(ptr noundef nonnull align 8 dereferenceable(16) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = cmpxchg ptr %2, i64 0, i64 1 seq_cst seq_cst, align 8
  %.not3 = extractvalue { i64, i1 } %3, 1
  br i1 %.not3, label %._crit_edge, label %.preheader

.loopexit:                                        ; preds = %.lr.ph, %.preheader
  %4 = cmpxchg ptr %2, i64 0, i64 1 seq_cst seq_cst, align 8
  %.not = extractvalue { i64, i1 } %4, 1
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %1, %.loopexit
  %5 = load volatile i64, ptr %2, align 8, !tbaa !7
  %.not12 = icmp eq i64 %5, 0
  br i1 %.not12, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  tail call void @llvm.x86.sse2.pause()
  %6 = load volatile i64, ptr %2, align 8, !tbaa !7
  %.not1 = icmp eq i64 %6, 0
  br i1 %.not1, label %.loopexit, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.loopexit, %1
  ret void
}

; Function Attrs: nounwind
declare void @llvm.x86.sse2.pause() #1

attributes #0 = { 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 #1 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !10, i64 8}
!8 = !{!"_ZTSN2vl8SpinLockE", !9, i64 0, !10, i64 8}
!9 = !{!"_ZTSN2vl6ObjectE"}
!10 = !{!"long", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = distinct !{!13, !6}


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