; LLVM IR from EarlGray/language-incubator :: bf/bfi1.ll (Z9find_jumpRKSt6vectorI2OpSaIS0_EEjS0_)

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

@.str.1 = external hidden unnamed_addr constant [41 x i8], align 1
@_ZTIPKc = external constant ptr
@.str.2 = external hidden unnamed_addr constant [26 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 uwtable
define dso_local noundef i32 @_Z9find_jumpRKSt6vectorI2OpSaIS0_EEjS0_(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %14 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %14, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %15 = load i32, ptr %7, align 4, !tbaa !11
  switch i32 %15, label %18 [
    i32 6, label %16
    i32 7, label %17
  ]

16:                                               ; preds = %3
  store i32 7, ptr %11, align 4, !tbaa !11
  store i64 -1, ptr %10, align 8, !tbaa !13
  br label %20

17:                                               ; preds = %3
  store i32 6, ptr %11, align 4, !tbaa !11
  store i64 1, ptr %10, align 8, !tbaa !13
  br label %20

18:                                               ; preds = %3
  %19 = call ptr @__cxa_allocate_exception(i64 8) #2
  store ptr @.str.1, ptr %19, align 16, !tbaa !5
  call void @__cxa_throw(ptr %19, ptr @_ZTIPKc, ptr null) #3
  unreachable

20:                                               ; preds = %17, %16
  br label %21

21:                                               ; preds = %61, %20
  br label %22

22:                                               ; preds = %21
  %23 = load i64, ptr %10, align 8, !tbaa !13
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = add nsw i64 %25, %23
  %27 = trunc i64 %26 to i32
  store i32 %27, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorI2OpSaIS0_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24) %28, i64 noundef %30)
  %32 = load i32, ptr %31, align 4, !tbaa !11
  store i32 %32, ptr %12, align 4, !tbaa !11
  %33 = load i32, ptr %12, align 4, !tbaa !11
  %34 = load i32, ptr %11, align 4, !tbaa !11
  %35 = icmp eq i32 %33, %34
  br i1 %35, label %36, label %39

36:                                               ; preds = %22
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %8, align 4, !tbaa !9
  br label %58

39:                                               ; preds = %22
  %40 = load i32, ptr %12, align 4, !tbaa !11
  %41 = load i32, ptr %7, align 4, !tbaa !11
  %42 = icmp eq i32 %40, %41
  br i1 %42, label %43, label %57

43:                                               ; preds = %39
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = icmp sgt i32 %44, 0
  br i1 %45, label %46, label %49

46:                                               ; preds = %43
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = add nsw i32 %47, -1
  store i32 %48, ptr %8, align 4, !tbaa !9
  br label %56

49:                                               ; preds = %43
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %54

52:                                               ; preds = %49
  %53 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %53, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %59

54:                                               ; preds = %49
  %55 = call ptr @__cxa_allocate_exception(i64 8) #2
  store ptr @.str.2, ptr %55, align 16, !tbaa !5
  call void @__cxa_throw(ptr %55, ptr @_ZTIPKc, ptr null) #3
  unreachable

56:                                               ; preds = %46
  br label %57

57:                                               ; preds = %56, %39
  br label %58

58:                                               ; preds = %57, %36
  store i32 0, ptr %13, align 4
  br label %59

59:                                               ; preds = %58, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %60 = load i32, ptr %13, align 4
  switch i32 %60, label %62 [
    i32 0, label %61
  ]

61:                                               ; preds = %59
  br label %21, !llvm.loop !15

62:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %63 = load i32, ptr %4, align 4
  ret i32 %63
}

declare ptr @__cxa_allocate_exception(i64)

declare void @__cxa_throw(ptr, ptr, ptr)

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorI2OpSaIS0_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 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 = { nounwind }
attributes #3 = { noreturn }

!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 = !{!"_ZTS2Op", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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.1 = external hidden unnamed_addr constant [41 x i8], align 1
@_ZTIPKc = external constant ptr
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9find_jumpRKSt6vectorI2OpSaIS0_EEjS0_(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  switch i32 %2, label %5 [
    i32 6, label %7
    i32 7, label %4
  ]

4:                                                ; preds = %3
  br label %7

5:                                                ; preds = %3
  %6 = tail call ptr @__cxa_allocate_exception(i64 8) #1
  store ptr @.str.1, ptr %6, align 16, !tbaa !5
  tail call void @__cxa_throw(ptr nonnull %6, ptr nonnull @_ZTIPKc, ptr null) #2
  unreachable

7:                                                ; preds = %3, %4
  %.018 = phi i32 [ 1, %4 ], [ -1, %3 ]
  %.017 = phi i32 [ 6, %4 ], [ 7, %3 ]
  br label %.outer

.outer:                                           ; preds = %.outer.backedge, %7
  %.020.ph = phi i32 [ 0, %7 ], [ %.020.ph.be, %.outer.backedge ]
  %.019.ph = phi i32 [ %1, %7 ], [ %9, %.outer.backedge ]
  br label %8

8:                                                ; preds = %.outer, %16
  %.019 = phi i32 [ %9, %16 ], [ %.019.ph, %.outer ]
  %9 = add i32 %.019, %.018
  %10 = zext i32 %9 to i64
  %11 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorI2OpSaIS0_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %10)
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp eq i32 %12, %.017
  br i1 %13, label %14, label %16

14:                                               ; preds = %8
  %15 = add nsw i32 %.020.ph, 1
  br label %.outer.backedge

.outer.backedge:                                  ; preds = %14, %20
  %.020.ph.be = phi i32 [ %21, %20 ], [ %15, %14 ]
  br label %.outer, !llvm.loop !11

16:                                               ; preds = %8
  %17 = icmp eq i32 %12, %2
  br i1 %17, label %18, label %8, !llvm.loop !11

18:                                               ; preds = %16
  %19 = icmp sgt i32 %.020.ph, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %18
  %21 = add nsw i32 %.020.ph, -1
  br label %.outer.backedge

22:                                               ; preds = %18
  %23 = icmp eq i32 %.020.ph, 0
  br i1 %23, label %26, label %24

24:                                               ; preds = %22
  %25 = tail call ptr @__cxa_allocate_exception(i64 8) #1
  store ptr @.str.2, ptr %25, align 16, !tbaa !5
  tail call void @__cxa_throw(ptr nonnull %25, ptr nonnull @_ZTIPKc, ptr null) #2
  unreachable

26:                                               ; preds = %22
  ret i32 %9
}

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

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

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 = { nounwind }
attributes #2 = { noreturn }

!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 = !{!"_ZTS2Op", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass