; 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_ptr = type { i64, %union.anon.8, i64 }
%union.anon.8 = type { ptr }
%struct.MDBX_txn = type { i32, i32, i64, i64, ptr, ptr, %struct.geo, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, %struct.MDBX_canary, ptr, %union.anon.11 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.9, %union.anon.10 }
%union.anon.9 = type { i32 }
%union.anon.10 = type { i32 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.11 = type { %struct.anon.13 }
%struct.anon.13 = type { %struct.troika, ptr, %struct.anon.14, i8, i32, i32, i64, ptr, ptr, ptr, i64, %union.anon.15 }
%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.anon.14 = type { %struct.MDBX_rkl, i64, %struct.MDBX_rkl }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }
%union.anon.15 = type { %struct.anon.16 }
%struct.anon.16 = type { i64, 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 }
%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 }
%union.anon.21 = type { i64 }
%union.mdbx_atomic_uint32_t = type { i32 }

@globals = external global %struct.libmdbx_globals, align 8
@__func__.coherency_fetch_head = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [37 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [37 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: hot nounwind uwtable
define dso_local i32 @coherency_fetch_head(ptr noundef %0, ptr noundef byval(%struct.meta_ptr) align 8 %1, ptr noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.meta_ptr, ptr %1, i32 0, i32 0
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.MDBX_txn, ptr %9, i32 0, i32 7
  store i64 %8, ptr %10, align 8, !tbaa !12
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.MDBX_txn, ptr %11, i32 0, i32 6
  %13 = getelementptr inbounds %struct.meta_ptr, ptr %1, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !18
  %15 = getelementptr inbounds %struct.meta, ptr %14, i32 0, i32 5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 4 %15, i64 20, i1 false), !tbaa.struct !19
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.MDBX_txn, ptr %16, i32 0, i32 10
  %18 = load ptr, ptr %17, align 8, !tbaa !22
  %19 = getelementptr inbounds %struct.meta_ptr, ptr %1, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !18
  %21 = getelementptr inbounds %struct.meta, ptr %20, i32 0, i32 6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %21, i64 96, i1 false)
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.MDBX_txn, ptr %22, i32 0, i32 15
  %24 = getelementptr inbounds %struct.meta_ptr, ptr %1, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !18
  %26 = getelementptr inbounds %struct.meta, ptr %25, i32 0, i32 7
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %23, ptr align 4 %26, i64 32, i1 false), !tbaa.struct !23
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.MDBX_txn, ptr %27, i32 0, i32 9
  %29 = load ptr, ptr %28, align 8, !tbaa !25
  %30 = getelementptr inbounds %struct.meta_ptr, ptr %1, i32 0, i32 0
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.MDBX_txn, ptr %32, i32 0, i32 10
  %34 = load ptr, ptr %33, align 8, !tbaa !22
  %35 = getelementptr inbounds %struct.meta_ptr, ptr %1, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !18
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i64, ptr %37, align 8, !tbaa !24
  %39 = icmp eq i64 %38, 0
  %40 = call zeroext i1 @coherency_check(ptr noundef %29, i64 noundef %31, ptr noundef %34, ptr noundef %36, i1 noundef zeroext %39)
  br i1 %40, label %41, label %49

41:                                               ; preds = %3
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.MDBX_txn, ptr %42, i32 0, i32 7
  %44 = load i64, ptr %43, align 8, !tbaa !12
  %45 = getelementptr inbounds %struct.meta_ptr, ptr %1, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = call i64 @meta_txnid(ptr noundef %46)
  %48 = icmp ne i64 %44, %47
  br label %49

49:                                               ; preds = %41, %3
  %50 = phi i1 [ true, %3 ], [ %48, %41 ]
  %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 0)
  %56 = icmp ne i64 %55, 0
  br i1 %56, label %57, label %63

57:                                               ; preds = %49
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.MDBX_txn, ptr %59, i32 0, i32 9
  %61 = load ptr, ptr %60, align 8, !tbaa !25
  %62 = call i32 @coherency_timeout(ptr noundef %58, i64 noundef -1, ptr noundef %61) #9
  store i32 %62, ptr %4, align 4
  br label %198

63:                                               ; preds = %49
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.MDBX_txn, ptr %64, i32 0, i32 10
  %66 = load ptr, ptr %65, align 8, !tbaa !22
  %67 = getelementptr inbounds %struct.tree, ptr %66, i64 0
  %68 = getelementptr inbounds %struct.tree, ptr %67, i32 0, i32 0
  %69 = load i16, ptr %68, align 4, !tbaa !26
  %70 = zext i16 %69 to i32
  %71 = icmp ne i32 %70, 8
  %72 = xor i1 %71, true
  %73 = xor i1 %72, true
  %74 = zext i1 %73 to i32
  %75 = sext i32 %74 to i64
  %76 = call i64 @llvm.expect.i64(i64 %75, i64 0)
  %77 = icmp ne i64 %76, 0
  br i1 %77, label %78, label %125

78:                                               ; preds = %63
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.MDBX_txn, ptr %79, i32 0, i32 10
  %81 = load ptr, ptr %80, align 8, !tbaa !22
  %82 = getelementptr inbounds %struct.tree, ptr %81, i64 0
  %83 = getelementptr inbounds %struct.tree, ptr %82, i32 0, i32 0
  %84 = load i16, ptr %83, align 4, !tbaa !26
  %85 = zext i16 %84 to i32
  %86 = and i32 %85, 126
  %87 = icmp ne i32 %86, 8
  br i1 %87, label %94, label %88

88:                                               ; preds = %78
  %89 = getelementptr inbounds %struct.meta_ptr, ptr %1, i32 0, i32 1
  %90 = load ptr, ptr %89, align 8, !tbaa !18
  %91 = getelementptr inbounds %struct.meta, ptr %90, i32 0, i32 0
  %92 = call i64 @unaligned_peek_u64(i64 noundef 4, ptr noundef %91) #10
  %93 = icmp eq i64 %92, 6441728281112482051
  br i1 %93, label %94, label %115

94:                                               ; preds = %88, %78
  br label %95

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

105:                                              ; preds = %95
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.MDBX_txn, ptr %106, i32 0, i32 10
  %108 = load ptr, ptr %107, align 8, !tbaa !22
  %109 = getelementptr inbounds %struct.tree, ptr %108, i64 0
  %110 = getelementptr inbounds %struct.tree, ptr %109, i32 0, i32 0
  %111 = load i16, ptr %110, align 4, !tbaa !26
  %112 = zext i16 %111 to i32
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.coherency_fetch_head, i32 noundef 136, ptr noundef @.str.4, i32 noundef %112, ptr noundef @.str.5)
  br label %113

113:                                              ; preds = %105, %95
  br label %114

114:                                              ; preds = %113
  store i32 -30784, ptr %4, align 4
  br label %198

115:                                              ; preds = %88
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.MDBX_txn, ptr %116, i32 0, i32 10
  %118 = load ptr, ptr %117, align 8, !tbaa !22
  %119 = getelementptr inbounds %struct.tree, ptr %118, i64 0
  %120 = getelementptr inbounds %struct.tree, ptr %119, i32 0, i32 0
  %121 = load i16, ptr %120, align 4, !tbaa !26
  %122 = zext i16 %121 to i32
  %123 = and i32 %122, 126
  %124 = trunc i32 %123 to i16
  store i16 %124, ptr %120, align 4, !tbaa !26
  br label %125

125:                                              ; preds = %115, %63
  br label %126

126:                                              ; preds = %125
  %127 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !31
  %128 = zext i8 %127 to i32
  %129 = and i32 %128, 1
  %130 = icmp ne i32 %129, 0
  %131 = xor i1 %130, true
  %132 = xor i1 %131, true
  %133 = zext i1 %132 to i32
  %134 = sext i32 %133 to i64
  %135 = call i64 @llvm.expect.i64(i64 %134, i64 1)
  %136 = icmp ne i64 %135, 0
  br i1 %136, label %137, label %160

137:                                              ; preds = %126
  br label %138

138:                                              ; preds = %137
  %139 = load ptr, ptr %5, align 8, !tbaa !5
  %140 = getelementptr inbounds %struct.MDBX_txn, ptr %139, i32 0, i32 10
  %141 = load ptr, ptr %140, align 8, !tbaa !22
  %142 = getelementptr inbounds %struct.tree, ptr %141, i64 0
  %143 = getelementptr inbounds %struct.tree, ptr %142, i32 0, i32 0
  %144 = load i16, ptr %143, align 4, !tbaa !26
  %145 = zext i16 %144 to i32
  %146 = icmp eq i32 %145, 8
  %147 = xor i1 %146, true
  %148 = xor i1 %147, true
  %149 = xor i1 %148, true
  %150 = zext i1 %149 to i32
  %151 = sext i32 %150 to i64
  %152 = call i64 @llvm.expect.i64(i64 %151, i64 0)
  %153 = icmp ne i64 %152, 0
  br i1 %153, label %154, label %158

154:                                              ; preds = %138
  %155 = load ptr, ptr %5, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.MDBX_txn, ptr %155, i32 0, i32 9
  %157 = load ptr, ptr %156, align 8, !tbaa !25
  call void @mdbx_assert_fail(ptr noundef %157, ptr noundef @.str.6, ptr noundef @__func__.coherency_fetch_head, i32 noundef 141) #11
  unreachable

158:                                              ; preds = %138
  br label %159

159:                                              ; preds = %158
  br label %160

160:                                              ; preds = %159, %126
  br label %161

161:                                              ; preds = %160
  br label %162

162:                                              ; preds = %161
  %163 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !31
  %164 = zext i8 %163 to i32
  %165 = and i32 %164, 1
  %166 = icmp ne i32 %165, 0
  %167 = xor i1 %166, true
  %168 = xor i1 %167, true
  %169 = zext i1 %168 to i32
  %170 = sext i32 %169 to i64
  %171 = call i64 @llvm.expect.i64(i64 %170, i64 1)
  %172 = icmp ne i64 %171, 0
  br i1 %172, label %173, label %196

173:                                              ; preds = %162
  br label %174

174:                                              ; preds = %173
  %175 = load ptr, ptr %5, align 8, !tbaa !5
  %176 = getelementptr inbounds %struct.MDBX_txn, ptr %175, i32 0, i32 10
  %177 = load ptr, ptr %176, align 8, !tbaa !22
  %178 = getelementptr inbounds %struct.tree, ptr %177, i64 1
  %179 = getelementptr inbounds %struct.tree, ptr %178, i32 0, i32 0
  %180 = load i16, ptr %179, align 4, !tbaa !26
  %181 = zext i16 %180 to i32
  %182 = call zeroext i1 @check_table_flags(i32 noundef %181)
  %183 = xor i1 %182, true
  %184 = xor i1 %183, true
  %185 = xor i1 %184, true
  %186 = zext i1 %185 to i32
  %187 = sext i32 %186 to i64
  %188 = call i64 @llvm.expect.i64(i64 %187, i64 0)
  %189 = icmp ne i64 %188, 0
  br i1 %189, label %190, label %194

190:                                              ; preds = %174
  %191 = load ptr, ptr %5, align 8, !tbaa !5
  %192 = getelementptr inbounds %struct.MDBX_txn, ptr %191, i32 0, i32 9
  %193 = load ptr, ptr %192, align 8, !tbaa !25
  call void @mdbx_assert_fail(ptr noundef %193, ptr noundef @.str.7, ptr noundef @__func__.coherency_fetch_head, i32 noundef 142) #11
  unreachable

194:                                              ; preds = %174
  br label %195

195:                                              ; preds = %194
  br label %196

196:                                              ; preds = %195, %162
  br label %197

197:                                              ; preds = %196
  store i32 0, ptr %4, align 4
  br label %198

198:                                              ; preds = %197, %114, %57
  %199 = load i32, ptr %4, align 4
  ret i32 %199
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

declare i64 @meta_txnid(ptr noundef) #2

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden i64 @unaligned_peek_u64(i64 noundef, ptr noalias noundef) #6

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

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

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

!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 0}
!10 = !{!"meta_ptr", !11, i64 0, !7, i64 8, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !11, i64 64}
!13 = !{!"MDBX_txn", !14, i64 0, !14, i64 4, !11, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !15, i64 40, !11, i64 64, !11, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !17, i64 128, !6, i64 160, !7, i64 168}
!14 = !{!"int", !7, i64 0}
!15 = !{!"geo", !16, i64 0, !16, i64 2, !14, i64 4, !14, i64 8, !7, i64 12, !7, i64 16}
!16 = !{!"short", !7, i64 0}
!17 = !{!"MDBX_canary", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!18 = !{!7, !7, i64 0}
!19 = !{i64 0, i64 2, !20, i64 2, i64 2, !20, i64 4, i64 4, !21, i64 8, i64 4, !21, i64 12, i64 4, !18, i64 16, i64 4, !18}
!20 = !{!16, !16, i64 0}
!21 = !{!14, !14, i64 0}
!22 = !{!13, !6, i64 88}
!23 = !{i64 0, i64 8, !24, i64 8, i64 8, !24, i64 16, i64 8, !24, i64 24, i64 8, !24}
!24 = !{!11, !11, i64 0}
!25 = !{!13, !6, i64 80}
!26 = !{!27, !16, i64 0}
!27 = !{!"tree", !16, i64 0, !16, i64 2, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20, !11, i64 24, !11, i64 32, !11, i64 40}
!28 = !{!29, !7, i64 26}
!29 = !{!"libmdbx_globals", !7, i64 0, !14, i64 16, !14, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !30, i64 27, !14, i64 28, !7, i64 32, !7, i64 40, !11, i64 80, !6, i64 88}
!30 = !{!"_Bool", !7, i64 0}
!31 = !{!29, !7, i64 25}


; 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 }
%struct.meta_ptr = type { i64, %union.anon.8, i64 }
%union.anon.8 = type { ptr }

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@__func__.coherency_fetch_head = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [37 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: hot nounwind uwtable
define dso_local i32 @coherency_fetch_head(ptr nocapture noundef %0, ptr nocapture noundef readonly byval(%struct.meta_ptr) align 8 %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  store i64 %4, ptr %5, align 8, !tbaa !10
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !17
  %9 = getelementptr inbounds i8, ptr %8, i64 20
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %6, ptr noundef nonnull align 4 dereferenceable(20) %9, i64 20, i1 false), !tbaa.struct !18
  %10 = getelementptr inbounds i8, ptr %0, i64 88
  %11 = load ptr, ptr %10, align 8, !tbaa !21
  %12 = getelementptr inbounds i8, ptr %8, i64 40
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(96) %11, ptr noundef nonnull align 4 dereferenceable(96) %12, i64 96, i1 false)
  %13 = getelementptr inbounds i8, ptr %0, i64 128
  %14 = getelementptr inbounds i8, ptr %8, i64 136
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %13, ptr noundef nonnull align 4 dereferenceable(32) %14, i64 32, i1 false), !tbaa.struct !22
  %15 = getelementptr inbounds i8, ptr %0, i64 80
  %16 = load ptr, ptr %15, align 8, !tbaa !24
  %17 = load ptr, ptr %10, align 8, !tbaa !21
  %18 = load i64, ptr %2, align 8, !tbaa !23
  %19 = icmp eq i64 %18, 0
  %20 = tail call zeroext i1 @coherency_check(ptr noundef %16, i64 noundef %4, ptr noundef %17, ptr noundef %8, i1 noundef zeroext %19)
  br i1 %20, label %21, label %.critedge, !prof !25

21:                                               ; preds = %3
  %22 = load i64, ptr %5, align 8, !tbaa !10
  %23 = tail call i64 @meta_txnid(ptr noundef nonnull %8) #8
  %.not25 = icmp eq i64 %22, %23
  br i1 %.not25, label %26, label %.critedge, !prof !25

.critedge:                                        ; preds = %3, %21
  %24 = load ptr, ptr %15, align 8, !tbaa !24
  %25 = tail call i32 @coherency_timeout(ptr noundef nonnull %2, i64 noundef -1, ptr noundef %24) #9
  br label %.thread

26:                                               ; preds = %21
  %27 = load ptr, ptr %10, align 8, !tbaa !21
  %28 = load i16, ptr %27, align 4, !tbaa !26
  %.not = icmp eq i16 %28, 8
  br i1 %.not, label %39, label %29, !prof !25

29:                                               ; preds = %26
  %30 = and i16 %28, 126
  %.not20 = icmp eq i16 %30, 8
  br i1 %.not20, label %31, label %34

31:                                               ; preds = %29
  %32 = tail call i64 @unaligned_peek_u64(i64 noundef 4, ptr noundef nonnull %8) #10
  %33 = icmp eq i64 %32, 6441728281112482051
  br i1 %33, label %34, label %38

34:                                               ; preds = %29, %31
  %35 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !28
  %.not24 = icmp eq i8 %35, 0
  br i1 %.not24, label %.thread, label %36, !prof !25

36:                                               ; preds = %34
  %37 = zext i16 %28 to i32
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.coherency_fetch_head, i32 noundef 136, ptr noundef nonnull @.str.4, i32 noundef %37, ptr noundef nonnull @.str.5) #8
  br label %.thread

38:                                               ; preds = %31
  store i16 8, ptr %27, align 4, !tbaa !26
  br label %39

39:                                               ; preds = %26, %38
  %40 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !31
  %41 = and i8 %40, 1
  %.not21 = icmp eq i8 %41, 0
  br i1 %.not21, label %.thread, label %42, !prof !32

42:                                               ; preds = %39
  %43 = getelementptr inbounds i8, ptr %27, i64 48
  %44 = load i16, ptr %43, align 4, !tbaa !26
  %45 = zext i16 %44 to i32
  %46 = tail call zeroext i1 @check_table_flags(i32 noundef %45)
  br i1 %46, label %.thread, label %47, !prof !25

47:                                               ; preds = %42
  %48 = load ptr, ptr %15, align 8, !tbaa !24
  tail call void @mdbx_assert_fail(ptr noundef %48, ptr noundef nonnull @.str.7, ptr noundef nonnull @__func__.coherency_fetch_head, i32 noundef 142) #11
  unreachable

.thread:                                          ; preds = %39, %42, %36, %34, %.critedge
  %.0 = phi i32 [ %25, %.critedge ], [ -30784, %34 ], [ -30784, %36 ], [ 0, %42 ], [ 0, %39 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

declare i64 @meta_txnid(ptr noundef) local_unnamed_addr #1

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

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

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

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 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #7 = { 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 #8 = { nounwind }
attributes #9 = { cold }
attributes #10 = { nounwind willreturn memory(read) }
attributes #11 = { noreturn 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 0}
!6 = !{!"meta_ptr", !7, i64 0, !8, i64 8, !7, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 64}
!11 = !{!"MDBX_txn", !12, i64 0, !12, i64 4, !7, i64 8, !7, i64 16, !13, i64 24, !13, i64 32, !14, i64 40, !7, i64 64, !7, i64 72, !13, i64 80, !13, i64 88, !13, i64 96, !13, i64 104, !13, i64 112, !13, i64 120, !16, i64 128, !13, i64 160, !8, i64 168}
!12 = !{!"int", !8, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"geo", !15, i64 0, !15, i64 2, !12, i64 4, !12, i64 8, !8, i64 12, !8, i64 16}
!15 = !{!"short", !8, i64 0}
!16 = !{!"MDBX_canary", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!17 = !{!8, !8, i64 0}
!18 = !{i64 0, i64 2, !19, i64 2, i64 2, !19, i64 4, i64 4, !20, i64 8, i64 4, !20, i64 12, i64 4, !17, i64 16, i64 4, !17}
!19 = !{!15, !15, i64 0}
!20 = !{!12, !12, i64 0}
!21 = !{!11, !13, i64 88}
!22 = !{i64 0, i64 8, !23, i64 8, i64 8, !23, i64 16, i64 8, !23, i64 24, i64 8, !23}
!23 = !{!7, !7, i64 0}
!24 = !{!11, !13, i64 80}
!25 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!26 = !{!27, !15, i64 0}
!27 = !{!"tree", !15, i64 0, !15, i64 2, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !7, i64 24, !7, i64 32, !7, i64 40}
!28 = !{!29, !8, i64 26}
!29 = !{!"libmdbx_globals", !8, i64 0, !12, i64 16, !12, i64 20, !8, i64 24, !8, i64 25, !8, i64 26, !30, i64 27, !12, i64 28, !8, i64 32, !8, i64 40, !7, i64 80, !13, i64 88}
!30 = !{!"_Bool", !8, i64 0}
!31 = !{!29, !8, i64 25}
!32 = !{!"branch_weights", !"expected", i32 1, i32 2000}


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