; LLVM IR from rahulyesantharao/b-epsilon-tree :: src/be_tree/be_tree.ll (ZN6BeNode10IndexOfKeyEj)

; 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.BeNode = type { %class.Serializable, ptr, i32, ptr, ptr, ptr, ptr, ptr }
%class.Serializable = type { ptr }
%struct.BePivots = type { i32, [15 x i32], [16 x i32] }

@.str.11 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [89 x i8], align 1
@__PRETTY_FUNCTION__._ZN6BeNode10IndexOfKeyEj = external hidden unnamed_addr constant [33 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
declare dso_local void @_ZN6BeNode4OpenEv(ptr noundef nonnull align 8 dereferenceable(64)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6BeNode10IndexOfKeyEj(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %class.BeNode, ptr %8, i32 0, i32 4
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = icmp ne i32 %11, 0
  %13 = xor i1 %12, true
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  br label %17

15:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.11, ptr noundef @.str.12, i32 noundef 96, ptr noundef @__PRETTY_FUNCTION__._ZN6BeNode10IndexOfKeyEj) #3
  unreachable

16:                                               ; No predecessors!
  br label %17

17:                                               ; preds = %16, %14
  call void @_ZN6BeNode4OpenEv(ptr noundef nonnull align 8 dereferenceable(64) %8)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %60, %17
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = getelementptr inbounds %class.BeNode, ptr %8, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = getelementptr inbounds %struct.BePivots, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !15
  %24 = icmp ule i32 %19, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %18
  store i32 2, ptr %7, align 4
  br label %63

26:                                               ; preds = %18
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = getelementptr inbounds %class.BeNode, ptr %8, i32 0, i32 6
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = getelementptr inbounds %struct.BePivots, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !15
  %32 = icmp eq i32 %27, %31
  br i1 %32, label %43, label %33

33:                                               ; preds = %26
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = getelementptr inbounds %class.BeNode, ptr %8, i32 0, i32 6
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = getelementptr inbounds %struct.BePivots, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %6, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [15 x i32], ptr %37, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = icmp ult i32 %34, %41
  br i1 %42, label %43, label %59

43:                                               ; preds = %33, %26
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %57, label %46

46:                                               ; preds = %43
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = getelementptr inbounds %class.BeNode, ptr %8, i32 0, i32 6
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  %50 = getelementptr inbounds %struct.BePivots, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = sub nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [15 x i32], ptr %50, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = icmp uge i32 %47, %55
  br i1 %56, label %57, label %59

57:                                               ; preds = %46, %43
  %58 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %58, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %63

59:                                               ; preds = %46, %33
  br label %60

60:                                               ; preds = %59
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %6, align 4, !tbaa !9
  br label %18, !llvm.loop !17

63:                                               ; preds = %57, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %64 = load i32, ptr %7, align 4
  switch i32 %64, label %68 [
    i32 2, label %65
    i32 1, label %66
  ]

65:                                               ; preds = %63
  unreachable

66:                                               ; preds = %63
  %67 = load i32, ptr %3, align 4
  ret i32 %67

68:                                               ; preds = %63
  unreachable
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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 = { 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 = { noreturn nounwind }
attributes #4 = { 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, !6, i64 32}
!12 = !{!"_ZTS6BeNode", !13, i64 0, !6, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!13 = !{!"_ZTS12Serializable"}
!14 = !{!12, !6, i64 48}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTS8BePivots", !10, i64 0, !7, i64 4, !7, i64 64}
!17 = distinct !{!17, !18}
!18 = !{!"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.11 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [89 x i8], align 1
@__PRETTY_FUNCTION__._ZN6BeNode10IndexOfKeyEj = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6BeNode4OpenEv(ptr noundef nonnull align 8 dereferenceable(64)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6BeNode10IndexOfKeyEj(ptr noundef nonnull align 8 dereferenceable(64) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 4, !tbaa !12
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %.peel.begin, label %6

6:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.12, i32 noundef 96, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN6BeNode10IndexOfKeyEj) #2
  unreachable

.peel.begin:                                      ; preds = %2
  tail call void @_ZN6BeNode4OpenEv(ptr noundef nonnull align 8 dereferenceable(64) %0)
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = load i32, ptr %8, align 4, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %8, i64 4
  %11 = zext i32 %9 to i64
  %12 = add i32 %9, 1
  %wide.trip.count = zext i32 %12 to i64
  %13 = icmp eq i32 %9, 0
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %.peel.begin
  %15 = load i32, ptr %10, align 4, !tbaa !12
  %16 = icmp ugt i32 %15, %1
  br i1 %16, label %.loopexit, label %.peel.next

.peel.next:                                       ; preds = %14, %26
  %indvars.iv = phi i64 [ %indvars.iv.next, %26 ], [ 1, %14 ]
  %17 = icmp eq i64 %indvars.iv, %11
  br i1 %17, label %22, label %18

18:                                               ; preds = %.peel.next
  %19 = getelementptr inbounds [15 x i32], ptr %10, i64 0, i64 %indvars.iv
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = icmp ugt i32 %20, %1
  br i1 %21, label %22, label %26

22:                                               ; preds = %.peel.next, %18
  %23 = add nsw i64 %indvars.iv, -1
  %24 = getelementptr inbounds [15 x i32], ptr %10, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !12
  %.not13 = icmp ugt i32 %25, %1
  br i1 %.not13, label %26, label %.loopexit.loopexit.split.loop.exit18

26:                                               ; preds = %18, %22
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.peel.next, !llvm.loop !16

.loopexit.loopexit.split.loop.exit18:             ; preds = %22
  %27 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.loopexit

.loopexit:                                        ; preds = %26, %.loopexit.loopexit.split.loop.exit18, %.peel.begin, %14
  %.0.lcssa = phi i32 [ 0, %14 ], [ 0, %.peel.begin ], [ %27, %.loopexit.loopexit.split.loop.exit18 ], [ %12, %26 ]
  ret i32 %.0.lcssa
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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 = { 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 = { 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, !8, i64 32}
!6 = !{!"_ZTS6BeNode", !7, i64 0, !8, i64 8, !11, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56}
!7 = !{!"_ZTS12Serializable"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!6, !8, i64 48}
!14 = !{!15, !11, i64 0}
!15 = !{!"_ZTS8BePivots", !11, i64 0, !9, i64 4, !9, i64 64}
!16 = distinct !{!16, !17, !18}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.peeled.count", i32 1}


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