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

; 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.rthc_entry = type { 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.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.8, %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.6 }
%struct.anon.6 = 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.7 }
%struct.anon.7 = type { i64, i64, i32 }
%struct.anon.8 = 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 }

@rthc_count = external hidden global i32, align 4
@rthc_table = external hidden global ptr, align 8
@globals = external global %struct.libmdbx_globals, align 8
@__func__.rthc_uniq_check = external hidden unnamed_addr constant [16 x i8], align 1
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @rthc_uniq_check(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %171, %2
  %14 = load i64, ptr %7, align 8, !tbaa !9
  %15 = load i32, ptr @rthc_count, align 4, !tbaa !11
  %16 = zext i32 %15 to i64
  %17 = icmp ult i64 %14, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  store i32 2, ptr %8, align 4
  br label %174

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %20 = load ptr, ptr @rthc_table, align 8, !tbaa !5
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.rthc_entry, ptr %20, i64 %21
  %23 = getelementptr inbounds %struct.rthc_entry, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  store ptr %24, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MDBX_env, ptr %25, i32 0, i32 6
  %27 = getelementptr inbounds %struct.osal_mmap, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %35

30:                                               ; preds = %19
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.MDBX_env, ptr %31, i32 0, i32 6
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = icmp eq ptr %32, %33
  br i1 %34, label %35, label %36

35:                                               ; preds = %30, %19
  store i32 4, ptr %8, align 4
  br label %168

36:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.MDBX_env, ptr %37, i32 0, i32 6
  %39 = getelementptr inbounds %struct.osal_mmap, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = getelementptr inbounds %struct.shared_lck, ptr %40, i32 0, i32 6
  %42 = call i64 @atomic_load64(ptr noundef %41, i32 noundef 1)
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %44, label %49

44:                                               ; preds = %36
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.MDBX_env, ptr %46, i32 0, i32 6
  %48 = call i32 @uniq_peek(ptr noundef %45, ptr noundef %47)
  br label %54

49:                                               ; preds = %36
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.MDBX_env, ptr %51, i32 0, i32 6
  %53 = call i32 @uniq_poke(ptr noundef %50, ptr noundef %52, ptr noundef %6)
  br label %54

54:                                               ; preds = %49, %44
  %55 = phi i32 [ %48, %44 ], [ %53, %49 ]
  store i32 %55, ptr %10, align 4, !tbaa !11
  %56 = load i32, ptr %10, align 4, !tbaa !11
  %57 = icmp eq i32 %56, 61
  br i1 %57, label %58, label %94

58:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  store i64 0, ptr %11, align 8, !tbaa !9
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.osal_mmap, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 8, !tbaa !16
  %62 = call i32 @osal_filesize(i32 noundef %61, ptr noundef %11)
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %67

64:                                               ; preds = %58
  %65 = load i64, ptr %11, align 8, !tbaa !9
  %66 = icmp eq i64 %65, 0
  br label %67

67:                                               ; preds = %64, %58
  %68 = phi i1 [ false, %58 ], [ %66, %64 ]
  %69 = xor i1 %68, true
  %70 = xor i1 %69, true
  %71 = zext i1 %70 to i32
  %72 = sext i32 %71 to i64
  %73 = call i64 @llvm.expect.i64(i64 %72, i64 1)
  %74 = icmp ne i64 %73, 0
  br i1 %74, label %75, label %90

75:                                               ; preds = %67
  br label %76

76:                                               ; preds = %75
  %77 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !18
  %78 = zext i8 %77 to i32
  %79 = icmp sle i32 5, %78
  %80 = xor i1 %79, true
  %81 = xor i1 %80, true
  %82 = zext i1 %81 to i32
  %83 = sext i32 %82 to i64
  %84 = call i64 @llvm.expect.i64(i64 %83, i64 0)
  %85 = icmp ne i64 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %76
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef @__func__.rthc_uniq_check, i32 noundef 71, ptr noundef @.str, ptr noundef @.str.1)
  br label %87

87:                                               ; preds = %86, %76
  br label %88

88:                                               ; preds = %87
  br label %89

89:                                               ; preds = %88
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %91

90:                                               ; preds = %67
  store i32 0, ptr %8, align 4
  br label %91

91:                                               ; preds = %90, %89
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  %92 = load i32, ptr %8, align 4
  switch i32 %92, label %167 [
    i32 0, label %93
  ]

93:                                               ; preds = %91
  br label %94

94:                                               ; preds = %93, %54
  %95 = load i32, ptr %10, align 4, !tbaa !11
  %96 = icmp eq i32 %95, -1
  br i1 %96, label %97, label %102

97:                                               ; preds = %94
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.MDBX_env, ptr %99, i32 0, i32 6
  %101 = call i32 @uniq_poke(ptr noundef %98, ptr noundef %100, ptr noundef %6)
  store i32 %101, ptr %10, align 4, !tbaa !11
  br label %102

102:                                              ; preds = %97, %94
  %103 = load i32, ptr %10, align 4, !tbaa !11
  %104 = icmp eq i32 %103, -1
  br i1 %104, label %105, label %113

105:                                              ; preds = %102
  %106 = load ptr, ptr %9, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.MDBX_env, ptr %106, i32 0, i32 6
  %108 = call i32 @osal_msync(ptr noundef %107, i64 noundef 0, i64 noundef 512, i32 noundef 1)
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = load ptr, ptr %9, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.MDBX_env, ptr %110, i32 0, i32 6
  %112 = call i32 @uniq_poke(ptr noundef %109, ptr noundef %111, ptr noundef %6)
  store i32 %112, ptr %10, align 4, !tbaa !11
  br label %113

113:                                              ; preds = %105, %102
  %114 = load i32, ptr %10, align 4, !tbaa !11
  %115 = icmp eq i32 %114, -1
  br i1 %115, label %116, label %140

116:                                              ; preds = %113
  %117 = load ptr, ptr %4, align 8, !tbaa !5
  %118 = load ptr, ptr %9, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.MDBX_env, ptr %118, i32 0, i32 6
  %120 = call i32 @uniq_poke(ptr noundef %117, ptr noundef %119, ptr noundef %6)
  store i32 %120, ptr %10, align 4, !tbaa !11
  %121 = load ptr, ptr %9, align 8, !tbaa !5
  %122 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %121, ptr %122, align 8, !tbaa !5
  br label %123

123:                                              ; preds = %116
  %124 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !18
  %125 = zext i8 %124 to i32
  %126 = icmp sle i32 5, %125
  %127 = xor i1 %126, true
  %128 = xor i1 %127, true
  %129 = zext i1 %128 to i32
  %130 = sext i32 %129 to i64
  %131 = call i64 @llvm.expect.i64(i64 %130, i64 0)
  %132 = icmp ne i64 %131, 0
  br i1 %132, label %133, label %137

133:                                              ; preds = %123
  %134 = load ptr, ptr %5, align 8, !tbaa !5
  %135 = load ptr, ptr %134, align 8, !tbaa !5
  %136 = call ptr @__Wpedantic_format_voidptr(ptr noundef %135)
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef @__func__.rthc_uniq_check, i32 noundef 84, ptr noundef @.str.2, ptr noundef %136)
  br label %137

137:                                              ; preds = %133, %123
  br label %138

138:                                              ; preds = %137
  br label %139

139:                                              ; preds = %138
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %167

140:                                              ; preds = %113
  %141 = load i32, ptr %10, align 4, !tbaa !11
  %142 = icmp ne i32 %141, 0
  %143 = xor i1 %142, true
  %144 = xor i1 %143, true
  %145 = zext i1 %144 to i32
  %146 = sext i32 %145 to i64
  %147 = call i64 @llvm.expect.i64(i64 %146, i64 0)
  %148 = icmp ne i64 %147, 0
  br i1 %148, label %149, label %166

149:                                              ; preds = %140
  br label %150

150:                                              ; preds = %149
  %151 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !18
  %152 = zext i8 %151 to i32
  %153 = icmp sle i32 5, %152
  %154 = xor i1 %153, true
  %155 = xor i1 %154, true
  %156 = zext i1 %155 to i32
  %157 = sext i32 %156 to i64
  %158 = call i64 @llvm.expect.i64(i64 %157, i64 0)
  %159 = icmp ne i64 %158, 0
  br i1 %159, label %160, label %162

160:                                              ; preds = %150
  %161 = load i32, ptr %10, align 4, !tbaa !11
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef @__func__.rthc_uniq_check, i32 noundef 88, ptr noundef @.str.3, i32 noundef %161)
  br label %162

162:                                              ; preds = %160, %150
  br label %163

163:                                              ; preds = %162
  br label %164

164:                                              ; preds = %163
  %165 = load i32, ptr %10, align 4, !tbaa !11
  store i32 %165, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %167

166:                                              ; preds = %140
  store i32 0, ptr %8, align 4
  br label %167

167:                                              ; preds = %166, %164, %139, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %168

168:                                              ; preds = %167, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  %169 = load i32, ptr %8, align 4
  switch i32 %169, label %174 [
    i32 0, label %170
    i32 4, label %171
  ]

170:                                              ; preds = %168
  br label %171

171:                                              ; preds = %170, %168
  %172 = load i64, ptr %7, align 8, !tbaa !9
  %173 = add i64 %172, 1
  store i64 %173, ptr %7, align 8, !tbaa !9
  br label %13, !llvm.loop !21

174:                                              ; preds = %168, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  %175 = load i32, ptr %8, align 4
  switch i32 %175, label %191 [
    i32 2, label %176
  ]

176:                                              ; preds = %174
  br label %177

177:                                              ; preds = %176
  %178 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !18
  %179 = zext i8 %178 to i32
  %180 = icmp sle i32 5, %179
  %181 = xor i1 %180, true
  %182 = xor i1 %181, true
  %183 = zext i1 %182 to i32
  %184 = sext i32 %183 to i64
  %185 = call i64 @llvm.expect.i64(i64 %184, i64 0)
  %186 = icmp ne i64 %185, 0
  br i1 %186, label %187, label %188

187:                                              ; preds = %177
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef @__func__.rthc_uniq_check, i32 noundef 93, ptr noundef @.str, ptr noundef @.str.4)
  br label %188

188:                                              ; preds = %187, %177
  br label %189

189:                                              ; preds = %188
  br label %190

190:                                              ; preds = %189
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %191

191:                                              ; preds = %190, %174
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  %192 = load i32, ptr %3, 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) #1

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @atomic_load64(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @uniq_peek(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @uniq_poke(ptr noundef, ptr noundef, ptr noundef) #3

declare i32 @osal_filesize(i32 noundef, ptr noundef) #4

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

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

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

declare i32 @osal_msync(ptr noundef, i64 noundef, i64 noundef, i32 noundef) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @__Wpedantic_format_voidptr(ptr noundef) #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(argmem: readwrite) }
attributes #2 = { alwaysinline 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 = { 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #6 = { 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 #7 = { 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, !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 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"rthc_entry", !6, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !12, i64 8}
!17 = !{!"osal_mmap", !7, i64 0, !12, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!18 = !{!19, !7, i64 26}
!19 = !{!"libmdbx_globals", !7, i64 0, !12, i64 16, !12, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !20, i64 27, !12, i64 28, !7, i64 32, !7, i64 40, !10, i64 80, !6, i64 88}
!20 = !{!"_Bool", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

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

@rthc_count = external hidden local_unnamed_addr global i32, align 4
@rthc_table = external hidden local_unnamed_addr global ptr, align 8
@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@__func__.rthc_uniq_check = external hidden unnamed_addr constant [16 x i8], align 1
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
define dso_local noundef i32 @rthc_uniq_check(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store ptr null, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #6
  store i64 0, ptr %3, align 8, !tbaa !9
  %5 = load i32, ptr @rthc_count, align 4, !tbaa !11
  %.not5075.not = icmp eq i32 %5, 0
  br i1 %.not5075.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %48
  %6 = phi i32 [ %49, %48 ], [ %5, %2 ]
  %.04076 = phi i64 [ %50, %48 ], [ 0, %2 ]
  %7 = load ptr, ptr @rthc_table, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.rthc_entry, ptr %7, i64 %.04076
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %9, i64 64
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %.not = icmp eq ptr %11, null
  %12 = icmp eq ptr %10, %0
  %or.cond = or i1 %.not, %12
  br i1 %or.cond, label %48, label %13

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %11, i64 32
  %15 = call i64 @atomic_load64(ptr noundef nonnull %14, i32 noundef 1)
  %.not45 = icmp eq i64 %15, 0
  br i1 %.not45, label %18, label %16

16:                                               ; preds = %13
  %17 = call i32 @uniq_peek(ptr noundef %0, ptr noundef nonnull %10)
  br label %20

18:                                               ; preds = %13
  %19 = call i32 @uniq_poke(ptr noundef %0, ptr noundef nonnull %10, ptr noundef nonnull %3)
  br label %20

20:                                               ; preds = %18, %16
  %21 = phi i32 [ %17, %16 ], [ %19, %18 ]
  switch i32 %21, label %.thread56 [
    i32 61, label %22
    i32 -1, label %33
  ]

22:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  store i64 0, ptr %4, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = load i32, ptr %23, align 8, !tbaa !16
  %25 = call i32 @osal_filesize(i32 noundef %24, ptr noundef nonnull %4) #6
  %26 = icmp ne i32 %25, 0
  %27 = load i64, ptr %4, align 8
  %28 = icmp ne i64 %27, 0
  %.not48 = select i1 %26, i1 true, i1 %28
  br i1 %.not48, label %.thread56.thread, label %29, !prof !18

29:                                               ; preds = %22
  %30 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !19
  %31 = icmp ugt i8 %30, 4
  br i1 %31, label %32, label %.thread, !prof !18

32:                                               ; preds = %29
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef nonnull @__func__.rthc_uniq_check, i32 noundef 71, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1) #6
  br label %.thread

.thread:                                          ; preds = %29, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  br label %.thread64

.thread56.thread:                                 ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  br label %.loopexit

33:                                               ; preds = %20
  %34 = call i32 @uniq_poke(ptr noundef %0, ptr noundef nonnull %10, ptr noundef nonnull %3)
  %35 = icmp eq i32 %34, -1
  br i1 %35, label %36, label %.thread56

36:                                               ; preds = %33
  %37 = call i32 @osal_msync(ptr noundef nonnull %10, i64 noundef 0, i64 noundef 512, i32 noundef 1) #6
  %38 = call i32 @uniq_poke(ptr noundef %0, ptr noundef nonnull %10, ptr noundef nonnull %3)
  br label %.thread56

.thread56:                                        ; preds = %20, %36, %33
  %.1 = phi i32 [ %38, %36 ], [ %34, %33 ], [ %21, %20 ]
  switch i32 %.1, label %.loopexit [
    i32 -1, label %39
    i32 0, label %.thread56._crit_edge
  ], !prof !22

.thread56._crit_edge:                             ; preds = %.thread56
  %.pre = load i32, ptr @rthc_count, align 4, !tbaa !11
  br label %48

39:                                               ; preds = %.thread56
  %40 = call i32 @uniq_poke(ptr noundef %0, ptr noundef nonnull %10, ptr noundef nonnull %3)
  store ptr %9, ptr %1, align 8, !tbaa !5
  %41 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !19
  %42 = icmp ugt i8 %41, 4
  br i1 %42, label %43, label %.thread64, !prof !18

43:                                               ; preds = %39
  %44 = call ptr @__Wpedantic_format_voidptr(ptr noundef nonnull %9)
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef nonnull @__func__.rthc_uniq_check, i32 noundef 84, ptr noundef nonnull @.str.2, ptr noundef %44) #6
  br label %.thread64

.loopexit:                                        ; preds = %.thread56, %.thread56.thread
  %.168 = phi i32 [ 61, %.thread56.thread ], [ %.1, %.thread56 ]
  %45 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !19
  %46 = icmp ugt i8 %45, 4
  br i1 %46, label %47, label %.thread64, !prof !18

47:                                               ; preds = %.loopexit
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef nonnull @__func__.rthc_uniq_check, i32 noundef 88, ptr noundef nonnull @.str.3, i32 noundef %.168) #6
  br label %.thread64

48:                                               ; preds = %.thread56._crit_edge, %.lr.ph
  %49 = phi i32 [ %.pre, %.thread56._crit_edge ], [ %6, %.lr.ph ]
  %50 = add nuw nsw i64 %.04076, 1
  %51 = zext i32 %49 to i64
  %.not50 = icmp ult i64 %50, %51
  br i1 %.not50, label %.lr.ph, label %._crit_edge, !llvm.loop !23

._crit_edge:                                      ; preds = %48, %2
  %52 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !19
  %53 = icmp ugt i8 %52, 4
  br i1 %53, label %54, label %.thread64, !prof !18

54:                                               ; preds = %._crit_edge
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef nonnull @__func__.rthc_uniq_check, i32 noundef 93, ptr noundef nonnull @.str, ptr noundef nonnull @.str.4) #6
  br label %.thread64

.thread64:                                        ; preds = %43, %39, %47, %.loopexit, %.thread, %._crit_edge, %54
  %.6 = phi i32 [ 0, %54 ], [ 0, %._crit_edge ], [ 0, %.thread ], [ %.168, %.loopexit ], [ %.168, %47 ], [ 0, %39 ], [ 0, %43 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #6
  ret i32 %.6
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i64 @atomic_load64(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @uniq_peek(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @uniq_poke(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @osal_filesize(i32 noundef, ptr noundef) local_unnamed_addr #4

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

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

declare i32 @osal_msync(ptr noundef, i64 noundef, i64 noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @__Wpedantic_format_voidptr(ptr 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { alwaysinline 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 = { 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 = { "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 = { 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, !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 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"rthc_entry", !6, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !12, i64 8}
!17 = !{!"osal_mmap", !7, i64 0, !12, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!18 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!19 = !{!20, !7, i64 26}
!20 = !{!"libmdbx_globals", !7, i64 0, !12, i64 16, !12, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !21, i64 27, !12, i64 28, !7, i64 32, !7, i64 40, !10, i64 80, !6, i64 88}
!21 = !{!"_Bool", !7, i64 0}
!22 = !{!"branch_weights", i32 0, i32 1074010193, i32 1073473455}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass