; LLVM IR from erthink/libmdbx :: src (cogs)

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

; Function Attrs: nounwind willreturn memory(none) uwtable
define dso_local i32 @pv2pages(i16 noundef zeroext %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i16, align 2
  store i16 %0, ptr %3, align 2, !tbaa !5
  %4 = load i16, ptr %3, align 2, !tbaa !5
  %5 = zext i16 %4 to i32
  %6 = and i32 %5, 32769
  %7 = icmp ne i32 %6, 32769
  br i1 %7, label %8, label %11

8:                                                ; preds = %1
  %9 = load i16, ptr %3, align 2, !tbaa !5
  %10 = zext i16 %9 to i32
  store i32 %10, ptr %2, align 4
  br label %28

11:                                               ; preds = %1
  %12 = load i16, ptr %3, align 2, !tbaa !5
  %13 = zext i16 %12 to i32
  %14 = icmp eq i32 %13, 65535
  br i1 %14, label %15, label %16

15:                                               ; preds = %11
  store i32 65536, ptr %2, align 4
  br label %28

16:                                               ; preds = %11
  %17 = load i16, ptr %3, align 2, !tbaa !5
  %18 = zext i16 %17 to i32
  %19 = ashr i32 %18, 1
  %20 = and i32 %19, 2047
  %21 = sext i32 %20 to i64
  %22 = load i16, ptr %3, align 2, !tbaa !5
  %23 = zext i16 %22 to i32
  %24 = ashr i32 %23, 12
  %25 = and i32 %24, 7
  %26 = sext i32 %25 to i64
  %27 = call i32 @me2v(i64 noundef %21, i64 noundef %26) #2
  store i32 %27, ptr %2, align 4
  br label %28

28:                                               ; preds = %16, %15, %8
  %29 = load i32, ptr %2, align 4
  ret i32 %29
}

; Function Attrs: inlinehint nounwind willreturn memory(none) uwtable
declare hidden i32 @me2v(i64 noundef, i64 noundef) #1

attributes #0 = { nounwind willreturn memory(none) 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 = { inlinehint nounwind willreturn memory(none) 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 willreturn memory(none) }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
define dso_local i32 @pv2pages(i16 noundef zeroext %0) local_unnamed_addr #0 {
  %2 = zext i16 %0 to i32
  %3 = and i32 %2, 32769
  %.not = icmp eq i32 %3, 32769
  br i1 %.not, label %4, label %14

4:                                                ; preds = %1
  %5 = icmp eq i16 %0, -1
  br i1 %5, label %14, label %6

6:                                                ; preds = %4
  %7 = lshr i32 %2, 1
  %8 = and i32 %7, 2047
  %9 = zext nneg i32 %8 to i64
  %10 = lshr i32 %2, 12
  %11 = and i32 %10, 7
  %12 = zext nneg i32 %11 to i64
  %13 = tail call i32 @me2v(i64 noundef %9, i64 noundef %12) #2
  br label %14

14:                                               ; preds = %4, %1, %6
  %.0 = phi i32 [ %13, %6 ], [ %2, %1 ], [ 65536, %4 ]
  ret i32 %.0
}

; Function Attrs: inlinehint mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare hidden i32 @me2v(i64 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(none) 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 = { inlinehint mustprogress nofree nosync nounwind willreturn memory(none) 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 willreturn memory(none) }

!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)"}


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