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

; 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.MDBX_env = type { %union.mdbx_atomic_uint32_t, i32, i32, %struct.osal_mmap, i32, i32, %struct.osal_mmap, ptr, i16, i16, i16, i16, i16, i16, %union.mdbx_atomic_uint32_t, i8, i8, i16, i32, i32, i32, i32, %struct.anon.1, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.2, %struct.anon.6, i8, ptr, ptr, ptr, %struct.anon.7, %union.pthread_mutex_t, i32, i32, ptr, %struct.osal_ioring, %union.pthread_mutex_t, [71 x %union.mdbx_atomic_uint64_t] }
%struct.osal_mmap = type { %union.anon, i32, i64, i64, i64 }
%union.anon = type { ptr }
%union.mdbx_atomic_uint32_t = type { i32 }
%struct.anon.1 = type { ptr, ptr, ptr, ptr }
%struct.anon.2 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.3, %union.anon.4 }
%struct.anon.3 = type { i16, i16, i16, i16 }
%union.anon.4 = type { i32 }
%struct.anon.6 = type { i64, i64, i64, i64, i64 }
%struct.anon.7 = type { i64 }
%struct.osal_ioring = type { i32, i32, i32, ptr, ptr, 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 }
%union.mdbx_atomic_uint64_t = type { i64 }

; 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: cold nounwind optsize uwtable
declare hidden i32 @default_rp_augment_limit(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @env_options_adjust_dp_limit(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @env_options_adjust_defaults(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.MDBX_env, ptr %6, i32 0, i32 34
  %8 = getelementptr inbounds %struct.anon.2, ptr %7, i32 0, i32 15
  %9 = load i8, ptr %8, align 8
  %10 = lshr i8 %9, 1
  %11 = and i8 %10, 1
  %12 = zext i8 %11 to i32
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %20, label %14

14:                                               ; preds = %1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call i32 @default_rp_augment_limit(ptr noundef %15) #5
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.MDBX_env, ptr %17, i32 0, i32 34
  %19 = getelementptr inbounds %struct.anon.2, ptr %18, i32 0, i32 1
  store i32 %16, ptr %19, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %14, %1
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.MDBX_env, ptr %21, i32 0, i32 34
  %23 = getelementptr inbounds %struct.anon.2, ptr %22, i32 0, i32 15
  %24 = load i8, ptr %23, align 8
  %25 = lshr i8 %24, 2
  %26 = and i8 %25, 1
  %27 = zext i8 %26 to i32
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %36, label %29

29:                                               ; preds = %20
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = call zeroext i1 @default_prefault_write(ptr noundef %30)
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.MDBX_env, ptr %32, i32 0, i32 34
  %34 = getelementptr inbounds %struct.anon.2, ptr %33, i32 0, i32 11
  %35 = zext i1 %31 to i8
  store i8 %35, ptr %34, align 4, !tbaa !22
  br label %36

36:                                               ; preds = %29, %20
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.MDBX_env, ptr %37, i32 0, i32 34
  %39 = getelementptr inbounds %struct.anon.2, ptr %38, i32 0, i32 13
  store i8 1, ptr %39, align 2, !tbaa !23
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.MDBX_env, ptr %40, i32 0, i32 39
  %42 = load ptr, ptr %41, align 8, !tbaa !24
  %43 = icmp ne ptr %42, null
  br i1 %43, label %46, label %44

44:                                               ; preds = %36
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  call void @env_options_adjust_dp_limit(ptr noundef %45)
  br label %46

46:                                               ; preds = %44, %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.MDBX_env, ptr %47, i32 0, i32 35
  %49 = getelementptr inbounds %struct.anon.6, ptr %48, i32 0, i32 2
  %50 = load i64, ptr %49, align 8, !tbaa !25
  store i64 %50, ptr %3, align 8, !tbaa !26
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 9, ptr %4, align 4, !tbaa !27
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %51 = load i64, ptr %3, align 8, !tbaa !26
  %52 = icmp ult i64 %51, 33554432
  br i1 %52, label %53, label %54

53:                                               ; preds = %46
  br label %63

54:                                               ; preds = %46
  %55 = load i64, ptr %3, align 8, !tbaa !26
  %56 = icmp ugt i64 %55, 2147483648
  br i1 %56, label %57, label %58

57:                                               ; preds = %54
  br label %61

58:                                               ; preds = %54
  %59 = load i64, ptr %3, align 8, !tbaa !26
  %60 = lshr i64 %59, 9
  br label %61

61:                                               ; preds = %58, %57
  %62 = phi i64 [ 4194304, %57 ], [ %60, %58 ]
  br label %63

63:                                               ; preds = %61, %53
  %64 = phi i64 [ 65536, %53 ], [ %62, %61 ]
  store i64 %64, ptr %5, align 8, !tbaa !26
  %65 = load i64, ptr %5, align 8, !tbaa !26
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.MDBX_env, ptr %66, i32 0, i32 35
  %68 = getelementptr inbounds %struct.anon.6, ptr %67, i32 0, i32 4
  %69 = load i64, ptr %68, align 8, !tbaa !28
  %70 = icmp ult i64 %65, %69
  br i1 %70, label %77, label %71

71:                                               ; preds = %63
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.MDBX_env, ptr %72, i32 0, i32 35
  %74 = getelementptr inbounds %struct.anon.6, ptr %73, i32 0, i32 4
  %75 = load i64, ptr %74, align 8, !tbaa !28
  %76 = icmp ne i64 %75, 0
  br i1 %76, label %79, label %77

77:                                               ; preds = %71, %63
  %78 = load i64, ptr %5, align 8, !tbaa !26
  br label %84

79:                                               ; preds = %71
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.MDBX_env, ptr %80, i32 0, i32 35
  %82 = getelementptr inbounds %struct.anon.6, ptr %81, i32 0, i32 4
  %83 = load i64, ptr %82, align 8, !tbaa !28
  br label %84

84:                                               ; preds = %79, %77
  %85 = phi i64 [ %78, %77 ], [ %83, %79 ]
  store i64 %85, ptr %5, align 8, !tbaa !26
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = load ptr, ptr %2, align 8, !tbaa !5
  %88 = load i64, ptr %5, align 8, !tbaa !26
  %89 = call i64 @bytes_align2os_bytes(ptr noundef %87, i64 noundef %88) #7
  %90 = call i32 @bytes2pgno(ptr noundef %86, i64 noundef %89) #7
  %91 = zext i32 %90 to i64
  %92 = load ptr, ptr %2, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.MDBX_env, ptr %92, i32 0, i32 33
  store i64 %91, ptr %93, align 8, !tbaa !29
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @default_prefault_write(ptr noundef) #2

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden i32 @bytes2pgno(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @bytes_align2os_bytes(ptr noundef, i64 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { inlinehint nounwind willreturn memory(read) 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 = { nounwind willreturn memory(read) "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 = { cold }
attributes #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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, !11, i64 268}
!10 = !{!"MDBX_env", !7, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !11, i64 56, !11, i64 60, !12, i64 64, !6, i64 104, !14, i64 112, !14, i64 114, !14, i64 116, !14, i64 118, !14, i64 120, !14, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !14, i64 130, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !15, i64 152, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !11, i64 224, !11, i64 228, !11, i64 232, !6, i64 240, !6, i64 248, !13, i64 256, !16, i64 264, !19, i64 320, !17, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !20, i64 392, !7, i64 400, !11, i64 440, !11, i64 444, !6, i64 448, !21, i64 456, !7, i64 496, !7, i64 536}
!11 = !{!"int", !7, i64 0}
!12 = !{!"osal_mmap", !7, i64 0, !11, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !13, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !11, i64 28, !11, i64 32, !17, i64 36, !17, i64 37, !17, i64 38, !18, i64 40, !7, i64 48}
!17 = !{!"_Bool", !7, i64 0}
!18 = !{!"", !14, i64 0, !14, i64 2, !14, i64 4, !14, i64 6}
!19 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!20 = !{!"", !13, i64 0}
!21 = !{!"osal_ioring", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!22 = !{!10, !17, i64 300}
!23 = !{!10, !17, i64 302}
!24 = !{!10, !6, i64 384}
!25 = !{!10, !13, i64 336}
!26 = !{!13, !13, i64 0}
!27 = !{!11, !11, i64 0}
!28 = !{!10, !13, i64 352}
!29 = !{!10, !13, i64 256}


; 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: cold nounwind optsize uwtable
declare hidden i32 @default_rp_augment_limit(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @env_options_adjust_dp_limit(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @env_options_adjust_defaults(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 312
  %3 = load i8, ptr %2, align 8
  %4 = and i8 %3, 2
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %5, label %8

5:                                                ; preds = %1
  %6 = tail call i32 @default_rp_augment_limit(ptr noundef nonnull %0) #4
  %7 = getelementptr inbounds i8, ptr %0, i64 268
  store i32 %6, ptr %7, align 4, !tbaa !5
  %.pre = load i8, ptr %2, align 8
  br label %8

8:                                                ; preds = %5, %1
  %9 = phi i8 [ %.pre, %5 ], [ %3, %1 ]
  %10 = and i8 %9, 4
  %.not22 = icmp eq i8 %10, 0
  br i1 %.not22, label %11, label %15

11:                                               ; preds = %8
  %12 = tail call zeroext i1 @default_prefault_write(ptr noundef nonnull %0)
  %13 = getelementptr inbounds i8, ptr %0, i64 300
  %14 = zext i1 %12 to i8
  store i8 %14, ptr %13, align 4, !tbaa !21
  br label %15

15:                                               ; preds = %11, %8
  %16 = getelementptr inbounds i8, ptr %0, i64 302
  store i8 1, ptr %16, align 2, !tbaa !22
  %17 = getelementptr inbounds i8, ptr %0, i64 384
  %18 = load ptr, ptr %17, align 8, !tbaa !23
  %.not23 = icmp eq ptr %18, null
  br i1 %.not23, label %19, label %20

19:                                               ; preds = %15
  tail call void @env_options_adjust_dp_limit(ptr noundef nonnull %0)
  br label %20

20:                                               ; preds = %19, %15
  %21 = getelementptr inbounds i8, ptr %0, i64 336
  %22 = load i64, ptr %21, align 8, !tbaa !24
  %23 = icmp ult i64 %22, 33554432
  %24 = icmp ugt i64 %22, 2147483648
  %25 = lshr i64 %22, 9
  %26 = select i1 %24, i64 4194304, i64 %25
  %27 = select i1 %23, i64 65536, i64 %26
  %28 = getelementptr inbounds i8, ptr %0, i64 352
  %29 = load i64, ptr %28, align 8, !tbaa !25
  %30 = add i64 %29, -1
  %or.cond.not = icmp ult i64 %30, %27
  %31 = select i1 %or.cond.not, i64 %29, i64 %27
  %32 = tail call i64 @bytes_align2os_bytes(ptr noundef nonnull %0, i64 noundef %31) #5
  %33 = tail call i32 @bytes2pgno(ptr noundef nonnull %0, i64 noundef %32) #5
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %0, i64 256
  store i64 %34, ptr %35, align 8, !tbaa !26
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @default_prefault_write(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden i32 @bytes2pgno(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i64 @bytes_align2os_bytes(ptr noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { 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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 = { mustprogress nofree nounwind willreturn memory(read) "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 = { cold }
attributes #5 = { nounwind willreturn memory(read) }

!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, !9, i64 268}
!6 = !{!"MDBX_env", !7, i64 0, !9, i64 4, !9, i64 8, !10, i64 16, !9, i64 56, !9, i64 60, !10, i64 64, !12, i64 104, !13, i64 112, !13, i64 114, !13, i64 116, !13, i64 118, !13, i64 120, !13, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !13, i64 130, !9, i64 132, !9, i64 136, !9, i64 140, !9, i64 144, !14, i64 152, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208, !12, i64 216, !9, i64 224, !9, i64 228, !9, i64 232, !12, i64 240, !12, i64 248, !11, i64 256, !15, i64 264, !18, i64 320, !16, i64 360, !12, i64 368, !12, i64 376, !12, i64 384, !19, i64 392, !7, i64 400, !9, i64 440, !9, i64 444, !12, i64 448, !20, i64 456, !7, i64 496, !7, i64 536}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"osal_mmap", !7, i64 0, !9, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!15 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !11, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !9, i64 28, !9, i64 32, !16, i64 36, !16, i64 37, !16, i64 38, !17, i64 40, !7, i64 48}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6}
!18 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!19 = !{!"", !11, i64 0}
!20 = !{!"osal_ioring", !9, i64 0, !9, i64 4, !9, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!21 = !{!6, !16, i64 300}
!22 = !{!6, !16, i64 302}
!23 = !{!6, !12, i64 384}
!24 = !{!6, !11, i64 336}
!25 = !{!6, !11, i64 352}
!26 = !{!6, !11, i64 256}


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