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

; 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.6 }
%struct.anon.6 = 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 }
%struct.meta = type { [2 x i32], %union.anon.17, i16, i8, i8, %struct.geo, %union.anon.18, %struct.MDBX_canary, %union.anon.21, [2 x %union.mdbx_atomic_uint32_t], [2 x i32], %union.bin128, %union.bin128 }
%union.anon.17 = type { i64 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.9, %union.anon.10 }
%union.anon.9 = type { i32 }
%union.anon.10 = type { i32 }
%union.anon.18 = type { %struct.anon.19 }
%struct.anon.19 = type { %struct.tree, %struct.tree }
%struct.tree = type { i16, i16, i32, i32, i32, i32, i32, i64, i64, i64 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.21 = type { i64 }
%union.mdbx_atomic_uint32_t = type { i32 }
%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, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.0, %struct.anon.4, i8, ptr, ptr, ptr, %struct.anon.5, %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 }
%struct.anon = type { ptr, ptr, ptr, ptr }
%struct.anon.0 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.1, %union.anon.2 }
%struct.anon.1 = type { i16, i16, i16, i16 }
%union.anon.2 = type { i32 }
%struct.anon.4 = type { i64, i64, i64, i64, i64 }
%struct.anon.5 = type { i64 }
%struct.osal_ioring = type { i32, i32, i32, ptr, ptr, ptr }
%union.mdbx_atomic_uint64_t = type { i64 }
%struct.shared_lck = type { i64, i32, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, [2 x %union.mdbx_atomic_uint32_t], [16 x i8], %struct.pgops, [16 x i8], %union.pthread_mutex_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, i32, %struct.anon.24, %union.pthread_mutex_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, [16 x i8], [0 x %struct.reader_slot] }
%struct.pgops = type { %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %struct.anon.22 }
%struct.anon.22 = type { %struct.gc_prof_stat, %struct.gc_prof_stat, i32, i32, i32, i32, i32 }
%struct.gc_prof_stat = type { i64, i64, i32, i32, i32, i32, %struct.anon.23 }
%struct.anon.23 = type { i64, i64, i32 }
%struct.anon.24 = type { [4 x i32], [4 x i64] }
%struct.reader_slot = type { %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint64_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint32_t, %union.mdbx_atomic_uint64_t }

@globals = external global %struct.libmdbx_globals, align 8
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [40 x i8], align 1
@__func__.coherency_check_written = external hidden unnamed_addr constant [24 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
declare dso_local i32 @coherency_timeout(ptr noundef, i64 noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @coherency_check(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i1 noundef zeroext) #3

declare i64 @meta_txnid(ptr noundef) #2

; Function Attrs: noreturn
declare void @mdbx_assert_fail(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @check_table_flags(i32 noundef) #5

; Function Attrs: nounwind uwtable
define dso_local i32 @coherency_check_written(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #8
  %15 = load ptr, ptr %11, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %21

17:                                               ; preds = %5
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = icmp ne i64 %19, 0
  br label %21

21:                                               ; preds = %17, %5
  %22 = phi i1 [ false, %5 ], [ %20, %17 ]
  %23 = xor i1 %22, true
  %24 = zext i1 %23 to i8
  store i8 %24, ptr %12, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #8
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = call i64 @meta_txnid(ptr noundef %25)
  store i64 %26, ptr %13, align 8, !tbaa !9
  %27 = load i64, ptr %13, align 8, !tbaa !9
  %28 = icmp uge i64 %27, 1
  br i1 %28, label %29, label %33

29:                                               ; preds = %21
  %30 = load i64, ptr %13, align 8, !tbaa !9
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = icmp uge i64 %30, %31
  br label %33

33:                                               ; preds = %29, %21
  %34 = phi i1 [ false, %21 ], [ %32, %29 ]
  %35 = xor i1 %34, true
  %36 = xor i1 %35, true
  %37 = zext i1 %36 to i32
  %38 = sext i32 %37 to i64
  %39 = call i64 @llvm.expect.i64(i64 %38, i64 1)
  %40 = icmp ne i64 %39, 0
  br i1 %40, label %41, label %129

41:                                               ; preds = %33
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i64, ptr %13, align 8, !tbaa !9
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.meta, ptr %44, i32 0, i32 6
  %46 = getelementptr inbounds %struct.anon.19, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i8, ptr %12, align 1, !tbaa !11, !range !13, !noundef !14
  %49 = trunc i8 %48 to i1
  %50 = call zeroext i1 @coherency_check(ptr noundef %42, i64 noundef %43, ptr noundef %46, ptr noundef %47, i1 noundef zeroext %49)
  %51 = xor i1 %50, true
  %52 = xor i1 %51, true
  %53 = zext i1 %52 to i32
  %54 = sext i32 %53 to i64
  %55 = call i64 @llvm.expect.i64(i64 %54, i64 1)
  %56 = icmp ne i64 %55, 0
  br i1 %56, label %57, label %128

57:                                               ; preds = %41
  br label %58

58:                                               ; preds = %57
  %59 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !15
  %60 = zext i8 %59 to i32
  %61 = and i32 %60, 1
  %62 = icmp ne i32 %61, 0
  %63 = xor i1 %62, true
  %64 = xor i1 %63, true
  %65 = zext i1 %64 to i32
  %66 = sext i32 %65 to i64
  %67 = call i64 @llvm.expect.i64(i64 %66, i64 1)
  %68 = icmp ne i64 %67, 0
  br i1 %68, label %69, label %90

69:                                               ; preds = %58
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.meta, ptr %71, i32 0, i32 6
  %73 = getelementptr inbounds %struct.anon.19, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds %struct.tree, ptr %73, i32 0, i32 0
  %75 = load volatile i16, ptr %74, align 4, !tbaa !18
  %76 = zext i16 %75 to i32
  %77 = icmp eq i32 %76, 8
  %78 = xor i1 %77, true
  %79 = xor i1 %78, true
  %80 = xor i1 %79, true
  %81 = zext i1 %80 to i32
  %82 = sext i32 %81 to i64
  %83 = call i64 @llvm.expect.i64(i64 %82, i64 0)
  %84 = icmp ne i64 %83, 0
  br i1 %84, label %85, label %87

85:                                               ; preds = %70
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %86, ptr noundef @.str.8, ptr noundef @__func__.coherency_check_written, i32 noundef 152) #9
  unreachable

87:                                               ; preds = %70
  br label %88

88:                                               ; preds = %87
  br label %89

89:                                               ; preds = %88
  br label %90

90:                                               ; preds = %89, %58
  br label %91

91:                                               ; preds = %90
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92
  %94 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !15
  %95 = zext i8 %94 to i32
  %96 = and i32 %95, 1
  %97 = icmp ne i32 %96, 0
  %98 = xor i1 %97, true
  %99 = xor i1 %98, true
  %100 = zext i1 %99 to i32
  %101 = sext i32 %100 to i64
  %102 = call i64 @llvm.expect.i64(i64 %101, i64 1)
  %103 = icmp ne i64 %102, 0
  br i1 %103, label %104, label %125

104:                                              ; preds = %93
  br label %105

105:                                              ; preds = %104
  %106 = load ptr, ptr %9, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.meta, ptr %106, i32 0, i32 6
  %108 = getelementptr inbounds %struct.anon.19, ptr %107, i32 0, i32 1
  %109 = getelementptr inbounds %struct.tree, ptr %108, i32 0, i32 0
  %110 = load volatile i16, ptr %109, align 4, !tbaa !18
  %111 = zext i16 %110 to i32
  %112 = call zeroext i1 @check_table_flags(i32 noundef %111)
  %113 = xor i1 %112, true
  %114 = xor i1 %113, true
  %115 = xor i1 %114, true
  %116 = zext i1 %115 to i32
  %117 = sext i32 %116 to i64
  %118 = call i64 @llvm.expect.i64(i64 %117, i64 0)
  %119 = icmp ne i64 %118, 0
  br i1 %119, label %120, label %122

120:                                              ; preds = %105
  %121 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %121, ptr noundef @.str.9, ptr noundef @__func__.coherency_check_written, i32 noundef 153) #9
  unreachable

122:                                              ; preds = %105
  br label %123

123:                                              ; preds = %122
  br label %124

124:                                              ; preds = %123
  br label %125

125:                                              ; preds = %124, %93
  br label %126

126:                                              ; preds = %125
  br label %127

127:                                              ; preds = %126
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %191

128:                                              ; preds = %41
  br label %186

129:                                              ; preds = %33
  %130 = load i8, ptr %12, align 1, !tbaa !11, !range !13, !noundef !14
  %131 = trunc i8 %130 to i1
  br i1 %131, label %132, label %185

132:                                              ; preds = %129
  %133 = load ptr, ptr %7, align 8, !tbaa !5
  %134 = getelementptr inbounds %struct.MDBX_env, ptr %133, i32 0, i32 7
  %135 = load ptr, ptr %134, align 8, !tbaa !19
  %136 = getelementptr inbounds %struct.shared_lck, ptr %135, i32 0, i32 9
  %137 = getelementptr inbounds %struct.pgops, ptr %136, i32 0, i32 12
  %138 = load volatile i32, ptr %137, align 32, !tbaa !18
  %139 = icmp uge i32 %138, 2147483647
  br i1 %139, label %140, label %141

140:                                              ; preds = %132
  br label %149

141:                                              ; preds = %132
  %142 = load ptr, ptr %7, align 8, !tbaa !5
  %143 = getelementptr inbounds %struct.MDBX_env, ptr %142, i32 0, i32 7
  %144 = load ptr, ptr %143, align 8, !tbaa !19
  %145 = getelementptr inbounds %struct.shared_lck, ptr %144, i32 0, i32 9
  %146 = getelementptr inbounds %struct.pgops, ptr %145, i32 0, i32 12
  %147 = load volatile i32, ptr %146, align 32, !tbaa !18
  %148 = add i32 %147, 1
  br label %149

149:                                              ; preds = %141, %140
  %150 = phi i32 [ 2147483647, %140 ], [ %148, %141 ]
  %151 = load ptr, ptr %7, align 8, !tbaa !5
  %152 = getelementptr inbounds %struct.MDBX_env, ptr %151, i32 0, i32 7
  %153 = load ptr, ptr %152, align 8, !tbaa !19
  %154 = getelementptr inbounds %struct.shared_lck, ptr %153, i32 0, i32 9
  %155 = getelementptr inbounds %struct.pgops, ptr %154, i32 0, i32 12
  store volatile i32 %150, ptr %155, align 32, !tbaa !18
  br label %156

156:                                              ; preds = %149
  %157 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !29
  %158 = zext i8 %157 to i32
  %159 = icmp sle i32 2, %158
  %160 = xor i1 %159, true
  %161 = xor i1 %160, true
  %162 = zext i1 %161 to i32
  %163 = sext i32 %162 to i64
  %164 = call i64 @llvm.expect.i64(i64 %163, i64 0)
  %165 = icmp ne i64 %164, 0
  br i1 %165, label %166, label %182

166:                                              ; preds = %156
  %167 = load i64, ptr %13, align 8, !tbaa !9
  %168 = icmp ult i64 %167, 1
  %169 = zext i1 %168 to i64
  %170 = select i1 %168, ptr @.str.11, ptr @.str.12
  %171 = load i64, ptr %13, align 8, !tbaa !9
  %172 = load ptr, ptr %7, align 8, !tbaa !5
  %173 = load ptr, ptr %9, align 8, !tbaa !5
  %174 = ptrtoint ptr %173 to i64
  %175 = load ptr, ptr %7, align 8, !tbaa !5
  %176 = getelementptr inbounds %struct.MDBX_env, ptr %175, i32 0, i32 3
  %177 = getelementptr inbounds %struct.osal_mmap, ptr %176, i32 0, i32 0
  %178 = load ptr, ptr %177, align 8, !tbaa !18
  %179 = ptrtoint ptr %178 to i64
  %180 = sub nsw i64 %174, %179
  %181 = call i32 @bytes2pgno(ptr noundef %172, i64 noundef %180) #10
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef @__func__.coherency_check_written, i32 noundef 162, ptr noundef @.str.10, ptr noundef %170, i64 noundef %171, i32 noundef %181, ptr noundef @.str.1)
  br label %182

182:                                              ; preds = %166, %156
  br label %183

183:                                              ; preds = %182
  br label %184

184:                                              ; preds = %183
  br label %185

185:                                              ; preds = %184, %129
  br label %186

186:                                              ; preds = %185, %128
  %187 = load ptr, ptr %11, align 8, !tbaa !5
  %188 = load i64, ptr %10, align 8, !tbaa !9
  %189 = load ptr, ptr %7, align 8, !tbaa !5
  %190 = call i32 @coherency_timeout(ptr noundef %187, i64 noundef %188, ptr noundef %189) #11
  store i32 %190, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %191

191:                                              ; preds = %186, %127
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #8
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #8
  %192 = load i32, ptr %6, align 4
  ret i32 %192
}

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 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 = { noreturn "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 = { 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 #6 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #7 = { 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 #8 = { nounwind }
attributes #9 = { noreturn }
attributes #10 = { nounwind willreturn memory(read) }
attributes #11 = { cold }

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


; 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.6 }
%struct.anon.6 = 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
@.str.1 = external hidden unnamed_addr constant [62 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [40 x i8], align 1
@__func__.coherency_check_written = external hidden unnamed_addr constant [24 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [42 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [11 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
declare dso_local i32 @coherency_timeout(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @coherency_check(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #2

declare i64 @meta_txnid(ptr noundef) local_unnamed_addr #1

; Function Attrs: noreturn
declare void @mdbx_assert_fail(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @check_table_flags(i32 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local i32 @coherency_check_written(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %9, label %6

6:                                                ; preds = %5
  %7 = load i64, ptr %4, align 8, !tbaa !5
  %8 = icmp eq i64 %7, 0
  br label %9

9:                                                ; preds = %6, %5
  %10 = phi i1 [ true, %5 ], [ %8, %6 ]
  %11 = tail call i64 @meta_txnid(ptr noundef %2) #6
  %12 = icmp ne i64 %11, 0
  %13 = icmp uge i64 %11, %1
  %14 = and i1 %12, %13
  br i1 %14, label %15, label %30, !prof !9

15:                                               ; preds = %9
  %16 = getelementptr inbounds i8, ptr %2, i64 40
  %17 = tail call zeroext i1 @coherency_check(ptr noundef %0, i64 noundef %11, ptr noundef nonnull %16, ptr noundef %2, i1 noundef zeroext %10)
  br i1 %17, label %18, label %53, !prof !9

18:                                               ; preds = %15
  %19 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !10
  %20 = and i8 %19, 1
  %.not29 = icmp eq i8 %20, 0
  br i1 %.not29, label %.thread, label %21, !prof !15

21:                                               ; preds = %18
  %22 = load volatile i16, ptr %16, align 4, !tbaa !16
  %.not30 = icmp eq i16 %22, 8
  br i1 %.not30, label %24, label %23, !prof !9

23:                                               ; preds = %21
  tail call void @mdbx_assert_fail(ptr noundef %0, ptr noundef nonnull @.str.8, ptr noundef nonnull @__func__.coherency_check_written, i32 noundef 152) #7
  unreachable

24:                                               ; preds = %21
  %25 = getelementptr inbounds i8, ptr %2, i64 88
  %26 = load volatile i16, ptr %25, align 4, !tbaa !16
  %27 = zext i16 %26 to i32
  %28 = tail call zeroext i1 @check_table_flags(i32 noundef %27)
  br i1 %28, label %.thread, label %29, !prof !9

29:                                               ; preds = %24
  tail call void @mdbx_assert_fail(ptr noundef %0, ptr noundef nonnull @.str.9, ptr noundef nonnull @__func__.coherency_check_written, i32 noundef 153) #7
  unreachable

30:                                               ; preds = %9
  br i1 %10, label %31, label %53

31:                                               ; preds = %30
  %32 = getelementptr inbounds i8, ptr %0, i64 104
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = getelementptr inbounds i8, ptr %33, i64 160
  %35 = load volatile i32, ptr %34, align 32, !tbaa !16
  %36 = icmp ugt i32 %35, 2147483646
  br i1 %36, label %40, label %37

37:                                               ; preds = %31
  %38 = load volatile i32, ptr %34, align 32, !tbaa !16
  %39 = add i32 %38, 1
  br label %40

40:                                               ; preds = %31, %37
  %41 = phi i32 [ %39, %37 ], [ 2147483647, %31 ]
  store volatile i32 %41, ptr %34, align 32, !tbaa !16
  %42 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !27
  %43 = icmp ugt i8 %42, 1
  br i1 %43, label %44, label %53, !prof !15

44:                                               ; preds = %40
  %45 = icmp eq i64 %11, 0
  %46 = select i1 %45, ptr @.str.11, ptr @.str.12
  %47 = ptrtoint ptr %2 to i64
  %48 = getelementptr inbounds i8, ptr %0, i64 16
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = ptrtoint ptr %49 to i64
  %51 = sub nsw i64 %47, %50
  %52 = tail call i32 @bytes2pgno(ptr noundef nonnull %0, i64 noundef %51) #8
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 2, ptr noundef nonnull @__func__.coherency_check_written, i32 noundef 162, ptr noundef nonnull @.str.10, ptr noundef nonnull %46, i64 noundef %11, i32 noundef %52, ptr noundef nonnull @.str.1) #6
  br label %53

53:                                               ; preds = %30, %44, %40, %15
  %54 = tail call i32 @coherency_timeout(ptr noundef %4, i64 noundef %3, ptr noundef %0) #9
  br label %.thread

.thread:                                          ; preds = %18, %24, %53
  %.0 = phi i32 [ %54, %53 ], [ 0, %24 ], [ 0, %18 ]
  ret i32 %.0
}

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

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 = { "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 = { noreturn "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 = { 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { cold }

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


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