; LLVM IR from erthink/libmdbx :: src (page-ops)

; 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 }
%struct.anon = 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.page_get_result = type { ptr, i32 }
%struct.MDBX_cursor = type { i32, %union.anon, i8, i8, ptr, ptr, ptr, ptr, ptr, [32 x ptr], [32 x i16], ptr, ptr }
%union.anon = type { i16 }
%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.4 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.2, %union.anon.3 }
%union.anon.2 = type { i32 }
%union.anon.3 = type { i32 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.4 = type { %struct.anon.6 }
%struct.anon.6 = type { %struct.troika, ptr, %struct.anon.7, i8, i32, i32, i64, ptr, ptr, ptr, i64, %union.anon.8 }
%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.anon.7 = type { %struct.MDBX_rkl, i64, %struct.MDBX_rkl }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }
%union.anon.8 = type { %struct.anon.9 }
%struct.anon.9 = type { i64, ptr }
%struct.page = type <{ i64, i16, i16, %union.anon.10, i32, [0 x i16] }>
%union.anon.10 = type { i32 }
%struct.MDBX_env = type { %union.mdbx_atomic_uint32_t, i32, i32, %struct.osal_mmap, i32, i32, %struct.osal_mmap, ptr, i16, i16, i16, i16, i16, i16, %union.mdbx_atomic_uint32_t, i8, i8, i16, i32, i32, i32, i32, %struct.anon.13, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.14, %struct.anon.18, i8, ptr, ptr, ptr, %struct.anon.19, %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.12, i32, i64, i64, i64 }
%union.anon.12 = type { ptr }
%union.mdbx_atomic_uint32_t = type { i32 }
%struct.anon.13 = type { ptr, ptr, ptr, ptr }
%struct.anon.14 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.15, %union.anon.16 }
%struct.anon.15 = type { i16, i16, i16, i16 }
%union.anon.16 = type { i32 }
%struct.anon.18 = type { i64, i64, i64, i64, i64 }
%struct.anon.19 = 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.22, %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.20 }
%struct.anon.20 = 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.21 }
%struct.anon.21 = type { i64, i64, i32 }
%struct.anon.22 = 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 }
%struct.anon.11 = type { i16, i16 }
%struct.tree = type { i16, i16, i32, i32, i32, i32, i32, i64, i64, i64 }
%struct.anon.1 = type { i8, i8 }

@globals = external global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [23 x i8], align 1
@__func__.page_new = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local { ptr, i32 } @page_new(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca %struct.page_get_result, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %2
  %9 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !11
  %10 = zext i8 %9 to i32
  %11 = and i32 %10, 1
  %12 = icmp ne i32 %11, 0
  %13 = xor i1 %12, true
  %14 = xor i1 %13, true
  %15 = zext i1 %14 to i32
  %16 = sext i32 %15 to i64
  %17 = call i64 @llvm.expect.i64(i64 %16, i64 1)
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %19, label %39

19:                                               ; preds = %8
  br label %20

20:                                               ; preds = %19
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = and i32 %21, 4
  %23 = icmp eq i32 %22, 0
  %24 = xor i1 %23, true
  %25 = xor i1 %24, true
  %26 = xor i1 %25, true
  %27 = zext i1 %26 to i32
  %28 = sext i32 %27 to i64
  %29 = call i64 @llvm.expect.i64(i64 %28, i64 0)
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %31, label %37

31:                                               ; preds = %20
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.MDBX_cursor, ptr %32, i32 0, i32 5
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = getelementptr inbounds %struct.MDBX_txn, ptr %34, i32 0, i32 9
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  call void @mdbx_assert_fail(ptr noundef %36, ptr noundef @.str, ptr noundef @__func__.page_new, i32 noundef 16) #7
  unreachable

37:                                               ; preds = %20
  br label %38

38:                                               ; preds = %37
  br label %39

39:                                               ; preds = %38, %8
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = call { ptr, i32 } @gc_alloc_single(ptr noundef %41)
  %43 = getelementptr inbounds { ptr, i32 }, ptr %3, i32 0, i32 0
  %44 = extractvalue { ptr, i32 } %42, 0
  store ptr %44, ptr %43, align 8
  %45 = getelementptr inbounds { ptr, i32 }, ptr %3, i32 0, i32 1
  %46 = extractvalue { ptr, i32 } %42, 1
  store i32 %46, ptr %45, align 8
  %47 = getelementptr inbounds %struct.page_get_result, ptr %3, i32 0, i32 1
  %48 = load i32, ptr %47, align 8, !tbaa !22
  %49 = icmp ne i32 %48, 0
  %50 = xor i1 %49, true
  %51 = xor i1 %50, true
  %52 = zext i1 %51 to i32
  %53 = sext i32 %52 to i64
  %54 = call i64 @llvm.expect.i64(i64 %53, i64 0)
  %55 = icmp ne i64 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %40
  br label %228

57:                                               ; preds = %40
  br label %58

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

68:                                               ; preds = %58
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = call i64 @cursor_dbi(ptr noundef %69) #8
  %71 = getelementptr inbounds %struct.page_get_result, ptr %3, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !25
  %73 = getelementptr inbounds %struct.page, ptr %72, i32 0, i32 4
  %74 = load i32, ptr %73, align 1, !tbaa !9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef @__func__.page_new, i32 noundef 21, ptr noundef @.str.1, i64 noundef %70, i32 noundef %74)
  br label %75

75:                                               ; preds = %68, %58
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %5, align 4, !tbaa !9
  %78 = trunc i32 %77 to i16
  %79 = getelementptr inbounds %struct.page_get_result, ptr %3, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !25
  %81 = getelementptr inbounds %struct.page, ptr %80, i32 0, i32 2
  store i16 %78, ptr %81, align 1, !tbaa !26
  br label %82

82:                                               ; preds = %76
  %83 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !11
  %84 = zext i8 %83 to i32
  %85 = and i32 %84, 1
  %86 = icmp ne i32 %85, 0
  %87 = xor i1 %86, true
  %88 = xor i1 %87, true
  %89 = zext i1 %88 to i32
  %90 = sext i32 %89 to i64
  %91 = call i64 @llvm.expect.i64(i64 %90, i64 1)
  %92 = icmp ne i64 %91, 0
  br i1 %92, label %93, label %116

93:                                               ; preds = %82
  br label %94

94:                                               ; preds = %93
  %95 = load ptr, ptr %4, align 8, !tbaa !5
  %96 = call ptr @cursor_dbi_state(ptr noundef %95) #8
  %97 = load i8, ptr %96, align 1, !tbaa !27
  %98 = zext i8 %97 to i32
  %99 = and i32 %98, 1
  %100 = icmp ne i32 %99, 0
  %101 = xor i1 %100, true
  %102 = xor i1 %101, true
  %103 = xor i1 %102, true
  %104 = zext i1 %103 to i32
  %105 = sext i32 %104 to i64
  %106 = call i64 @llvm.expect.i64(i64 %105, i64 0)
  %107 = icmp ne i64 %106, 0
  br i1 %107, label %108, label %114

108:                                              ; preds = %94
  %109 = load ptr, ptr %4, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.MDBX_cursor, ptr %109, i32 0, i32 5
  %111 = load ptr, ptr %110, align 8, !tbaa !15
  %112 = getelementptr inbounds %struct.MDBX_txn, ptr %111, i32 0, i32 9
  %113 = load ptr, ptr %112, align 8, !tbaa !17
  call void @mdbx_assert_fail(ptr noundef %113, ptr noundef @.str.2, ptr noundef @__func__.page_new, i32 noundef 23) #7
  unreachable

114:                                              ; preds = %94
  br label %115

115:                                              ; preds = %114
  br label %116

116:                                              ; preds = %115, %82
  br label %117

117:                                              ; preds = %116
  br label %118

118:                                              ; preds = %117
  %119 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !11
  %120 = zext i8 %119 to i32
  %121 = and i32 %120, 1
  %122 = icmp ne i32 %121, 0
  %123 = xor i1 %122, true
  %124 = xor i1 %123, true
  %125 = zext i1 %124 to i32
  %126 = sext i32 %125 to i64
  %127 = call i64 @llvm.expect.i64(i64 %126, i64 1)
  %128 = icmp ne i64 %127, 0
  br i1 %128, label %129, label %153

129:                                              ; preds = %118
  br label %130

130:                                              ; preds = %129
  %131 = load ptr, ptr %4, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.MDBX_cursor, ptr %131, i32 0, i32 5
  %133 = load ptr, ptr %132, align 8, !tbaa !15
  %134 = getelementptr inbounds %struct.MDBX_txn, ptr %133, i32 0, i32 1
  %135 = load i32, ptr %134, align 4, !tbaa !28
  %136 = and i32 %135, 4
  %137 = icmp ne i32 %136, 0
  %138 = xor i1 %137, true
  %139 = xor i1 %138, true
  %140 = xor i1 %139, true
  %141 = zext i1 %140 to i32
  %142 = sext i32 %141 to i64
  %143 = call i64 @llvm.expect.i64(i64 %142, i64 0)
  %144 = icmp ne i64 %143, 0
  br i1 %144, label %145, label %151

145:                                              ; preds = %130
  %146 = load ptr, ptr %4, align 8, !tbaa !5
  %147 = getelementptr inbounds %struct.MDBX_cursor, ptr %146, i32 0, i32 5
  %148 = load ptr, ptr %147, align 8, !tbaa !15
  %149 = getelementptr inbounds %struct.MDBX_txn, ptr %148, i32 0, i32 9
  %150 = load ptr, ptr %149, align 8, !tbaa !17
  call void @mdbx_assert_fail(ptr noundef %150, ptr noundef @.str.3, ptr noundef @__func__.page_new, i32 noundef 24) #7
  unreachable

151:                                              ; preds = %130
  br label %152

152:                                              ; preds = %151
  br label %153

153:                                              ; preds = %152, %118
  br label %154

154:                                              ; preds = %153
  %155 = load ptr, ptr %4, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.MDBX_cursor, ptr %155, i32 0, i32 5
  %157 = load ptr, ptr %156, align 8, !tbaa !15
  %158 = getelementptr inbounds %struct.MDBX_txn, ptr %157, i32 0, i32 9
  %159 = load ptr, ptr %158, align 8, !tbaa !17
  %160 = getelementptr inbounds %struct.MDBX_env, ptr %159, i32 0, i32 7
  %161 = load ptr, ptr %160, align 8, !tbaa !29
  %162 = getelementptr inbounds %struct.shared_lck, ptr %161, i32 0, i32 9
  %163 = getelementptr inbounds %struct.pgops, ptr %162, i32 0, i32 0
  %164 = load volatile i64, ptr %163, align 64, !tbaa !27
  %165 = add i64 %164, 1
  store volatile i64 %165, ptr %163, align 64, !tbaa !27
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #9
  %166 = load i32, ptr %5, align 4, !tbaa !9
  %167 = and i32 %166, 1
  store i32 %167, ptr %6, align 4, !tbaa !9
  %168 = getelementptr inbounds %struct.page_get_result, ptr %3, i32 0, i32 0
  %169 = load ptr, ptr %168, align 8, !tbaa !25
  %170 = getelementptr inbounds %struct.page, ptr %169, i32 0, i32 3
  %171 = getelementptr inbounds %struct.anon.11, ptr %170, i32 0, i32 0
  store i16 0, ptr %171, align 1, !tbaa !27
  %172 = load ptr, ptr %4, align 8, !tbaa !5
  %173 = getelementptr inbounds %struct.MDBX_cursor, ptr %172, i32 0, i32 5
  %174 = load ptr, ptr %173, align 8, !tbaa !15
  %175 = getelementptr inbounds %struct.MDBX_txn, ptr %174, i32 0, i32 9
  %176 = load ptr, ptr %175, align 8, !tbaa !17
  %177 = getelementptr inbounds %struct.MDBX_env, ptr %176, i32 0, i32 2
  %178 = load i32, ptr %177, align 8, !tbaa !38
  %179 = sub i32 %178, 20
  %180 = trunc i32 %179 to i16
  %181 = getelementptr inbounds %struct.page_get_result, ptr %3, i32 0, i32 0
  %182 = load ptr, ptr %181, align 8, !tbaa !25
  %183 = getelementptr inbounds %struct.page, ptr %182, i32 0, i32 3
  %184 = getelementptr inbounds %struct.anon.11, ptr %183, i32 0, i32 1
  store i16 %180, ptr %184, align 1, !tbaa !27
  %185 = load i32, ptr %6, align 4, !tbaa !9
  %186 = load ptr, ptr %4, align 8, !tbaa !5
  %187 = getelementptr inbounds %struct.MDBX_cursor, ptr %186, i32 0, i32 6
  %188 = load ptr, ptr %187, align 8, !tbaa !39
  %189 = getelementptr inbounds %struct.tree, ptr %188, i32 0, i32 4
  %190 = load i32, ptr %189, align 4, !tbaa !40
  %191 = add i32 %190, %185
  store i32 %191, ptr %189, align 4, !tbaa !40
  %192 = load i32, ptr %6, align 4, !tbaa !9
  %193 = sub i32 1, %192
  %194 = load ptr, ptr %4, align 8, !tbaa !5
  %195 = getelementptr inbounds %struct.MDBX_cursor, ptr %194, i32 0, i32 6
  %196 = load ptr, ptr %195, align 8, !tbaa !39
  %197 = getelementptr inbounds %struct.tree, ptr %196, i32 0, i32 5
  %198 = load i32, ptr %197, align 4, !tbaa !42
  %199 = add i32 %198, %193
  store i32 %199, ptr %197, align 4, !tbaa !42
  %200 = load ptr, ptr %4, align 8, !tbaa !5
  %201 = getelementptr inbounds %struct.MDBX_cursor, ptr %200, i32 0, i32 1
  %202 = getelementptr inbounds %struct.anon.1, ptr %201, i32 0, i32 0
  %203 = load i8, ptr %202, align 4, !tbaa !27
  %204 = sext i8 %203 to i32
  %205 = and i32 %204, 1
  %206 = icmp ne i32 %205, 0
  %207 = xor i1 %206, true
  %208 = xor i1 %207, true
  %209 = zext i1 %208 to i32
  %210 = sext i32 %209 to i64
  %211 = call i64 @llvm.expect.i64(i64 %210, i64 0)
  %212 = icmp ne i64 %211, 0
  br i1 %212, label %213, label %227

213:                                              ; preds = %154
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #9
  %214 = load ptr, ptr %4, align 8, !tbaa !5
  %215 = call ptr @outer_tree(ptr noundef %214)
  store ptr %215, ptr %7, align 8, !tbaa !5
  %216 = load i32, ptr %6, align 4, !tbaa !9
  %217 = load ptr, ptr %7, align 8, !tbaa !5
  %218 = getelementptr inbounds %struct.tree, ptr %217, i32 0, i32 4
  %219 = load i32, ptr %218, align 4, !tbaa !40
  %220 = add i32 %219, %216
  store i32 %220, ptr %218, align 4, !tbaa !40
  %221 = load i32, ptr %6, align 4, !tbaa !9
  %222 = sub i32 1, %221
  %223 = load ptr, ptr %7, align 8, !tbaa !5
  %224 = getelementptr inbounds %struct.tree, ptr %223, i32 0, i32 5
  %225 = load i32, ptr %224, align 4, !tbaa !42
  %226 = add i32 %225, %222
  store i32 %226, ptr %224, align 4, !tbaa !42
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #9
  br label %227

227:                                              ; preds = %213, %154
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #9
  br label %228

228:                                              ; preds = %227, %56
  %229 = load { ptr, i32 }, ptr %3, align 8
  ret { ptr, i32 } %229
}

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

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

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

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

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden i64 @cursor_dbi(ptr noundef) #4

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare hidden ptr @cursor_dbi_state(ptr noundef) #4

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @outer_tree(ptr noundef) #6

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { 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 #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 = { 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 #5 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 25}
!12 = !{!"libmdbx_globals", !7, i64 0, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !13, i64 27, !10, i64 28, !7, i64 32, !7, i64 40, !14, i64 80, !6, i64 88}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !6, i64 16}
!16 = !{!"MDBX_cursor", !10, i64 0, !7, i64 4, !7, i64 6, !7, i64 7, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !7, i64 48, !7, i64 304, !6, i64 368, !6, i64 376}
!17 = !{!18, !6, i64 80}
!18 = !{!"MDBX_txn", !10, i64 0, !10, i64 4, !14, i64 8, !14, i64 16, !6, i64 24, !6, i64 32, !19, i64 40, !14, i64 64, !14, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !21, i64 128, !6, i64 160, !7, i64 168}
!19 = !{!"geo", !20, i64 0, !20, i64 2, !10, i64 4, !10, i64 8, !7, i64 12, !7, i64 16}
!20 = !{!"short", !7, i64 0}
!21 = !{!"MDBX_canary", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!22 = !{!23, !10, i64 8}
!23 = !{!"page_get_result", !6, i64 0, !10, i64 8}
!24 = !{!12, !7, i64 26}
!25 = !{!23, !6, i64 0}
!26 = !{!20, !20, i64 0}
!27 = !{!7, !7, i64 0}
!28 = !{!18, !10, i64 4}
!29 = !{!30, !6, i64 104}
!30 = !{!"MDBX_env", !7, i64 0, !10, i64 4, !10, i64 8, !31, i64 16, !10, i64 56, !10, i64 60, !31, i64 64, !6, i64 104, !20, i64 112, !20, i64 114, !20, i64 116, !20, i64 118, !20, i64 120, !20, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !20, i64 130, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !32, 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, !14, i64 256, !33, i64 264, !35, i64 320, !13, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !36, i64 392, !7, i64 400, !10, i64 440, !10, i64 444, !6, i64 448, !37, i64 456, !7, i64 496, !7, i64 536}
!31 = !{!"osal_mmap", !7, i64 0, !10, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!32 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!33 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !14, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !10, i64 28, !10, i64 32, !13, i64 36, !13, i64 37, !13, i64 38, !34, i64 40, !7, i64 48}
!34 = !{!"", !20, i64 0, !20, i64 2, !20, i64 4, !20, i64 6}
!35 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!36 = !{!"", !14, i64 0}
!37 = !{!"osal_ioring", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!38 = !{!30, !10, i64 8}
!39 = !{!16, !6, i64 24}
!40 = !{!41, !10, i64 12}
!41 = !{!"tree", !20, i64 0, !20, i64 2, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !14, i64 24, !14, i64 32, !14, i64 40}
!42 = !{!41, !10, i64 16}


; 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 }
%struct.anon = type { i64, i64 }
%union.logger_union = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [23 x i8], align 1
@__func__.page_new = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [32 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local { ptr, i32 } @page_new(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %4 = and i8 %3, 1
  %.not = icmp eq i8 %4, 0
  %5 = and i32 %1, 4
  %.not25 = icmp eq i32 %5, 0
  %or.cond = or i1 %.not25, %.not
  br i1 %or.cond, label %11, label %6, !prof !13

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %8, i64 80
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  tail call void @mdbx_assert_fail(ptr noundef %10, ptr noundef nonnull @.str, ptr noundef nonnull @__func__.page_new, i32 noundef 16) #5
  unreachable

11:                                               ; preds = %2
  %12 = tail call { ptr, i32 } @gc_alloc_single(ptr noundef %0) #6
  %13 = extractvalue { ptr, i32 } %12, 0
  %14 = extractvalue { ptr, i32 } %12, 1
  %.not26 = icmp eq i32 %14, 0
  br i1 %.not26, label %15, label %82, !prof !21

15:                                               ; preds = %11
  %16 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !22
  %17 = icmp ugt i8 %16, 4
  br i1 %17, label %18, label %22, !prof !23

18:                                               ; preds = %15
  %19 = tail call i64 @cursor_dbi(ptr noundef %0) #7
  %20 = getelementptr inbounds i8, ptr %13, i64 16
  %21 = load i32, ptr %20, align 1, !tbaa !24
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef nonnull @__func__.page_new, i32 noundef 21, ptr noundef nonnull @.str.1, i64 noundef %19, i32 noundef %21) #6
  br label %22

22:                                               ; preds = %15, %18
  %23 = trunc i32 %1 to i16
  %24 = getelementptr inbounds i8, ptr %13, i64 10
  store i16 %23, ptr %24, align 1, !tbaa !25
  %25 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %26 = and i8 %25, 1
  %.not27 = icmp eq i8 %26, 0
  br i1 %.not27, label %..thread_crit_edge, label %27, !prof !23

..thread_crit_edge:                               ; preds = %22
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 16
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !14
  br label %.thread

27:                                               ; preds = %22
  %28 = tail call ptr @cursor_dbi_state(ptr noundef %0) #7
  %29 = load i8, ptr %28, align 1, !tbaa !26
  %30 = and i8 %29, 1
  %.not28 = icmp eq i8 %30, 0
  %31 = getelementptr inbounds i8, ptr %0, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  br i1 %.not28, label %33, label %36, !prof !23

33:                                               ; preds = %27
  %34 = getelementptr inbounds i8, ptr %32, i64 80
  %35 = load ptr, ptr %34, align 8, !tbaa !16
  tail call void @mdbx_assert_fail(ptr noundef %35, ptr noundef nonnull @.str.2, ptr noundef nonnull @__func__.page_new, i32 noundef 23) #5
  unreachable

36:                                               ; preds = %27
  %37 = getelementptr inbounds i8, ptr %32, i64 4
  %38 = load i32, ptr %37, align 4, !tbaa !27
  %39 = and i32 %38, 4
  %.not30 = icmp eq i32 %39, 0
  br i1 %.not30, label %40, label %.thread, !prof !23

40:                                               ; preds = %36
  %41 = getelementptr inbounds i8, ptr %32, i64 80
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  tail call void @mdbx_assert_fail(ptr noundef %42, ptr noundef nonnull @.str.3, ptr noundef nonnull @__func__.page_new, i32 noundef 24) #5
  unreachable

.thread:                                          ; preds = %..thread_crit_edge, %36
  %43 = phi ptr [ %.pre, %..thread_crit_edge ], [ %32, %36 ]
  %44 = getelementptr inbounds i8, ptr %0, i64 16
  %45 = getelementptr inbounds i8, ptr %43, i64 80
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  %47 = getelementptr inbounds i8, ptr %46, i64 104
  %48 = load ptr, ptr %47, align 8, !tbaa !28
  %49 = getelementptr inbounds i8, ptr %48, i64 64
  %50 = load volatile i64, ptr %49, align 64, !tbaa !26
  %51 = add i64 %50, 1
  store volatile i64 %51, ptr %49, align 64, !tbaa !26
  %52 = and i32 %1, 1
  %53 = getelementptr inbounds i8, ptr %13, i64 12
  store i16 0, ptr %53, align 1, !tbaa !26
  %54 = load ptr, ptr %44, align 8, !tbaa !14
  %55 = getelementptr inbounds i8, ptr %54, i64 80
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = getelementptr inbounds i8, ptr %56, i64 8
  %58 = load i32, ptr %57, align 8, !tbaa !37
  %59 = trunc i32 %58 to i16
  %60 = add i16 %59, -20
  %61 = getelementptr inbounds i8, ptr %13, i64 14
  store i16 %60, ptr %61, align 1, !tbaa !26
  %62 = getelementptr inbounds i8, ptr %0, i64 24
  %63 = load ptr, ptr %62, align 8, !tbaa !38
  %64 = getelementptr inbounds i8, ptr %63, i64 12
  %65 = load i32, ptr %64, align 4, !tbaa !39
  %66 = add i32 %65, %52
  store i32 %66, ptr %64, align 4, !tbaa !39
  %67 = xor i32 %52, 1
  %68 = getelementptr inbounds i8, ptr %63, i64 16
  %69 = load i32, ptr %68, align 4, !tbaa !41
  %70 = add i32 %69, %67
  store i32 %70, ptr %68, align 4, !tbaa !41
  %71 = getelementptr inbounds i8, ptr %0, i64 4
  %72 = load i8, ptr %71, align 4, !tbaa !26
  %73 = and i8 %72, 1
  %.not31 = icmp eq i8 %73, 0
  br i1 %.not31, label %82, label %74, !prof !21

74:                                               ; preds = %.thread
  %75 = tail call ptr @outer_tree(ptr noundef nonnull %0)
  %76 = getelementptr inbounds i8, ptr %75, i64 12
  %77 = load i32, ptr %76, align 4, !tbaa !39
  %78 = add i32 %77, %52
  store i32 %78, ptr %76, align 4, !tbaa !39
  %79 = getelementptr inbounds i8, ptr %75, i64 16
  %80 = load i32, ptr %79, align 4, !tbaa !41
  %81 = add i32 %80, %67
  store i32 %81, ptr %79, align 4, !tbaa !41
  br label %82

82:                                               ; preds = %.thread, %74, %11
  ret { ptr, i32 } %12
}

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

declare { ptr, i32 } @gc_alloc_single(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden i64 @cursor_dbi(ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare hidden ptr @cursor_dbi_state(ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @outer_tree(ptr noundef) local_unnamed_addr #4

attributes #0 = { 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 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { inlinehint 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 #4 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { noreturn nounwind }
attributes #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !7, i64 25}
!6 = !{!"libmdbx_globals", !7, i64 0, !9, i64 16, !9, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !10, i64 27, !9, i64 28, !7, i64 32, !7, i64 40, !11, i64 80, !12, i64 88}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"branch_weights", i32 4002001, i32 2000}
!14 = !{!15, !12, i64 16}
!15 = !{!"MDBX_cursor", !9, i64 0, !7, i64 4, !7, i64 6, !7, i64 7, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !7, i64 48, !7, i64 304, !12, i64 368, !12, i64 376}
!16 = !{!17, !12, i64 80}
!17 = !{!"MDBX_txn", !9, i64 0, !9, i64 4, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 32, !18, i64 40, !11, i64 64, !11, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !20, i64 128, !12, i64 160, !7, i64 168}
!18 = !{!"geo", !19, i64 0, !19, i64 2, !9, i64 4, !9, i64 8, !7, i64 12, !7, i64 16}
!19 = !{!"short", !7, i64 0}
!20 = !{!"MDBX_canary", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!21 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!22 = !{!6, !7, i64 26}
!23 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!24 = !{!9, !9, i64 0}
!25 = !{!19, !19, i64 0}
!26 = !{!7, !7, i64 0}
!27 = !{!17, !9, i64 4}
!28 = !{!29, !12, i64 104}
!29 = !{!"MDBX_env", !7, i64 0, !9, i64 4, !9, i64 8, !30, i64 16, !9, i64 56, !9, i64 60, !30, i64 64, !12, i64 104, !19, i64 112, !19, i64 114, !19, i64 116, !19, i64 118, !19, i64 120, !19, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !19, i64 130, !9, i64 132, !9, i64 136, !9, i64 140, !9, i64 144, !31, i64 152, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208, !12, i64 216, !9, i64 224, !9, i64 228, !9, i64 232, !12, i64 240, !12, i64 248, !11, i64 256, !32, i64 264, !34, i64 320, !10, i64 360, !12, i64 368, !12, i64 376, !12, i64 384, !35, i64 392, !7, i64 400, !9, i64 440, !9, i64 444, !12, i64 448, !36, i64 456, !7, i64 496, !7, i64 536}
!30 = !{!"osal_mmap", !7, i64 0, !9, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!31 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24}
!32 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !11, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !9, i64 28, !9, i64 32, !10, i64 36, !10, i64 37, !10, i64 38, !33, i64 40, !7, i64 48}
!33 = !{!"", !19, i64 0, !19, i64 2, !19, i64 4, !19, i64 6}
!34 = !{!"", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!35 = !{!"", !11, i64 0}
!36 = !{!"osal_ioring", !9, i64 0, !9, i64 4, !9, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!37 = !{!29, !9, i64 8}
!38 = !{!15, !12, i64 24}
!39 = !{!40, !9, i64 12}
!40 = !{!"tree", !19, i64 0, !19, i64 2, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !9, i64 20, !11, i64 24, !11, i64 32, !11, i64 40}
!41 = !{!40, !9, i64 16}


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