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

; 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.9 }
%struct.anon.9 = 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.bind_reader_slot_result = type { i32, ptr }
%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 }
%union.mdbx_atomic_uint32_t = type { i32 }
%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.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
@__func__.mdbx_thread_register = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [34 x i8], align 1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_env(ptr noundef, i1 noundef zeroext) #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @log_if_error(i32 noundef, ptr noundef, i32 noundef) #1

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

; 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
define dso_local i32 @mdbx_thread_register(ptr noundef %0) #4 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca %struct.bind_reader_slot_result, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call i32 @check_env(ptr noundef %8, i1 noundef zeroext true)
  store i32 %9, ptr %4, align 4, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = icmp ne i32 %10, 0
  %12 = xor i1 %11, true
  %13 = xor i1 %12, true
  %14 = zext i1 %13 to i32
  %15 = sext i32 %14 to i64
  %16 = call i64 @llvm.expect.i64(i64 %15, i64 0)
  %17 = icmp ne i64 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %1
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = call i32 @log_if_error(i32 noundef %19, ptr noundef @__func__.mdbx_thread_register, i32 noundef 78)
  store i32 %20, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %232

21:                                               ; preds = %1
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.MDBX_env, ptr %22, i32 0, i32 6
  %24 = getelementptr inbounds %struct.osal_mmap, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = icmp ne ptr %25, null
  %27 = xor i1 %26, true
  %28 = xor i1 %27, true
  %29 = xor i1 %28, true
  %30 = zext i1 %29 to i32
  %31 = sext i32 %30 to i64
  %32 = call i64 @llvm.expect.i64(i64 %31, i64 0)
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %43

34:                                               ; preds = %21
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.MDBX_env, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !12
  %38 = and i32 %37, 4194304
  %39 = icmp ne i32 %38, 0
  %40 = zext i1 %39 to i64
  %41 = select i1 %39, i32 22, i32 1
  %42 = call i32 @log_if_error(i32 noundef %41, ptr noundef @__func__.mdbx_thread_register, i32 noundef 81)
  store i32 %42, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %232

43:                                               ; preds = %21
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.MDBX_env, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = and i32 %46, 268435456
  %48 = icmp eq i32 %47, 0
  %49 = xor i1 %48, true
  %50 = xor i1 %49, true
  %51 = zext i1 %50 to i32
  %52 = sext i32 %51 to i64
  %53 = call i64 @llvm.expect.i64(i64 %52, i64 0)
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %55, label %90

55:                                               ; preds = %43
  br label %56

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

67:                                               ; preds = %56
  br label %68

68:                                               ; preds = %67
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.MDBX_env, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 4, !tbaa !12
  %72 = and i32 %71, 2097152
  %73 = icmp ne i32 %72, 0
  %74 = xor i1 %73, true
  %75 = xor i1 %74, true
  %76 = xor i1 %75, true
  %77 = zext i1 %76 to i32
  %78 = sext i32 %77 to i64
  %79 = call i64 @llvm.expect.i64(i64 %78, i64 0)
  %80 = icmp ne i64 %79, 0
  br i1 %80, label %81, label %83

81:                                               ; preds = %68
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %82, ptr noundef @.str.1, ptr noundef @__func__.mdbx_thread_register, i32 noundef 84) #7
  unreachable

83:                                               ; preds = %68
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84
  br label %86

86:                                               ; preds = %85, %56
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  %89 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_thread_register, i32 noundef 85)
  store i32 %89, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %232

90:                                               ; preds = %43
  br label %91

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

102:                                              ; preds = %91
  br label %103

103:                                              ; preds = %102
  %104 = load ptr, ptr %3, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.MDBX_env, ptr %104, i32 0, i32 1
  %106 = load i32, ptr %105, align 4, !tbaa !12
  %107 = and i32 %106, 270532608
  %108 = icmp eq i32 %107, 268435456
  %109 = xor i1 %108, true
  %110 = xor i1 %109, true
  %111 = xor i1 %110, true
  %112 = zext i1 %111 to i32
  %113 = sext i32 %112 to i64
  %114 = call i64 @llvm.expect.i64(i64 %113, i64 0)
  %115 = icmp ne i64 %114, 0
  br i1 %115, label %116, label %118

116:                                              ; preds = %103
  %117 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %117, ptr noundef @.str.2, ptr noundef @__func__.mdbx_thread_register, i32 noundef 88) #7
  unreachable

118:                                              ; preds = %103
  br label %119

119:                                              ; preds = %118
  br label %120

120:                                              ; preds = %119
  br label %121

121:                                              ; preds = %120, %91
  br label %122

122:                                              ; preds = %121
  br label %123

123:                                              ; preds = %122
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %124 = load ptr, ptr %3, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.MDBX_env, ptr %124, i32 0, i32 21
  %126 = load i32, ptr %125, align 8, !tbaa !26
  %127 = call ptr @thread_rthc_get(i32 noundef %126)
  store ptr %127, ptr %6, align 8, !tbaa !5
  %128 = load ptr, ptr %6, align 8, !tbaa !5
  %129 = icmp ne ptr %128, null
  %130 = xor i1 %129, true
  %131 = xor i1 %130, true
  %132 = zext i1 %131 to i32
  %133 = sext i32 %132 to i64
  %134 = call i64 @llvm.expect.i64(i64 %133, i64 0)
  %135 = icmp ne i64 %134, 0
  br i1 %135, label %136, label %221

136:                                              ; preds = %123
  br label %137

137:                                              ; preds = %136
  %138 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !24
  %139 = zext i8 %138 to i32
  %140 = and i32 %139, 1
  %141 = icmp ne i32 %140, 0
  %142 = xor i1 %141, true
  %143 = xor i1 %142, true
  %144 = zext i1 %143 to i32
  %145 = sext i32 %144 to i64
  %146 = call i64 @llvm.expect.i64(i64 %145, i64 1)
  %147 = icmp ne i64 %146, 0
  br i1 %147, label %148, label %169

148:                                              ; preds = %137
  br label %149

149:                                              ; preds = %148
  %150 = load ptr, ptr %6, align 8, !tbaa !5
  %151 = getelementptr inbounds %struct.reader_slot, ptr %150, i32 0, i32 2
  %152 = load volatile i32, ptr %151, align 8, !tbaa !11
  %153 = load ptr, ptr %3, align 8, !tbaa !5
  %154 = getelementptr inbounds %struct.MDBX_env, ptr %153, i32 0, i32 20
  %155 = load i32, ptr %154, align 4, !tbaa !27
  %156 = icmp eq i32 %152, %155
  %157 = xor i1 %156, true
  %158 = xor i1 %157, true
  %159 = xor i1 %158, true
  %160 = zext i1 %159 to i32
  %161 = sext i32 %160 to i64
  %162 = call i64 @llvm.expect.i64(i64 %161, i64 0)
  %163 = icmp ne i64 %162, 0
  br i1 %163, label %164, label %166

164:                                              ; preds = %149
  %165 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %165, ptr noundef @.str.3, ptr noundef @__func__.mdbx_thread_register, i32 noundef 91) #7
  unreachable

166:                                              ; preds = %149
  br label %167

167:                                              ; preds = %166
  br label %168

168:                                              ; preds = %167
  br label %169

169:                                              ; preds = %168, %137
  br label %170

170:                                              ; preds = %169
  br label %171

171:                                              ; preds = %170
  br label %172

172:                                              ; preds = %171
  %173 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !24
  %174 = zext i8 %173 to i32
  %175 = and i32 %174, 1
  %176 = icmp ne i32 %175, 0
  %177 = xor i1 %176, true
  %178 = xor i1 %177, true
  %179 = zext i1 %178 to i32
  %180 = sext i32 %179 to i64
  %181 = call i64 @llvm.expect.i64(i64 %180, i64 1)
  %182 = icmp ne i64 %181, 0
  br i1 %182, label %183, label %202

183:                                              ; preds = %172
  br label %184

184:                                              ; preds = %183
  %185 = load ptr, ptr %6, align 8, !tbaa !5
  %186 = getelementptr inbounds %struct.reader_slot, ptr %185, i32 0, i32 1
  %187 = load volatile i64, ptr %186, align 8, !tbaa !11
  %188 = call i64 @osal_thread_self()
  %189 = icmp eq i64 %187, %188
  %190 = xor i1 %189, true
  %191 = xor i1 %190, true
  %192 = xor i1 %191, true
  %193 = zext i1 %192 to i32
  %194 = sext i32 %193 to i64
  %195 = call i64 @llvm.expect.i64(i64 %194, i64 0)
  %196 = icmp ne i64 %195, 0
  br i1 %196, label %197, label %199

197:                                              ; preds = %184
  %198 = load ptr, ptr %3, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %198, ptr noundef @.str.4, ptr noundef @__func__.mdbx_thread_register, i32 noundef 92) #7
  unreachable

199:                                              ; preds = %184
  br label %200

200:                                              ; preds = %199
  br label %201

201:                                              ; preds = %200
  br label %202

202:                                              ; preds = %201, %172
  br label %203

203:                                              ; preds = %202
  br label %204

204:                                              ; preds = %203
  %205 = load ptr, ptr %6, align 8, !tbaa !5
  %206 = getelementptr inbounds %struct.reader_slot, ptr %205, i32 0, i32 2
  %207 = load volatile i32, ptr %206, align 8, !tbaa !11
  %208 = load ptr, ptr %3, align 8, !tbaa !5
  %209 = getelementptr inbounds %struct.MDBX_env, ptr %208, i32 0, i32 20
  %210 = load i32, ptr %209, align 4, !tbaa !27
  %211 = icmp ne i32 %207, %210
  %212 = xor i1 %211, true
  %213 = xor i1 %212, true
  %214 = zext i1 %213 to i32
  %215 = sext i32 %214 to i64
  %216 = call i64 @llvm.expect.i64(i64 %215, i64 0)
  %217 = icmp ne i64 %216, 0
  br i1 %217, label %218, label %220

218:                                              ; preds = %204
  %219 = call i32 @log_if_error(i32 noundef -30783, ptr noundef @__func__.mdbx_thread_register, i32 noundef 94)
  store i32 %219, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %231

220:                                              ; preds = %204
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %231

221:                                              ; preds = %123
  %222 = load ptr, ptr %3, align 8, !tbaa !5
  %223 = call { i32, ptr } @mvcc_bind_slot(ptr noundef %222)
  %224 = getelementptr inbounds { i32, ptr }, ptr %7, i32 0, i32 0
  %225 = extractvalue { i32, ptr } %223, 0
  store i32 %225, ptr %224, align 8
  %226 = getelementptr inbounds { i32, ptr }, ptr %7, i32 0, i32 1
  %227 = extractvalue { i32, ptr } %223, 1
  store ptr %227, ptr %226, align 8
  %228 = getelementptr inbounds %struct.bind_reader_slot_result, ptr %7, i32 0, i32 0
  %229 = load i32, ptr %228, align 8, !tbaa !28
  %230 = call i32 @log_if_error(i32 noundef %229, ptr noundef @__func__.mdbx_thread_register, i32 noundef 98)
  store i32 %230, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %231

231:                                              ; preds = %221, %220, %218
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %232

232:                                              ; preds = %231, %88, %34, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  %233 = load i32, ptr %2, align 4
  ret i32 %233
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @thread_rthc_get(i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @osal_thread_self() #1

declare { i32, ptr } @mvcc_bind_slot(ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(none) }
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 = { 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 #5 = { "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 }

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


; 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.9 }
%struct.anon.9 = 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__.mdbx_thread_register = external hidden unnamed_addr constant [21 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @check_env(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @log_if_error(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_thread_register(ptr noundef %0) local_unnamed_addr #2 {
  %2 = tail call i32 @check_env(ptr noundef %0, i1 noundef zeroext true)
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %5, label %3, !prof !5

3:                                                ; preds = %1
  %4 = tail call i32 @log_if_error(i32 noundef %2, ptr noundef nonnull @__func__.mdbx_thread_register, i32 noundef 78)
  br label %55

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = load ptr, ptr %6, align 8, !tbaa !6
  %.not22 = icmp eq ptr %7, null
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !9
  br i1 %.not22, label %10, label %14, !prof !23

10:                                               ; preds = %5
  %11 = and i32 %9, 4194304
  %.not33 = icmp eq i32 %11, 0
  %12 = select i1 %.not33, i32 1, i32 22
  %13 = tail call i32 @log_if_error(i32 noundef %12, ptr noundef nonnull @__func__.mdbx_thread_register, i32 noundef 81)
  br label %55

14:                                               ; preds = %5
  %15 = and i32 %9, 268435456
  %16 = icmp eq i32 %15, 0
  %17 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !24
  %18 = and i8 %17, 1
  br i1 %16, label %19, label %24, !prof !23

19:                                               ; preds = %14
  %.not31 = icmp ne i8 %18, 0
  %20 = and i32 %9, 2097152
  %.not32 = icmp eq i32 %20, 0
  %or.cond = and i1 %.not32, %.not31
  br i1 %or.cond, label %21, label %22, !prof !26

21:                                               ; preds = %19
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.1, ptr noundef nonnull @__func__.mdbx_thread_register, i32 noundef 84) #4
  unreachable

22:                                               ; preds = %19
  %23 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_thread_register, i32 noundef 85)
  br label %55

24:                                               ; preds = %14
  %.not23 = icmp eq i8 %18, 0
  %25 = and i32 %9, 270532608
  %.not24 = icmp eq i32 %25, 268435456
  %or.cond34 = or i1 %.not24, %.not23
  br i1 %or.cond34, label %27, label %26, !prof !27

26:                                               ; preds = %24
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.2, ptr noundef nonnull @__func__.mdbx_thread_register, i32 noundef 88) #4
  unreachable

27:                                               ; preds = %24
  %28 = getelementptr inbounds i8, ptr %0, i64 144
  %29 = load i32, ptr %28, align 8, !tbaa !28
  %30 = tail call ptr @thread_rthc_get(i32 noundef %29)
  %.not25 = icmp eq ptr %30, null
  br i1 %.not25, label %51, label %31, !prof !5

31:                                               ; preds = %27
  %32 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !24
  %33 = and i8 %32, 1
  %.not26 = icmp eq i8 %33, 0
  br i1 %.not26, label %.thread, label %34, !prof !23

34:                                               ; preds = %31
  %35 = getelementptr inbounds i8, ptr %30, i64 16
  %36 = load volatile i32, ptr %35, align 8, !tbaa !6
  %37 = getelementptr inbounds i8, ptr %0, i64 140
  %38 = load i32, ptr %37, align 4, !tbaa !29
  %.not27 = icmp eq i32 %36, %38
  br i1 %.not27, label %40, label %39, !prof !5

39:                                               ; preds = %34
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.3, ptr noundef nonnull @__func__.mdbx_thread_register, i32 noundef 91) #4
  unreachable

40:                                               ; preds = %34
  %41 = getelementptr inbounds i8, ptr %30, i64 8
  %42 = load volatile i64, ptr %41, align 8, !tbaa !6
  %43 = tail call i64 @osal_thread_self()
  %.not29 = icmp eq i64 %42, %43
  br i1 %.not29, label %.thread, label %44, !prof !5

44:                                               ; preds = %40
  tail call void @mdbx_assert_fail(ptr noundef nonnull %0, ptr noundef nonnull @.str.4, ptr noundef nonnull @__func__.mdbx_thread_register, i32 noundef 92) #4
  unreachable

.thread:                                          ; preds = %31, %40
  %45 = getelementptr inbounds i8, ptr %30, i64 16
  %46 = load volatile i32, ptr %45, align 8, !tbaa !6
  %47 = getelementptr inbounds i8, ptr %0, i64 140
  %48 = load i32, ptr %47, align 4, !tbaa !29
  %.not30 = icmp eq i32 %46, %48
  br i1 %.not30, label %55, label %49, !prof !5

49:                                               ; preds = %.thread
  %50 = tail call i32 @log_if_error(i32 noundef -30783, ptr noundef nonnull @__func__.mdbx_thread_register, i32 noundef 94)
  br label %55

51:                                               ; preds = %27
  %52 = tail call { i32, ptr } @mvcc_bind_slot(ptr noundef nonnull %0) #5
  %53 = extractvalue { i32, ptr } %52, 0
  %54 = tail call i32 @log_if_error(i32 noundef %53, ptr noundef nonnull @__func__.mdbx_thread_register, i32 noundef 98)
  br label %55

55:                                               ; preds = %49, %51, %.thread, %22, %10, %3
  %.1 = phi i32 [ %4, %3 ], [ %13, %10 ], [ %23, %22 ], [ %50, %49 ], [ %54, %51 ], [ -1, %.thread ]
  ret i32 %.1
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @thread_rthc_get(i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @osal_thread_self() local_unnamed_addr #0

declare { i32, ptr } @mvcc_bind_slot(ptr noundef) local_unnamed_addr #3

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


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