; LLVM IR from mitdbg/deneva :: storage/index_btree.ll (ZN11index_btree10index_nextEmRP8itemid_tb)

; 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.index_btree = type { %class.index_base, i64, i32, ptr, ptr, ptr }
%class.index_base = type { ptr, ptr }
%struct.bt_node = type { ptr, i8, ptr, ptr, i32, ptr, i8, %union.pthread_mutex_t, i32, i32 }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__._ZN11index_btree10index_nextEmRP8itemid_tb = external hidden unnamed_addr constant [56 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN11index_btree10index_nextEmRP8itemid_tb(ptr noundef nonnull align 8 dereferenceable(56) %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %2, i1 noundef zeroext %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %12 = zext i1 %3 to i8
  store i8 %12, ptr %8, align 1, !tbaa !11
  %13 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %14 = getelementptr inbounds %class.index_btree, ptr %13, i32 0, i32 5
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = getelementptr inbounds ptr, ptr %15, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !5
  %19 = load i32, ptr %18, align 4, !tbaa !17
  store i32 %19, ptr %9, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %20 = getelementptr inbounds %class.index_btree, ptr %13, i32 0, i32 4
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = getelementptr inbounds ptr, ptr %21, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  store ptr %25, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.bt_node, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !19
  %29 = load i32, ptr %9, align 4, !tbaa !17
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i64, ptr %28, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !9
  store i64 %32, ptr %11, align 8, !tbaa !9
  %33 = getelementptr inbounds %class.index_btree, ptr %13, i32 0, i32 5
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = getelementptr inbounds ptr, ptr %34, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = load i32, ptr %37, align 4, !tbaa !17
  %39 = add i32 %38, 1
  store i32 %39, ptr %37, align 4, !tbaa !17
  %40 = getelementptr inbounds %class.index_btree, ptr %13, i32 0, i32 5
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = load i64, ptr %6, align 8, !tbaa !9
  %43 = getelementptr inbounds ptr, ptr %41, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = load i32, ptr %44, align 4, !tbaa !17
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.bt_node, ptr %46, i32 0, i32 4
  %48 = load i32, ptr %47, align 8, !tbaa !22
  %49 = icmp uge i32 %45, %48
  br i1 %49, label %50, label %65

50:                                               ; preds = %4
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.bt_node, ptr %51, i32 0, i32 5
  %53 = load ptr, ptr %52, align 8, !tbaa !23
  store ptr %53, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %class.index_btree, ptr %13, i32 0, i32 4
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  %57 = load i64, ptr %6, align 8, !tbaa !9
  %58 = getelementptr inbounds ptr, ptr %56, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  store ptr %54, ptr %59, align 8, !tbaa !5
  %60 = getelementptr inbounds %class.index_btree, ptr %13, i32 0, i32 5
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = load i64, ptr %6, align 8, !tbaa !9
  %63 = getelementptr inbounds ptr, ptr %61, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  store i32 0, ptr %64, align 4, !tbaa !17
  br label %65

65:                                               ; preds = %50, %4
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = icmp eq ptr %66, null
  br i1 %67, label %68, label %70

68:                                               ; preds = %65
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr null, ptr %69, align 8, !tbaa !5
  br label %113

70:                                               ; preds = %65
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.bt_node, ptr %71, i32 0, i32 1
  %73 = load i8, ptr %72, align 8, !tbaa !24, !range !25, !noundef !26
  %74 = trunc i8 %73 to i1
  br i1 %74, label %75, label %76

75:                                               ; preds = %70
  br label %78

76:                                               ; preds = %70
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 79, ptr noundef @__PRETTY_FUNCTION__._ZN11index_btree10index_nextEmRP8itemid_tb) #4
  unreachable

77:                                               ; No predecessors!
  br label %78

78:                                               ; preds = %77, %75
  %79 = load i8, ptr %8, align 1, !tbaa !11, !range !25, !noundef !26
  %80 = trunc i8 %79 to i1
  br i1 %80, label %81, label %98

81:                                               ; preds = %78
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.bt_node, ptr %82, i32 0, i32 2
  %84 = load ptr, ptr %83, align 8, !tbaa !19
  %85 = getelementptr inbounds %class.index_btree, ptr %13, i32 0, i32 5
  %86 = load ptr, ptr %85, align 8, !tbaa !13
  %87 = load i64, ptr %6, align 8, !tbaa !9
  %88 = getelementptr inbounds ptr, ptr %86, i64 %87
  %89 = load ptr, ptr %88, align 8, !tbaa !5
  %90 = load i32, ptr %89, align 4, !tbaa !17
  %91 = zext i32 %90 to i64
  %92 = getelementptr inbounds i64, ptr %84, i64 %91
  %93 = load i64, ptr %92, align 8, !tbaa !9
  %94 = load i64, ptr %11, align 8, !tbaa !9
  %95 = icmp ne i64 %93, %94
  br i1 %95, label %96, label %98

96:                                               ; preds = %81
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr null, ptr %97, align 8, !tbaa !5
  br label %112

98:                                               ; preds = %81, %78
  %99 = load ptr, ptr %10, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.bt_node, ptr %99, i32 0, i32 0
  %101 = load ptr, ptr %100, align 8, !tbaa !27
  %102 = getelementptr inbounds %class.index_btree, ptr %13, i32 0, i32 5
  %103 = load ptr, ptr %102, align 8, !tbaa !13
  %104 = load i64, ptr %6, align 8, !tbaa !9
  %105 = getelementptr inbounds ptr, ptr %103, i64 %104
  %106 = load ptr, ptr %105, align 8, !tbaa !5
  %107 = load i32, ptr %106, align 4, !tbaa !17
  %108 = zext i32 %107 to i64
  %109 = getelementptr inbounds ptr, ptr %101, i64 %108
  %110 = load ptr, ptr %109, align 8, !tbaa !5
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %110, ptr %111, align 8, !tbaa !5
  br label %112

112:                                              ; preds = %98, %96
  br label %113

113:                                              ; preds = %112, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !6, i64 48}
!14 = !{!"_ZTS11index_btree", !15, i64 0, !10, i64 16, !16, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!15 = !{!"_ZTS10index_base", !6, i64 8}
!16 = !{!"int", !7, i64 0}
!17 = !{!16, !16, i64 0}
!18 = !{!14, !6, i64 40}
!19 = !{!20, !6, i64 16}
!20 = !{!"_ZTS7bt_node", !6, i64 0, !12, i64 8, !6, i64 16, !6, i64 24, !16, i64 32, !6, i64 40, !12, i64 48, !7, i64 56, !21, i64 96, !16, i64 100}
!21 = !{!"_ZTS7latch_t", !7, i64 0}
!22 = !{!20, !16, i64 32}
!23 = !{!20, !6, i64 40}
!24 = !{!20, !12, i64 8}
!25 = !{i8 0, i8 2}
!26 = !{}
!27 = !{!20, !6, 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"

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1
@__PRETTY_FUNCTION__._ZN11index_btree10index_nextEmRP8itemid_tb = external hidden unnamed_addr constant [56 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN11index_btree10index_nextEmRP8itemid_tb(ptr nocapture noundef nonnull readonly align 8 dereferenceable(56) %0, i64 noundef %1, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %2, i1 noundef zeroext %3) local_unnamed_addr #1 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds ptr, ptr %6, i64 %1
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = load i32, ptr %8, align 4, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = getelementptr inbounds ptr, ptr %11, i64 %1
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = sext i32 %9 to i64
  %18 = getelementptr inbounds i64, ptr %16, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !20
  %20 = add i32 %9, 1
  store i32 %20, ptr %8, align 4, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %14, i64 32
  %22 = load i32, ptr %21, align 8, !tbaa !21
  %.not = icmp ult i32 %20, %22
  br i1 %.not, label %.thread, label %23

23:                                               ; preds = %4
  %24 = getelementptr inbounds i8, ptr %14, i64 40
  %25 = load ptr, ptr %24, align 8, !tbaa !22
  store ptr %25, ptr %13, align 8, !tbaa !13
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds ptr, ptr %26, i64 %1
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  store i32 0, ptr %28, align 4, !tbaa !14
  %29 = icmp eq ptr %25, null
  br i1 %29, label %46, label %.thread

.thread:                                          ; preds = %4, %23
  %30 = phi i32 [ 0, %23 ], [ %20, %4 ]
  %.024 = phi ptr [ %25, %23 ], [ %14, %4 ]
  %31 = getelementptr inbounds i8, ptr %.024, i64 8
  %32 = load i8, ptr %31, align 8, !tbaa !23, !range !24, !noundef !25
  %33 = trunc nuw i8 %32 to i1
  br i1 %33, label %35, label %34

34:                                               ; preds = %.thread
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 79, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN11index_btree10index_nextEmRP8itemid_tb) #2
  unreachable

35:                                               ; preds = %.thread
  br i1 %3, label %36, label %._crit_edge

._crit_edge:                                      ; preds = %35
  %.pre = zext i32 %30 to i64
  br label %42

36:                                               ; preds = %35
  %37 = getelementptr inbounds i8, ptr %.024, i64 16
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  %39 = zext i32 %30 to i64
  %40 = getelementptr inbounds i64, ptr %38, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !20
  %.not22 = icmp eq i64 %41, %19
  br i1 %.not22, label %42, label %46

42:                                               ; preds = %._crit_edge, %36
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %39, %36 ]
  %43 = load ptr, ptr %.024, align 8, !tbaa !26
  %44 = getelementptr inbounds ptr, ptr %43, i64 %.pre-phi
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  br label %46

46:                                               ; preds = %36, %23, %42
  %.sink = phi ptr [ %45, %42 ], [ null, %23 ], [ null, %36 ]
  store ptr %.sink, ptr %2, align 8, !tbaa !13
  ret i32 0
}

attributes #0 = { 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 #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 }

!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 48}
!6 = !{!"_ZTS11index_btree", !7, i64 0, !11, i64 16, !12, i64 24, !8, i64 32, !8, i64 40, !8, i64 48}
!7 = !{!"_ZTS10index_base", !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!6, !8, i64 40}
!16 = !{!17, !8, i64 16}
!17 = !{!"_ZTS7bt_node", !8, i64 0, !18, i64 8, !8, i64 16, !8, i64 24, !12, i64 32, !8, i64 40, !18, i64 48, !9, i64 56, !19, i64 96, !12, i64 100}
!18 = !{!"bool", !9, i64 0}
!19 = !{!"_ZTS7latch_t", !9, i64 0}
!20 = !{!11, !11, i64 0}
!21 = !{!17, !12, i64 32}
!22 = !{!17, !8, i64 40}
!23 = !{!17, !18, i64 8}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = !{!17, !8, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass