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

%struct.libmdbx_globals = type { %union.bin128, i32, i32, i8, i8, i8, i8, i32, %union.logger_union, %union.pthread_mutex_t, i64, ptr }
%union.bin128 = type { %struct.anon }
%struct.anon = type { i64, i64 }
%union.logger_union = type { ptr }
%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 }

@globals = external global %struct.libmdbx_globals, align 8
@__func__.pv2pages_verify = external hidden unnamed_addr constant [16 x i8], align 1
@.str = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind willreturn memory(none) uwtable
declare dso_local i32 @pv2pages(i16 noundef zeroext) #0

; Function Attrs: nounwind willreturn memory(none) uwtable
declare dso_local zeroext i16 @pages2pv(i64 noundef) #0

; Function Attrs: cold nounwind optsize uwtable
define dso_local zeroext i1 @pv2pages_verify() #1 {
  %1 = alloca i8, align 1
  %2 = alloca i8, align 1
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #5
  store i8 1, ptr %1, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #5
  store i8 0, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 0, ptr %3, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %80, %0
  %8 = load i64, ptr %3, align 8, !tbaa !9
  %9 = icmp ult i64 %8, 65536
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %83

11:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %12 = load i64, ptr %3, align 8, !tbaa !9
  %13 = trunc i64 %12 to i16
  %14 = call i32 @pv2pages(i16 noundef zeroext %13) #6
  %15 = zext i32 %14 to i64
  store i64 %15, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %16 = load i64, ptr %4, align 8, !tbaa !9
  %17 = call zeroext i16 @pages2pv(i64 noundef %16) #6
  %18 = zext i16 %17 to i64
  store i64 %18, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = trunc i64 %19 to i16
  %21 = call i32 @pv2pages(i16 noundef zeroext %20) #6
  %22 = zext i32 %21 to i64
  store i64 %22, ptr %6, align 8, !tbaa !9
  %23 = load i64, ptr %4, align 8, !tbaa !9
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = icmp ne i64 %23, %24
  br i1 %25, label %26, label %45

26:                                               ; preds = %11
  br label %27

27:                                               ; preds = %26
  %28 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !11
  %29 = zext i8 %28 to i32
  %30 = icmp sle i32 1, %29
  %31 = xor i1 %30, true
  %32 = xor i1 %31, true
  %33 = zext i1 %32 to i32
  %34 = sext i32 %33 to i64
  %35 = call i64 @llvm.expect.i64(i64 %34, i64 0)
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %42

37:                                               ; preds = %27
  %38 = load i64, ptr %3, align 8, !tbaa !9
  %39 = load i64, ptr %4, align 8, !tbaa !9
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = load i64, ptr %6, align 8, !tbaa !9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.pv2pages_verify, i32 noundef 66, ptr noundef @.str, i64 noundef %38, i64 noundef %39, i64 noundef %40, i64 noundef %41)
  br label %42

42:                                               ; preds = %37, %27
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  store i8 0, ptr %1, align 1, !tbaa !5
  br label %79

45:                                               ; preds = %11
  %46 = load i8, ptr %2, align 1, !tbaa !5, !range !15, !noundef !16
  %47 = trunc i8 %46 to i1
  br i1 %47, label %48, label %78

48:                                               ; preds = %45
  %49 = load i64, ptr %5, align 8, !tbaa !9
  %50 = load i64, ptr %3, align 8, !tbaa !9
  %51 = icmp eq i64 %49, %50
  br i1 %51, label %78, label %52

52:                                               ; preds = %48
  %53 = load i64, ptr %5, align 8, !tbaa !9
  %54 = urem i64 %53, 2
  %55 = icmp eq i64 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %52
  %57 = load i64, ptr %5, align 8, !tbaa !9
  %58 = icmp ult i64 %57, 65536
  br i1 %58, label %78, label %59

59:                                               ; preds = %56, %52
  br label %60

60:                                               ; preds = %59
  %61 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !11
  %62 = zext i8 %61 to i32
  %63 = icmp sle i32 5, %62
  %64 = xor i1 %63, true
  %65 = xor i1 %64, true
  %66 = zext i1 %65 to i32
  %67 = sext i32 %66 to i64
  %68 = call i64 @llvm.expect.i64(i64 %67, i64 0)
  %69 = icmp ne i64 %68, 0
  br i1 %69, label %70, label %75

70:                                               ; preds = %60
  %71 = load i64, ptr %3, align 8, !tbaa !9
  %72 = load i64, ptr %4, align 8, !tbaa !9
  %73 = load i64, ptr %5, align 8, !tbaa !9
  %74 = load i64, ptr %6, align 8, !tbaa !9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef @__func__.pv2pages_verify, i32 noundef 69, ptr noundef @.str, i64 noundef %71, i64 noundef %72, i64 noundef %73, i64 noundef %74)
  br label %75

75:                                               ; preds = %70, %60
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  br label %78

78:                                               ; preds = %77, %56, %48, %45
  br label %79

79:                                               ; preds = %78, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br label %80

80:                                               ; preds = %79
  %81 = load i64, ptr %3, align 8, !tbaa !9
  %82 = add i64 %81, 1
  store i64 %82, ptr %3, align 8, !tbaa !9
  br label %7, !llvm.loop !17

83:                                               ; preds = %10
  %84 = load i8, ptr %1, align 1, !tbaa !5, !range !15, !noundef !16
  %85 = trunc i8 %84 to i1
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #5
  ret i1 %85
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #3

declare void @debug_log(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #4

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

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 = { cold nounwind optsize 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #4 = { "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 = { 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !7, i64 26}
!12 = !{!"libmdbx_globals", !7, i64 0, !13, i64 16, !13, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !6, i64 27, !13, i64 28, !7, i64 32, !7, i64 40, !10, i64 80, !14, i64 88}
!13 = !{!"int", !7, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!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"

%struct.libmdbx_globals = type { %union.bin128, i32, i32, i8, i8, i8, i8, i32, %union.logger_union, %union.pthread_mutex_t, i64, ptr }
%union.bin128 = type { %struct.anon }
%struct.anon = type { i64, i64 }
%union.logger_union = type { ptr }
%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 }

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@__func__.pv2pages_verify = external hidden unnamed_addr constant [16 x i8], align 1
@.str = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare dso_local i32 @pv2pages(i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare dso_local zeroext i16 @pages2pv(i64 noundef) local_unnamed_addr #0

; Function Attrs: cold nounwind optsize uwtable
define dso_local zeroext i1 @pv2pages_verify() local_unnamed_addr #1 {
  br label %2

1:                                                ; preds = %13
  ret i1 %.1

2:                                                ; preds = %0, %13
  %.030 = phi i1 [ true, %0 ], [ %.1, %13 ]
  %.02229 = phi i64 [ 0, %0 ], [ %14, %13 ]
  %3 = trunc nuw i64 %.02229 to i16
  %4 = tail call i32 @pv2pages(i16 noundef zeroext %3) #3
  %5 = zext i32 %4 to i64
  %6 = tail call zeroext i16 @pages2pv(i64 noundef %5) #3
  %7 = zext i16 %6 to i64
  %8 = tail call i32 @pv2pages(i16 noundef zeroext %6) #3
  %9 = zext i32 %8 to i64
  %.not = icmp eq i32 %4, %8
  br i1 %.not, label %13, label %10

10:                                               ; preds = %2
  %11 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !5
  %.not28 = icmp eq i8 %11, 0
  br i1 %.not28, label %13, label %12, !prof !13

12:                                               ; preds = %10
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.pv2pages_verify, i32 noundef 66, ptr noundef nonnull @.str, i64 noundef %.02229, i64 noundef %5, i64 noundef %7, i64 noundef %9) #4
  br label %13

13:                                               ; preds = %2, %10, %12
  %.1 = phi i1 [ false, %12 ], [ false, %10 ], [ %.030, %2 ]
  %14 = add nuw nsw i64 %.02229, 1
  %exitcond.not = icmp eq i64 %14, 65536
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !14
}

declare void @debug_log(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #2

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 = { cold nounwind optsize 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 = { "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 willreturn memory(none) }
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, !7, i64 26}
!6 = !{!"libmdbx_globals", !7, i64 0, !9, i64 16, !9, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !10, i64 27, !9, i64 28, !7, i64 32, !7, i64 40, !11, i64 80, !12, i64 88}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass