; LLVM IR from thepowersgang/mrustc :: src/mir/from_hir_match.ll (ZNK14PatternRuleset9is_beforeERKS_)

; 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.PatternRuleset = type { i32, i32, %"class.std::vector.136", %"class.std::vector.141" }
%"class.std::vector.136" = type { %"struct.std::_Vector_base.137" }
%"struct.std::_Vector_base.137" = type { %"struct.std::_Vector_base<PatternRule, std::allocator<PatternRule>>::_Vector_impl" }
%"struct.std::_Vector_base<PatternRule, std::allocator<PatternRule>>::_Vector_impl" = type { %"struct.std::_Vector_base<PatternRule, std::allocator<PatternRule>>::_Vector_impl_data" }
%"struct.std::_Vector_base<PatternRule, std::allocator<PatternRule>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.141" = type { %"struct.std::_Vector_base.142" }
%"struct.std::_Vector_base.142" = type { %"struct.std::_Vector_base<PatternBinding, std::allocator<PatternBinding>>::_Vector_impl" }
%"struct.std::_Vector_base<PatternBinding, std::allocator<PatternBinding>>::_Vector_impl" = type { %"struct.std::_Vector_base<PatternBinding, std::allocator<PatternBinding>>::_Vector_impl_data" }
%"struct.std::_Vector_base<PatternBinding, std::allocator<PatternBinding>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@.str.17 = external hidden unnamed_addr constant [81 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [39 x i8], align 1
@__PRETTY_FUNCTION__._ZNK14PatternRuleset9is_beforeERKS_ = external hidden unnamed_addr constant [61 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI11PatternRuleSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(120) ptr @_ZNKSt6vectorI11PatternRuleSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK14PatternRuleset9is_beforeERKS_(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(56) %1) #3 align 2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  %12 = getelementptr inbounds %struct.PatternRuleset, ptr %11, i32 0, i32 2
  %13 = call noundef i64 @_ZNKSt6vectorI11PatternRuleSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %12) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.PatternRuleset, ptr %14, i32 0, i32 2
  %16 = call noundef i64 @_ZNKSt6vectorI11PatternRuleSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %15) #4
  %17 = icmp eq i64 %13, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %2
  br label %21

19:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.38, ptr noundef @.str.17, i32 noundef 812, ptr noundef @__PRETTY_FUNCTION__._ZNK14PatternRuleset9is_beforeERKS_) #5
  unreachable

20:                                               ; No predecessors!
  br label %21

21:                                               ; preds = %20, %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %51, %21
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds %struct.PatternRuleset, ptr %11, i32 0, i32 2
  %26 = call noundef i64 @_ZNKSt6vectorI11PatternRuleSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %25) #4
  %27 = icmp ult i64 %24, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %22
  store i32 2, ptr %7, align 4
  br label %54

29:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %30 = getelementptr inbounds %struct.PatternRuleset, ptr %11, i32 0, i32 2
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = zext i32 %31 to i64
  %33 = call noundef nonnull align 8 dereferenceable(120) ptr @_ZNKSt6vectorI11PatternRuleSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %32) #4
  store ptr %33, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.PatternRuleset, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = call noundef nonnull align 8 dereferenceable(120) ptr @_ZNKSt6vectorI11PatternRuleSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %35, i64 noundef %37) #4
  store ptr %38, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = call noundef i32 @_ZN14PatternRuleset14rule_is_beforeERK11PatternRuleS2_(ptr noundef nonnull align 8 dereferenceable(120) %39, ptr noundef nonnull align 8 dereferenceable(120) %40)
  store i32 %41, ptr %10, align 4, !tbaa !11
  %42 = load i32, ptr %10, align 4, !tbaa !11
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %47

44:                                               ; preds = %29
  %45 = load i32, ptr %10, align 4, !tbaa !11
  %46 = icmp eq i32 %45, -1
  store i1 %46, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %48

47:                                               ; preds = %29
  store i32 0, ptr %7, align 4
  br label %48

48:                                               ; preds = %47, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %49 = load i32, ptr %7, align 4
  switch i32 %49, label %54 [
    i32 0, label %50
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = add i32 %52, 1
  store i32 %53, ptr %6, align 4, !tbaa !9
  br label %22, !llvm.loop !13

54:                                               ; preds = %48, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %55 = load i32, ptr %7, align 4
  switch i32 %55, label %59 [
    i32 2, label %56
    i32 1, label %57
  ]

56:                                               ; preds = %54
  store i1 false, ptr %3, align 1
  br label %57

57:                                               ; preds = %56, %54
  %58 = load i1, ptr %3, align 1
  ret i1 %58

59:                                               ; preds = %54
  unreachable
}

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 = { 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 #3 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTS8Ordering", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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.17 = external hidden unnamed_addr constant [81 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [39 x i8], align 1
@__PRETTY_FUNCTION__._ZNK14PatternRuleset9is_beforeERKS_ = external hidden unnamed_addr constant [61 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI11PatternRuleSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(120) ptr @_ZNKSt6vectorI11PatternRuleSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZNK14PatternRuleset9is_beforeERKS_(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef nonnull align 8 dereferenceable(56) %1) local_unnamed_addr #2 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = tail call noundef i64 @_ZNKSt6vectorI11PatternRuleSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #3
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = tail call noundef i64 @_ZNKSt6vectorI11PatternRuleSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #3
  %7 = icmp eq i64 %4, %6
  br i1 %7, label %.preheader, label %9

.preheader:                                       ; preds = %2
  %8 = tail call noundef i64 @_ZNKSt6vectorI11PatternRuleSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #3
  %.not1822.not = icmp eq i64 %8, 0
  br i1 %.not1822.not, label %.split.loop.exit, label %.lr.ph

9:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.38, ptr noundef nonnull @.str.17, i32 noundef 812, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK14PatternRuleset9is_beforeERKS_) #4
  unreachable

10:                                               ; preds = %.lr.ph
  %11 = add i32 %.01323, 1
  %12 = zext i32 %11 to i64
  %13 = tail call noundef i64 @_ZNKSt6vectorI11PatternRuleSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #3
  %.not18 = icmp ugt i64 %13, %12
  br i1 %.not18, label %.lr.ph, label %.split.loop.exit, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader, %10
  %14 = phi i64 [ %12, %10 ], [ 0, %.preheader ]
  %.01323 = phi i32 [ %11, %10 ], [ 0, %.preheader ]
  %15 = tail call noundef nonnull align 8 dereferenceable(120) ptr @_ZNKSt6vectorI11PatternRuleSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %14) #3
  %16 = tail call noundef nonnull align 8 dereferenceable(120) ptr @_ZNKSt6vectorI11PatternRuleSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %14) #3
  %17 = tail call noundef i32 @_ZN14PatternRuleset14rule_is_beforeERK11PatternRuleS2_(ptr noundef nonnull align 8 dereferenceable(120) %15, ptr noundef nonnull align 8 dereferenceable(120) %16)
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %10, label %.split.loop.exit19

.split.loop.exit19:                               ; preds = %.lr.ph
  %18 = icmp eq i32 %17, -1
  br label %.split.loop.exit

.split.loop.exit:                                 ; preds = %10, %.preheader, %.split.loop.exit19
  %.not18.lcssa = phi i1 [ true, %.split.loop.exit19 ], [ false, %.preheader ], [ false, %10 ]
  %.2 = phi i1 [ %18, %.split.loop.exit19 ], [ undef, %.preheader ], [ undef, %10 ]
  %spec.select = and i1 %.not18.lcssa, %.2
  ret i1 %spec.select
}

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 = { 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 = { nounwind }
attributes #4 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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