; LLVM IR from erthink/libmdbx :: src (api-cursor)

; 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.iovec = type { ptr, i64 }

@__func__.mdbx_cursor_scan = external hidden unnamed_addr constant [17 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(none)
declare i64 @llvm.expect.i64(i64, i64) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @log_if_error(i32 noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @mdbx_cursor_get(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local i32 @mdbx_cursor_scan(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #4 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca %struct.iovec, align 8
  %18 = alloca %struct.iovec, align 8
  %19 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  %22 = xor i1 %21, true
  %23 = xor i1 %22, true
  %24 = xor i1 %23, true
  %25 = zext i1 %24 to i32
  %26 = sext i32 %25 to i64
  %27 = call i64 @llvm.expect.i64(i64 %26, i64 0)
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %6
  %30 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_cursor_scan, i32 noundef 546)
  store i32 %30, ptr %7, align 4
  br label %93

31:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  store i32 243, ptr %14, align 4, !tbaa !9
  %32 = load i32, ptr %11, align 4, !tbaa !9
  %33 = icmp ugt i32 %32, 30
  br i1 %33, label %39, label %34

34:                                               ; preds = %31
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = shl i32 1, %35
  %37 = and i32 %36, 243
  %38 = icmp eq i32 %37, 0
  br label %39

39:                                               ; preds = %34, %31
  %40 = phi i1 [ true, %31 ], [ %38, %34 ]
  %41 = xor i1 %40, true
  %42 = xor i1 %41, true
  %43 = zext i1 %42 to i32
  %44 = sext i32 %43 to i64
  %45 = call i64 @llvm.expect.i64(i64 %44, i64 0)
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %39
  %48 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_cursor_scan, i32 noundef 551)
  store i32 %48, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %92

49:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  store i32 294656, ptr %16, align 4, !tbaa !9
  %50 = load i32, ptr %12, align 4, !tbaa !9
  %51 = icmp ugt i32 %50, 30
  br i1 %51, label %57, label %52

52:                                               ; preds = %49
  %53 = load i32, ptr %12, align 4, !tbaa !9
  %54 = shl i32 1, %53
  %55 = and i32 %54, 294656
  %56 = icmp eq i32 %55, 0
  br label %57

57:                                               ; preds = %52, %49
  %58 = phi i1 [ true, %49 ], [ %56, %52 ]
  %59 = xor i1 %58, true
  %60 = xor i1 %59, true
  %61 = zext i1 %60 to i32
  %62 = sext i32 %61 to i64
  %63 = call i64 @llvm.expect.i64(i64 %62, i64 0)
  %64 = icmp ne i64 %63, 0
  br i1 %64, label %65, label %67

65:                                               ; preds = %57
  %66 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_cursor_scan, i32 noundef 557)
  store i32 %66, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %91

67:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 16, ptr %17) #6
  call void @llvm.memset.p0.i64(ptr align 8 %17, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr %18) #6
  call void @llvm.memset.p0.i64(ptr align 8 %18, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #6
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = call i32 @mdbx_cursor_get(ptr noundef %68, ptr noundef %17, ptr noundef %18, i32 noundef %69)
  store i32 %70, ptr %19, align 4, !tbaa !9
  %71 = load i32, ptr %19, align 4, !tbaa !9
  %72 = icmp ne i32 %71, 0
  %73 = xor i1 %72, true
  %74 = xor i1 %73, true
  %75 = zext i1 %74 to i32
  %76 = sext i32 %75 to i64
  %77 = call i64 @llvm.expect.i64(i64 %76, i64 0)
  %78 = icmp ne i64 %77, 0
  br i1 %78, label %79, label %82

79:                                               ; preds = %67
  %80 = load i32, ptr %19, align 4, !tbaa !9
  %81 = call i32 @log_if_error(i32 noundef %80, ptr noundef @__func__.mdbx_cursor_scan, i32 noundef 562)
  store i32 %81, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %90

82:                                               ; preds = %67
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = load ptr, ptr %13, align 8, !tbaa !5
  %87 = load i32, ptr %12, align 4, !tbaa !9
  %88 = call i32 @scan_confinue(ptr noundef %83, ptr noundef %84, ptr noundef %85, ptr noundef %86, ptr noundef %17, ptr noundef %18, i32 noundef %87) #7
  %89 = call i32 @log_if_error(i32 noundef %88, ptr noundef @__func__.mdbx_cursor_scan, i32 noundef 563)
  store i32 %89, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %90

90:                                               ; preds = %82, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %18) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %17) #6
  br label %91

91:                                               ; preds = %90, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  br label %92

92:                                               ; preds = %91, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  br label %93

93:                                               ; preds = %92, %29
  %94 = load i32, ptr %7, align 4
  ret i32 %94
}

; Function Attrs: hot nounwind uwtable
declare hidden i32 @scan_confinue(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { hot 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 #6 = { nounwind }
attributes #7 = { hot }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, 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"

%struct.iovec = type { ptr, i64 }

@__func__.mdbx_cursor_scan = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @log_if_error(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @mdbx_cursor_get(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @mdbx_cursor_scan(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) local_unnamed_addr #3 {
  %7 = alloca %struct.iovec, align 8
  %8 = alloca %struct.iovec, align 8
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %9, label %11, !prof !5

9:                                                ; preds = %6
  %10 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_cursor_scan, i32 noundef 546)
  br label %35

11:                                               ; preds = %6
  %12 = icmp ugt i32 %3, 30
  %13 = shl nuw i32 1, %3
  %14 = and i32 %13, 243
  %15 = icmp eq i32 %14, 0
  %16 = select i1 %12, i1 true, i1 %15, !prof !5
  br i1 %16, label %17, label %19, !prof !5

17:                                               ; preds = %11
  %18 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_cursor_scan, i32 noundef 551)
  br label %35

19:                                               ; preds = %11
  %20 = icmp ugt i32 %4, 30
  %21 = shl nuw i32 1, %4
  %22 = and i32 %21, 294656
  %23 = icmp eq i32 %22, 0
  %24 = select i1 %20, i1 true, i1 %23, !prof !5
  br i1 %24, label %25, label %27, !prof !5

25:                                               ; preds = %19
  %26 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_cursor_scan, i32 noundef 557)
  br label %35

27:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %7, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %8, i8 0, i64 16, i1 false)
  %28 = call i32 @mdbx_cursor_get(ptr noundef %0, ptr noundef nonnull %7, ptr noundef nonnull %8, i32 noundef %3)
  %.not17 = icmp eq i32 %28, 0
  br i1 %.not17, label %31, label %29, !prof !6

29:                                               ; preds = %27
  %30 = call i32 @log_if_error(i32 noundef %28, ptr noundef nonnull @__func__.mdbx_cursor_scan, i32 noundef 562)
  br label %34

31:                                               ; preds = %27
  %32 = call i32 @scan_confinue(ptr noundef %0, ptr noundef nonnull %1, ptr noundef %2, ptr noundef %5, ptr noundef nonnull %7, ptr noundef nonnull %8, i32 noundef %4) #6
  %33 = call i32 @log_if_error(i32 noundef %32, ptr noundef nonnull @__func__.mdbx_cursor_scan, i32 noundef 563)
  br label %34

34:                                               ; preds = %31, %29
  %.0 = phi i32 [ %30, %29 ], [ %33, %31 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #5
  br label %35

35:                                               ; preds = %17, %34, %25, %9
  %.3 = phi i32 [ %10, %9 ], [ %18, %17 ], [ %26, %25 ], [ %.0, %34 ]
  ret i32 %.3
}

; Function Attrs: hot nounwind uwtable
declare hidden i32 @scan_confinue(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { hot 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 #5 = { nounwind }
attributes #6 = { hot }

!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 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!6 = !{!"branch_weights", !"expected", i32 2000, i32 1}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass