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

; 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.16 }
%struct.anon.16 = 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.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.2 }
%struct.geo = type { i16, i16, i32, i32, %union.anon.0, %union.anon.1 }
%union.anon.0 = type { i32 }
%union.anon.1 = type { i32 }
%struct.MDBX_canary = type { i64, i64, i64, i64 }
%union.anon.2 = type { %struct.anon.4 }
%struct.anon.4 = type { %struct.troika, ptr, %struct.anon.5, i8, i32, i32, i64, ptr, ptr, ptr, i64, %union.anon.6 }
%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }
%struct.anon.5 = type { %struct.MDBX_rkl, i64, %struct.MDBX_rkl }
%struct.MDBX_rkl = type { i64, i64, i32, i32, ptr, [12 x i64] }
%union.anon.6 = type { %struct.anon.7 }
%struct.anon.7 = type { i64, ptr }

@__func__.mdbx_cursor_bind = external hidden unnamed_addr constant [17 x i8], align 1
@globals = external global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [15 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: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mdbx_cursor_bind(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  %13 = xor i1 %12, true
  %14 = xor i1 %13, true
  %15 = xor i1 %14, true
  %16 = zext i1 %15 to i32
  %17 = sext i32 %16 to i64
  %18 = call i64 @llvm.expect.i64(i64 %17, i64 0)
  %19 = icmp ne i64 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %3
  %21 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_cursor_bind, i32 noundef 40)
  store i32 %21, ptr %4, align 4
  br label %226

22:                                               ; preds = %3
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.MDBX_cursor, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = icmp ne i32 %25, 672636999
  br i1 %26, label %27, label %32

27:                                               ; preds = %22
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.MDBX_cursor, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = icmp ne i32 %30, 2114311601
  br label %32

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

40:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.MDBX_cursor, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !11
  %44 = icmp eq i32 %43, 283285415
  %45 = zext i1 %44 to i64
  %46 = select i1 %44, i32 22, i32 -30420
  store i32 %46, ptr %8, align 4, !tbaa !9
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = call i32 @log_if_error(i32 noundef %47, ptr noundef @__func__.mdbx_cursor_bind, i32 noundef 44)
  store i32 %48, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  br label %226

49:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = call i32 @check_txn(ptr noundef %50, i32 noundef 17)
  store i32 %51, ptr %9, align 4, !tbaa !9
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = icmp ne i32 %52, 0
  %54 = xor i1 %53, true
  %55 = xor i1 %54, true
  %56 = zext i1 %55 to i32
  %57 = sext i32 %56 to i64
  %58 = call i64 @llvm.expect.i64(i64 %57, i64 0)
  %59 = icmp ne i64 %58, 0
  br i1 %59, label %60, label %63

60:                                               ; preds = %49
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = call i32 @log_if_error(i32 noundef %61, ptr noundef @__func__.mdbx_cursor_bind, i32 noundef 49)
  store i32 %62, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %225

63:                                               ; preds = %49
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %66, label %73

66:                                               ; preds = %63
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.MDBX_txn, ptr %67, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !13
  %70 = and i32 %69, 131072
  %71 = icmp ne i32 %70, 0
  %72 = xor i1 %71, true
  br label %73

73:                                               ; preds = %66, %63
  %74 = phi i1 [ false, %63 ], [ %72, %66 ]
  %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 = %73
  %82 = call i32 @log_if_error(i32 noundef 13, ptr noundef @__func__.mdbx_cursor_bind, i32 noundef 52)
  store i32 %82, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %225

83:                                               ; preds = %73
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = load i32, ptr %7, align 4, !tbaa !9
  %86 = zext i32 %85 to i64
  %87 = call i32 @dbi_check(ptr noundef %84, i64 noundef %86)
  store i32 %87, ptr %9, align 4, !tbaa !9
  %88 = load i32, ptr %9, align 4, !tbaa !9
  %89 = icmp ne i32 %88, 0
  %90 = xor i1 %89, true
  %91 = xor i1 %90, true
  %92 = zext i1 %91 to i32
  %93 = sext i32 %92 to i64
  %94 = call i64 @llvm.expect.i64(i64 %93, i64 0)
  %95 = icmp ne i64 %94, 0
  br i1 %95, label %96, label %99

96:                                               ; preds = %83
  %97 = load i32, ptr %9, align 4, !tbaa !9
  %98 = call i32 @log_if_error(i32 noundef %97, ptr noundef @__func__.mdbx_cursor_bind, i32 noundef 56)
  store i32 %98, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %225

99:                                               ; preds = %83
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.MDBX_cursor, ptr %100, i32 0, i32 12
  %102 = load ptr, ptr %101, align 8, !tbaa !19
  %103 = icmp ne ptr %102, null
  %104 = xor i1 %103, true
  %105 = xor i1 %104, true
  %106 = zext i1 %105 to i32
  %107 = sext i32 %106 to i64
  %108 = call i64 @llvm.expect.i64(i64 %107, i64 0)
  %109 = icmp ne i64 %108, 0
  br i1 %109, label %110, label %112

110:                                              ; preds = %99
  %111 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_cursor_bind, i32 noundef 59)
  br label %112

112:                                              ; preds = %110, %99
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = getelementptr inbounds %struct.MDBX_cursor, ptr %113, i32 0, i32 0
  %115 = load i32, ptr %114, align 8, !tbaa !11
  %116 = icmp eq i32 %115, 2114311601
  br i1 %116, label %117, label %150

117:                                              ; preds = %112
  %118 = load ptr, ptr %6, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.MDBX_cursor, ptr %118, i32 0, i32 5
  %120 = load ptr, ptr %119, align 8, !tbaa !20
  %121 = load ptr, ptr %5, align 8, !tbaa !5
  %122 = icmp eq ptr %120, %121
  br i1 %122, label %123, label %130

123:                                              ; preds = %117
  %124 = load ptr, ptr %6, align 8, !tbaa !5
  %125 = call i64 @cursor_dbi(ptr noundef %124) #9
  %126 = load i32, ptr %7, align 4, !tbaa !9
  %127 = zext i32 %126 to i64
  %128 = icmp eq i64 %125, %127
  br i1 %128, label %129, label %130

129:                                              ; preds = %123
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %225

130:                                              ; preds = %123, %117
  %131 = load ptr, ptr %6, align 8, !tbaa !5
  %132 = call i32 @mdbx_cursor_unbind(ptr noundef %131)
  store i32 %132, ptr %9, align 4, !tbaa !9
  %133 = load i32, ptr %9, align 4, !tbaa !9
  %134 = icmp ne i32 %133, 0
  %135 = xor i1 %134, true
  %136 = xor i1 %135, true
  %137 = zext i1 %136 to i32
  %138 = sext i32 %137 to i64
  %139 = call i64 @llvm.expect.i64(i64 %138, i64 0)
  %140 = icmp ne i64 %139, 0
  br i1 %140, label %141, label %149

141:                                              ; preds = %130
  %142 = load i32, ptr %9, align 4, !tbaa !9
  %143 = icmp eq i32 %142, -30782
  br i1 %143, label %144, label %145

144:                                              ; preds = %141
  br label %147

145:                                              ; preds = %141
  %146 = load i32, ptr %9, align 4, !tbaa !9
  br label %147

147:                                              ; preds = %145, %144
  %148 = phi i32 [ 22, %144 ], [ %146, %145 ]
  store i32 %148, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %225

149:                                              ; preds = %130
  br label %150

150:                                              ; preds = %149, %112
  br label %151

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

162:                                              ; preds = %151
  br label %163

163:                                              ; preds = %162
  %164 = load ptr, ptr %6, align 8, !tbaa !5
  %165 = getelementptr inbounds %struct.MDBX_cursor, ptr %164, i32 0, i32 11
  %166 = load ptr, ptr %165, align 8, !tbaa !24
  %167 = load ptr, ptr %6, align 8, !tbaa !5
  %168 = icmp eq ptr %166, %167
  %169 = xor i1 %168, true
  %170 = xor i1 %169, true
  %171 = xor i1 %170, true
  %172 = zext i1 %171 to i32
  %173 = sext i32 %172 to i64
  %174 = call i64 @llvm.expect.i64(i64 %173, i64 0)
  %175 = icmp ne i64 %174, 0
  br i1 %175, label %176, label %182

176:                                              ; preds = %163
  %177 = load ptr, ptr %6, align 8, !tbaa !5
  %178 = getelementptr inbounds %struct.MDBX_cursor, ptr %177, i32 0, i32 5
  %179 = load ptr, ptr %178, align 8, !tbaa !20
  %180 = getelementptr inbounds %struct.MDBX_txn, ptr %179, i32 0, i32 9
  %181 = load ptr, ptr %180, align 8, !tbaa !25
  call void @mdbx_assert_fail(ptr noundef %181, ptr noundef @.str, ptr noundef @__func__.mdbx_cursor_bind, i32 noundef 68) #10
  unreachable

182:                                              ; preds = %163
  br label %183

183:                                              ; preds = %182
  br label %184

184:                                              ; preds = %183
  br label %185

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

186:                                              ; preds = %185
  br label %187

187:                                              ; preds = %186
  %188 = load ptr, ptr %6, align 8, !tbaa !5
  %189 = load ptr, ptr %5, align 8, !tbaa !5
  %190 = load i32, ptr %7, align 4, !tbaa !9
  %191 = zext i32 %190 to i64
  %192 = call i32 @cursor_init(ptr noundef %188, ptr noundef %189, i64 noundef %191)
  store i32 %192, ptr %9, align 4, !tbaa !9
  %193 = load i32, ptr %9, align 4, !tbaa !9
  %194 = icmp ne i32 %193, 0
  %195 = xor i1 %194, true
  %196 = xor i1 %195, true
  %197 = zext i1 %196 to i32
  %198 = sext i32 %197 to i64
  %199 = call i64 @llvm.expect.i64(i64 %198, i64 0)
  %200 = icmp ne i64 %199, 0
  br i1 %200, label %201, label %204

201:                                              ; preds = %187
  %202 = load i32, ptr %9, align 4, !tbaa !9
  %203 = call i32 @log_if_error(i32 noundef %202, ptr noundef @__func__.mdbx_cursor_bind, i32 noundef 72)
  store i32 %203, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %225

204:                                              ; preds = %187
  %205 = load ptr, ptr %5, align 8, !tbaa !5
  %206 = getelementptr inbounds %struct.MDBX_txn, ptr %205, i32 0, i32 14
  %207 = load ptr, ptr %206, align 8, !tbaa !26
  %208 = load i32, ptr %7, align 4, !tbaa !9
  %209 = zext i32 %208 to i64
  %210 = getelementptr inbounds ptr, ptr %207, i64 %209
  %211 = load ptr, ptr %210, align 8, !tbaa !5
  %212 = load ptr, ptr %6, align 8, !tbaa !5
  %213 = getelementptr inbounds %struct.MDBX_cursor, ptr %212, i32 0, i32 11
  store ptr %211, ptr %213, align 8, !tbaa !24
  %214 = load ptr, ptr %6, align 8, !tbaa !5
  %215 = load ptr, ptr %5, align 8, !tbaa !5
  %216 = getelementptr inbounds %struct.MDBX_txn, ptr %215, i32 0, i32 14
  %217 = load ptr, ptr %216, align 8, !tbaa !26
  %218 = load i32, ptr %7, align 4, !tbaa !9
  %219 = zext i32 %218 to i64
  %220 = getelementptr inbounds ptr, ptr %217, i64 %219
  store ptr %214, ptr %220, align 8, !tbaa !5
  %221 = load ptr, ptr %5, align 8, !tbaa !5
  %222 = getelementptr inbounds %struct.MDBX_txn, ptr %221, i32 0, i32 1
  %223 = load i32, ptr %222, align 4, !tbaa !13
  %224 = or i32 %223, 256
  store i32 %224, ptr %222, align 4, !tbaa !13
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %225

225:                                              ; preds = %204, %201, %147, %129, %96, %81, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  br label %226

226:                                              ; preds = %225, %40, %20
  %227 = load i32, ptr %4, align 4
  ret i32 %227
}

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @check_txn(ptr noundef, i32 noundef) #4

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mdbx_cursor_unbind(ptr noundef) #2

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

declare i32 @cursor_init(ptr noundef, ptr noundef, i64 noundef) #7

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { 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 #4 = { 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 #5 = { 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 #6 = { noreturn "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #7 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(read) }
attributes #10 = { 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 = !{!12, !10, i64 0}
!12 = !{!"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}
!13 = !{!14, !10, i64 4}
!14 = !{!"MDBX_txn", !10, i64 0, !10, i64 4, !15, i64 8, !15, i64 16, !6, i64 24, !6, i64 32, !16, i64 40, !15, i64 64, !15, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !18, i64 128, !6, i64 160, !7, i64 168}
!15 = !{!"long", !7, i64 0}
!16 = !{!"geo", !17, i64 0, !17, i64 2, !10, i64 4, !10, i64 8, !7, i64 12, !7, i64 16}
!17 = !{!"short", !7, i64 0}
!18 = !{!"MDBX_canary", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24}
!19 = !{!12, !6, i64 376}
!20 = !{!12, !6, i64 16}
!21 = !{!22, !7, i64 25}
!22 = !{!"libmdbx_globals", !7, i64 0, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !23, i64 27, !10, i64 28, !7, i64 32, !7, i64 40, !15, i64 80, !6, i64 88}
!23 = !{!"_Bool", !7, i64 0}
!24 = !{!12, !6, i64 368}
!25 = !{!14, !6, i64 80}
!26 = !{!14, !6, i64 120}


; 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.16 }
%struct.anon.16 = 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 }

@__func__.mdbx_cursor_bind = external hidden unnamed_addr constant [17 x i8], align 1
@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [15 x i8], align 1

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

4:                                                ; preds = %3
  %5 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_cursor_bind, i32 noundef 40)
  br label %72

6:                                                ; preds = %3
  %7 = load i32, ptr %1, align 8, !tbaa !6
  switch i32 %7, label %8 [
    i32 2114311601, label %12
    i32 672636999, label %12
  ]

8:                                                ; preds = %6
  %9 = icmp eq i32 %7, 283285415
  %10 = select i1 %9, i32 22, i32 -30420
  %11 = tail call i32 @log_if_error(i32 noundef %10, ptr noundef nonnull @__func__.mdbx_cursor_bind, i32 noundef 44)
  br label %72

12:                                               ; preds = %6, %6
  %13 = tail call i32 @check_txn(ptr noundef %0, i32 noundef 17)
  %.not45 = icmp eq i32 %13, 0
  br i1 %.not45, label %16, label %14, !prof !12

14:                                               ; preds = %12
  %15 = tail call i32 @log_if_error(i32 noundef %13, ptr noundef nonnull @__func__.mdbx_cursor_bind, i32 noundef 49)
  br label %72

16:                                               ; preds = %12
  %17 = icmp eq i32 %2, 0
  br i1 %17, label %18, label %.critedge

18:                                               ; preds = %16
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = and i32 %20, 131072
  %.not46 = icmp eq i32 %21, 0
  br i1 %.not46, label %22, label %.critedge, !prof !5

22:                                               ; preds = %18
  %23 = tail call i32 @log_if_error(i32 noundef 13, ptr noundef nonnull @__func__.mdbx_cursor_bind, i32 noundef 52)
  br label %72

.critedge:                                        ; preds = %16, %18
  %24 = zext i32 %2 to i64
  %25 = tail call i32 @dbi_check(ptr noundef %0, i64 noundef %24)
  %.not47 = icmp eq i32 %25, 0
  br i1 %.not47, label %28, label %26, !prof !12

26:                                               ; preds = %.critedge
  %27 = tail call i32 @log_if_error(i32 noundef %25, ptr noundef nonnull @__func__.mdbx_cursor_bind, i32 noundef 56)
  br label %72

28:                                               ; preds = %.critedge
  %29 = getelementptr inbounds i8, ptr %1, i64 376
  %30 = load ptr, ptr %29, align 8, !tbaa !19
  %.not48 = icmp eq ptr %30, null
  br i1 %.not48, label %33, label %31, !prof !12

31:                                               ; preds = %28
  %32 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_cursor_bind, i32 noundef 59)
  br label %33

33:                                               ; preds = %31, %28
  %34 = load i32, ptr %1, align 8, !tbaa !6
  %35 = icmp eq i32 %34, 2114311601
  br i1 %35, label %36, label %48

36:                                               ; preds = %33
  %37 = getelementptr inbounds i8, ptr %1, i64 16
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  %39 = icmp eq ptr %38, %0
  br i1 %39, label %40, label %43

40:                                               ; preds = %36
  %41 = tail call i64 @cursor_dbi(ptr noundef nonnull %1) #6
  %42 = icmp eq i64 %41, %24
  br i1 %42, label %72, label %43

43:                                               ; preds = %40, %36
  %44 = tail call i32 @mdbx_cursor_unbind(ptr noundef nonnull %1)
  %.not49 = icmp eq i32 %44, 0
  br i1 %.not49, label %48, label %45, !prof !12

45:                                               ; preds = %43
  %46 = icmp eq i32 %44, -30782
  %47 = select i1 %46, i32 22, i32 %44
  br label %72

48:                                               ; preds = %33, %43
  %49 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !21
  %50 = and i8 %49, 1
  %.not50 = icmp eq i8 %50, 0
  br i1 %.not50, label %59, label %51, !prof !5

51:                                               ; preds = %48
  %52 = getelementptr inbounds i8, ptr %1, i64 368
  %53 = load ptr, ptr %52, align 8, !tbaa !24
  %.not51 = icmp eq ptr %53, %1
  br i1 %.not51, label %59, label %54, !prof !12

54:                                               ; preds = %51
  %55 = getelementptr inbounds i8, ptr %1, i64 16
  %56 = load ptr, ptr %55, align 8, !tbaa !20
  %57 = getelementptr inbounds i8, ptr %56, i64 80
  %58 = load ptr, ptr %57, align 8, !tbaa !25
  tail call void @mdbx_assert_fail(ptr noundef %58, ptr noundef nonnull @.str, ptr noundef nonnull @__func__.mdbx_cursor_bind, i32 noundef 68) #7
  unreachable

59:                                               ; preds = %51, %48
  %60 = tail call i32 @cursor_init(ptr noundef nonnull %1, ptr noundef %0, i64 noundef %24) #8
  %.not52 = icmp eq i32 %60, 0
  br i1 %.not52, label %63, label %61, !prof !12

61:                                               ; preds = %59
  %62 = tail call i32 @log_if_error(i32 noundef %60, ptr noundef nonnull @__func__.mdbx_cursor_bind, i32 noundef 72)
  br label %72

63:                                               ; preds = %59
  %64 = getelementptr inbounds i8, ptr %0, i64 120
  %65 = load ptr, ptr %64, align 8, !tbaa !26
  %66 = getelementptr inbounds ptr, ptr %65, i64 %24
  %67 = load ptr, ptr %66, align 8, !tbaa !27
  %68 = getelementptr inbounds i8, ptr %1, i64 368
  store ptr %67, ptr %68, align 8, !tbaa !24
  store ptr %1, ptr %66, align 8, !tbaa !27
  %69 = getelementptr inbounds i8, ptr %0, i64 4
  %70 = load i32, ptr %69, align 4, !tbaa !13
  %71 = or i32 %70, 256
  store i32 %71, ptr %69, align 4, !tbaa !13
  br label %72

72:                                               ; preds = %14, %22, %26, %45, %61, %63, %40, %8, %4
  %.1 = phi i32 [ %5, %4 ], [ %11, %8 ], [ %15, %14 ], [ %23, %22 ], [ %27, %26 ], [ %47, %45 ], [ %62, %61 ], [ 0, %63 ], [ 0, %40 ]
  ret i32 %.1
}

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mdbx_cursor_unbind(ptr noundef) local_unnamed_addr #0

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

declare i32 @cursor_init(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #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 = { 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 = { 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 = { 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 = { noreturn "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { "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 willreturn memory(read) }
attributes #7 = { noreturn nounwind }
attributes #8 = { 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 1, i32 2000}
!6 = !{!7, !8, i64 0}
!7 = !{!"MDBX_cursor", !8, i64 0, !9, i64 4, !9, i64 6, !9, i64 7, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !9, i64 48, !9, i64 304, !11, i64 368, !11, i64 376}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!13 = !{!14, !8, i64 4}
!14 = !{!"MDBX_txn", !8, i64 0, !8, i64 4, !15, i64 8, !15, i64 16, !11, i64 24, !11, i64 32, !16, i64 40, !15, i64 64, !15, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !18, i64 128, !11, i64 160, !9, i64 168}
!15 = !{!"long", !9, i64 0}
!16 = !{!"geo", !17, i64 0, !17, i64 2, !8, i64 4, !8, i64 8, !9, i64 12, !9, i64 16}
!17 = !{!"short", !9, i64 0}
!18 = !{!"MDBX_canary", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24}
!19 = !{!7, !11, i64 376}
!20 = !{!7, !11, i64 16}
!21 = !{!22, !9, i64 25}
!22 = !{!"libmdbx_globals", !9, i64 0, !8, i64 16, !8, i64 20, !9, i64 24, !9, i64 25, !9, i64 26, !23, i64 27, !8, i64 28, !9, i64 32, !9, i64 40, !15, i64 80, !11, i64 88}
!23 = !{!"_Bool", !9, i64 0}
!24 = !{!7, !11, i64 368}
!25 = !{!14, !11, i64 80}
!26 = !{!14, !11, i64 120}
!27 = !{!11, !11, i64 0}


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