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

; 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.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.1, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i64, %struct.anon.2, %struct.anon.6, i8, ptr, ptr, ptr, %struct.anon.7, %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.1 = type { ptr, ptr, ptr, ptr }
%struct.anon.2 = type { i32, i32, i32, i32, i64, i8, i8, i8, i8, i32, i32, i8, i8, i8, %struct.anon.3, %union.anon.4 }
%struct.anon.3 = type { i16, i16, i16, i16 }
%union.anon.4 = type { i32 }
%struct.anon.6 = type { i64, i64, i64, i64, i64 }
%struct.anon.7 = 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.10, %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.8 }
%struct.anon.8 = 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.9 }
%struct.anon.9 = type { i64, i64, i32 }
%struct.anon.10 = 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 }

@__func__.mdbx_env_create = external hidden unnamed_addr constant [16 x i8], align 1
@globals = external global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_env_create(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, 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 %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  %10 = xor i1 %9, true
  %11 = xor i1 %10, true
  %12 = xor i1 %11, true
  %13 = zext i1 %12 to i32
  %14 = sext i32 %13 to i64
  %15 = call i64 @llvm.expect.i64(i64 %14, i64 0)
  %16 = icmp ne i64 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %1
  %18 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_env_create, i32 noundef 189)
  store i32 %18, ptr %2, align 4
  br label %188

19:                                               ; preds = %1
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr null, ptr %20, align 8, !tbaa !5
  %21 = load i32, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 1), align 8, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = call zeroext i1 @is_powerof2(i64 noundef %22) #8
  br i1 %23, label %24, label %27

24:                                               ; preds = %19
  %25 = load i32, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 1), align 8, !tbaa !9
  %26 = icmp ult i32 %25, 256
  br label %27

27:                                               ; preds = %24, %19
  %28 = phi i1 [ true, %19 ], [ %26, %24 ]
  %29 = xor i1 %28, true
  %30 = xor i1 %29, true
  %31 = zext i1 %30 to i32
  %32 = sext i32 %31 to i64
  %33 = call i64 @llvm.expect.i64(i64 %32, i64 0)
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %51

35:                                               ; preds = %27
  br label %36

36:                                               ; preds = %35
  %37 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !14
  %38 = zext i8 %37 to i32
  %39 = icmp sle i32 1, %38
  %40 = xor i1 %39, true
  %41 = xor i1 %40, true
  %42 = zext i1 %41 to i32
  %43 = sext i32 %42 to i64
  %44 = call i64 @llvm.expect.i64(i64 %43, i64 0)
  %45 = icmp ne i64 %44, 0
  br i1 %45, label %46, label %48

46:                                               ; preds = %36
  %47 = load i32, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 1), align 8, !tbaa !9
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.mdbx_env_create, i32 noundef 206, ptr noundef @.str, i32 noundef %47)
  br label %48

48:                                               ; preds = %46, %36
  br label %49

49:                                               ; preds = %48
  %50 = call i32 @log_if_error(i32 noundef -30784, ptr noundef @__func__.mdbx_env_create, i32 noundef 207)
  store i32 %50, ptr %2, align 4
  br label %188

51:                                               ; preds = %27
  %52 = load i32, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 7), align 4, !tbaa !15
  %53 = icmp ult i32 %52, 67108864
  %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 %85

60:                                               ; preds = %51
  br label %61

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

71:                                               ; preds = %61
  %72 = load i32, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 7), align 4, !tbaa !15
  %73 = lshr i32 %72, 24
  %74 = load i32, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 7), align 4, !tbaa !15
  %75 = lshr i32 %74, 16
  %76 = and i32 %75, 255
  %77 = load i32, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 7), align 4, !tbaa !15
  %78 = lshr i32 %77, 8
  %79 = and i32 %78, 255
  %80 = load i32, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 7), align 4, !tbaa !15
  %81 = and i32 %80, 255
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef @__func__.mdbx_env_create, i32 noundef 216, ptr noundef @.str.1, i32 noundef %73, i32 noundef %76, i32 noundef %79, i32 noundef %81)
  br label %82

82:                                               ; preds = %71, %61
  br label %83

83:                                               ; preds = %82
  %84 = call i32 @log_if_error(i32 noundef -30784, ptr noundef @__func__.mdbx_env_create, i32 noundef 217)
  store i32 %84, ptr %2, align 4
  br label %188

85:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #9
  %86 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 1104) #10
  store ptr %86, ptr %4, align 8, !tbaa !5
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = icmp ne ptr %87, null
  %89 = xor i1 %88, true
  %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 %98

96:                                               ; preds = %85
  %97 = call i32 @log_if_error(i32 noundef 12, ptr noundef @__func__.mdbx_env_create, i32 noundef 223)
  store i32 %97, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %187

98:                                               ; preds = %85
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.MDBX_env, ptr %99, i32 0, i32 18
  store i32 61, ptr %100, align 4, !tbaa !16
  %101 = load ptr, ptr %4, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.MDBX_env, ptr %101, i32 0, i32 42
  store i32 2, ptr %102, align 8, !tbaa !26
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.MDBX_env, ptr %103, i32 0, i32 19
  store i32 2, ptr %104, align 8, !tbaa !27
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.MDBX_env, ptr %105, i32 0, i32 6
  %107 = getelementptr inbounds %struct.osal_mmap, ptr %106, i32 0, i32 1
  store i32 -1, ptr %107, align 8, !tbaa !28
  %108 = load ptr, ptr %4, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.MDBX_env, ptr %108, i32 0, i32 5
  store i32 -1, ptr %109, align 4, !tbaa !29
  %110 = load ptr, ptr %4, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.MDBX_env, ptr %110, i32 0, i32 4
  store i32 -1, ptr %111, align 8, !tbaa !30
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.MDBX_env, ptr %112, i32 0, i32 3
  %114 = getelementptr inbounds %struct.osal_mmap, ptr %113, i32 0, i32 1
  store i32 -1, ptr %114, align 8, !tbaa !31
  %115 = load ptr, ptr %4, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.MDBX_env, ptr %115, i32 0, i32 16
  store i8 -1, ptr %116, align 1, !tbaa !32
  %117 = load ptr, ptr %4, align 8, !tbaa !5
  call void @env_options_init(ptr noundef %117)
  %118 = load ptr, ptr %4, align 8, !tbaa !5
  %119 = load i32, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 1), align 8, !tbaa !9
  %120 = icmp ult i32 %119, 65536
  br i1 %120, label %121, label %123

121:                                              ; preds = %98
  %122 = load i32, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 1), align 8, !tbaa !9
  br label %124

123:                                              ; preds = %98
  br label %124

124:                                              ; preds = %123, %121
  %125 = phi i32 [ %122, %121 ], [ 65536, %123 ]
  %126 = zext i32 %125 to i64
  %127 = call i32 @env_setup_pagesize(ptr noundef %118, i64 noundef %126)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #9
  %128 = load ptr, ptr %4, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.MDBX_env, ptr %128, i32 0, i32 41
  %130 = call i32 @osal_fastmutex_init(ptr noundef %129)
  store i32 %130, ptr %6, align 4, !tbaa !33
  %131 = load i32, ptr %6, align 4, !tbaa !33
  %132 = icmp ne i32 %131, 0
  %133 = xor i1 %132, true
  %134 = xor i1 %133, true
  %135 = zext i1 %134 to i32
  %136 = sext i32 %135 to i64
  %137 = call i64 @llvm.expect.i64(i64 %136, i64 0)
  %138 = icmp ne i64 %137, 0
  br i1 %138, label %139, label %140

139:                                              ; preds = %124
  br label %182

140:                                              ; preds = %124
  %141 = load ptr, ptr %4, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct.MDBX_env, ptr %141, i32 0, i32 46
  %143 = call i32 @osal_fastmutex_init(ptr noundef %142)
  store i32 %143, ptr %6, align 4, !tbaa !33
  %144 = load i32, ptr %6, align 4, !tbaa !33
  %145 = icmp ne i32 %144, 0
  %146 = xor i1 %145, true
  %147 = xor i1 %146, true
  %148 = zext i1 %147 to i32
  %149 = sext i32 %148 to i64
  %150 = call i64 @llvm.expect.i64(i64 %149, i64 0)
  %151 = icmp ne i64 %150, 0
  br i1 %151, label %152, label %156

152:                                              ; preds = %140
  %153 = load ptr, ptr %4, align 8, !tbaa !5
  %154 = getelementptr inbounds %struct.MDBX_env, ptr %153, i32 0, i32 41
  %155 = call i32 @osal_fastmutex_destroy(ptr noundef %154)
  br label %182

156:                                              ; preds = %140
  %157 = load ptr, ptr %4, align 8, !tbaa !5
  %158 = call ptr @lckless_stub(ptr noundef %157) #8
  store ptr %158, ptr %7, align 8, !tbaa !5
  %159 = load ptr, ptr %7, align 8, !tbaa !5
  %160 = getelementptr inbounds %struct.shared_lck, ptr %159, i32 0, i32 11
  %161 = call i32 @lck_ipclock_stubinit(ptr noundef %160)
  store i32 %161, ptr %6, align 4, !tbaa !33
  %162 = load i32, ptr %6, align 4, !tbaa !33
  %163 = icmp ne i32 %162, 0
  %164 = xor i1 %163, true
  %165 = xor i1 %164, true
  %166 = zext i1 %165 to i32
  %167 = sext i32 %166 to i64
  %168 = call i64 @llvm.expect.i64(i64 %167, i64 0)
  %169 = icmp ne i64 %168, 0
  br i1 %169, label %170, label %177

170:                                              ; preds = %156
  %171 = load ptr, ptr %4, align 8, !tbaa !5
  %172 = getelementptr inbounds %struct.MDBX_env, ptr %171, i32 0, i32 46
  %173 = call i32 @osal_fastmutex_destroy(ptr noundef %172)
  %174 = load ptr, ptr %4, align 8, !tbaa !5
  %175 = getelementptr inbounds %struct.MDBX_env, ptr %174, i32 0, i32 41
  %176 = call i32 @osal_fastmutex_destroy(ptr noundef %175)
  br label %182

177:                                              ; preds = %156
  %178 = load ptr, ptr %4, align 8, !tbaa !5
  %179 = getelementptr inbounds %struct.MDBX_env, ptr %178, i32 0, i32 0
  store volatile i32 445224513, ptr %179, align 8, !tbaa !34
  %180 = load ptr, ptr %4, align 8, !tbaa !5
  %181 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %180, ptr %181, align 8, !tbaa !5
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %186

182:                                              ; preds = %170, %152, %139
  %183 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %183) #9
  %184 = load i32, ptr %6, align 4, !tbaa !33
  %185 = call i32 @log_if_error(i32 noundef %184, ptr noundef @__func__.mdbx_env_create, i32 noundef 265)
  store i32 %185, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %186

186:                                              ; preds = %182, %177
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #9
  br label %187

187:                                              ; preds = %186, %96
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #9
  br label %188

188:                                              ; preds = %187, %83, %49, %17
  %189 = load i32, ptr %2, align 4
  ret i32 %189
}

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

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

; Function Attrs: inlinehint nounwind willreturn memory(none) uwtable
declare hidden zeroext i1 @is_powerof2(i64 noundef) #3

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.start.p0(i64 immarg, ptr nocapture) #5

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #6

declare void @env_options_init(ptr noundef) #4

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

declare i32 @osal_fastmutex_init(ptr noundef) #4

declare i32 @osal_fastmutex_destroy(ptr noundef) #4

; Function Attrs: inlinehint nounwind willreturn memory(none) uwtable
declare hidden ptr @lckless_stub(ptr noundef) #3

declare i32 @lck_ipclock_stubinit(ptr noundef) #4

; Function Attrs: nounwind
declare void @free(ptr noundef) #7

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { 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 #3 = { inlinehint nounwind willreturn memory(none) 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(argmem: readwrite) }
attributes #6 = { nounwind allocsize(0,1) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #7 = { nounwind "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 willreturn memory(none) }
attributes #9 = { nounwind }
attributes #10 = { nounwind allocsize(0,1) }

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 16}
!10 = !{!"libmdbx_globals", !7, i64 0, !11, i64 16, !11, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !12, i64 27, !11, i64 28, !7, i64 32, !7, i64 40, !13, i64 80, !6, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !7, i64 26}
!15 = !{!10, !11, i64 28}
!16 = !{!17, !11, i64 132}
!17 = !{!"MDBX_env", !7, i64 0, !11, i64 4, !11, i64 8, !18, i64 16, !11, i64 56, !11, i64 60, !18, i64 64, !6, 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, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !20, i64 152, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !11, i64 224, !11, i64 228, !11, i64 232, !6, i64 240, !6, i64 248, !13, i64 256, !21, i64 264, !23, i64 320, !12, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !24, i64 392, !7, i64 400, !11, i64 440, !11, i64 444, !6, i64 448, !25, i64 456, !7, i64 496, !7, i64 536}
!18 = !{!"osal_mmap", !7, i64 0, !11, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!19 = !{!"short", !7, i64 0}
!20 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!21 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !13, i64 16, !7, i64 24, !7, i64 25, !7, i64 26, !7, i64 27, !11, i64 28, !11, i64 32, !12, i64 36, !12, i64 37, !12, i64 38, !22, i64 40, !7, i64 48}
!22 = !{!"", !19, i64 0, !19, i64 2, !19, i64 4, !19, i64 6}
!23 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!24 = !{!"", !13, i64 0}
!25 = !{!"osal_ioring", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!26 = !{!17, !11, i64 440}
!27 = !{!17, !11, i64 136}
!28 = !{!17, !11, i64 72}
!29 = !{!17, !11, i64 60}
!30 = !{!17, !11, i64 56}
!31 = !{!17, !11, i64 24}
!32 = !{!17, !7, i64 129}
!33 = !{!11, !11, i64 0}
!34 = !{!7, !7, i64 0}


; 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 }

@__func__.mdbx_env_create = external hidden unnamed_addr constant [16 x i8], align 1
@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [31 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1

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

2:                                                ; preds = %1
  %3 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_env_create, i32 noundef 189)
  br label %60

4:                                                ; preds = %1
  store ptr null, ptr %0, align 8, !tbaa !6
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @globals, i64 16), align 8
  %6 = zext i32 %5 to i64
  %7 = tail call zeroext i1 @is_powerof2(i64 noundef %6) #7
  %8 = icmp ugt i32 %5, 255
  %.not34 = and i1 %8, %7
  br i1 %.not34, label %14, label %9, !prof !10

9:                                                ; preds = %4
  %10 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !11
  %.not40 = icmp eq i8 %10, 0
  br i1 %.not40, label %12, label %11, !prof !10

11:                                               ; preds = %9
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.mdbx_env_create, i32 noundef 206, ptr noundef nonnull @.str, i32 noundef %5) #8
  br label %12

12:                                               ; preds = %9, %11
  %13 = tail call i32 @log_if_error(i32 noundef -30784, ptr noundef nonnull @__func__.mdbx_env_create, i32 noundef 207)
  br label %60

14:                                               ; preds = %4
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @globals, i64 28), align 4, !tbaa !16
  %16 = icmp ult i32 %15, 67108864
  br i1 %16, label %17, label %28, !prof !5

17:                                               ; preds = %14
  %18 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !11
  %.not39 = icmp eq i8 %18, 0
  br i1 %.not39, label %26, label %19, !prof !10

19:                                               ; preds = %17
  %20 = lshr i32 %15, 24
  %21 = lshr i32 %15, 16
  %22 = and i32 %21, 255
  %23 = lshr i32 %15, 8
  %24 = and i32 %23, 255
  %25 = and i32 %15, 255
  tail call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 1, ptr noundef nonnull @__func__.mdbx_env_create, i32 noundef 216, ptr noundef nonnull @.str.1, i32 noundef %20, i32 noundef %22, i32 noundef %24, i32 noundef %25) #8
  br label %26

26:                                               ; preds = %17, %19
  %27 = tail call i32 @log_if_error(i32 noundef -30784, ptr noundef nonnull @__func__.mdbx_env_create, i32 noundef 217)
  br label %60

28:                                               ; preds = %14
  %29 = tail call noalias dereferenceable_or_null(1104) ptr @calloc(i64 noundef 1, i64 noundef 1104) #9
  %.not35 = icmp eq ptr %29, null
  br i1 %.not35, label %30, label %32, !prof !5

30:                                               ; preds = %28
  %31 = tail call i32 @log_if_error(i32 noundef 12, ptr noundef nonnull @__func__.mdbx_env_create, i32 noundef 223)
  br label %60

32:                                               ; preds = %28
  %33 = getelementptr inbounds i8, ptr %29, i64 132
  store i32 61, ptr %33, align 4, !tbaa !17
  %34 = getelementptr inbounds i8, ptr %29, i64 440
  store i32 2, ptr %34, align 8, !tbaa !27
  %35 = getelementptr inbounds i8, ptr %29, i64 136
  store i32 2, ptr %35, align 8, !tbaa !28
  %36 = getelementptr inbounds i8, ptr %29, i64 72
  store i32 -1, ptr %36, align 8, !tbaa !29
  %37 = getelementptr inbounds i8, ptr %29, i64 60
  store i32 -1, ptr %37, align 4, !tbaa !30
  %38 = getelementptr inbounds i8, ptr %29, i64 56
  store i32 -1, ptr %38, align 8, !tbaa !31
  %39 = getelementptr inbounds i8, ptr %29, i64 24
  store i32 -1, ptr %39, align 8, !tbaa !32
  %40 = getelementptr inbounds i8, ptr %29, i64 129
  store i8 -1, ptr %40, align 1, !tbaa !33
  tail call void @env_options_init(ptr noundef nonnull %29) #8
  %41 = load i32, ptr getelementptr inbounds (i8, ptr @globals, i64 16), align 8
  %42 = tail call i32 @llvm.umin.i32(i32 %41, i32 65536)
  %43 = zext nneg i32 %42 to i64
  %44 = tail call i32 @env_setup_pagesize(ptr noundef nonnull %29, i64 noundef %43) #8
  %45 = getelementptr inbounds i8, ptr %29, i64 400
  %46 = tail call i32 @osal_fastmutex_init(ptr noundef nonnull %45) #8
  %.not36 = icmp eq i32 %46, 0
  br i1 %.not36, label %47, label %58, !prof !10

47:                                               ; preds = %32
  %48 = getelementptr inbounds i8, ptr %29, i64 496
  %49 = tail call i32 @osal_fastmutex_init(ptr noundef nonnull %48) #8
  %.not37 = icmp eq i32 %49, 0
  br i1 %.not37, label %50, label %.sink.split, !prof !10

50:                                               ; preds = %47
  %51 = tail call ptr @lckless_stub(ptr noundef nonnull %29) #7
  %52 = getelementptr inbounds i8, ptr %51, i64 320
  %53 = tail call i32 @lck_ipclock_stubinit(ptr noundef nonnull %52) #8
  %.not38 = icmp eq i32 %53, 0
  br i1 %.not38, label %56, label %54, !prof !10

54:                                               ; preds = %50
  %55 = tail call i32 @osal_fastmutex_destroy(ptr noundef nonnull %48) #8
  br label %.sink.split

56:                                               ; preds = %50
  store volatile i32 445224513, ptr %29, align 8, !tbaa !34
  store ptr %29, ptr %0, align 8, !tbaa !6
  br label %60

.sink.split:                                      ; preds = %47, %54
  %.028.ph = phi i32 [ %53, %54 ], [ %49, %47 ]
  %57 = tail call i32 @osal_fastmutex_destroy(ptr noundef nonnull %45) #8
  br label %58

58:                                               ; preds = %.sink.split, %32
  %.028 = phi i32 [ %46, %32 ], [ %.028.ph, %.sink.split ]
  tail call void @free(ptr noundef nonnull %29) #8
  %59 = tail call i32 @log_if_error(i32 noundef %.028, ptr noundef nonnull @__func__.mdbx_env_create, i32 noundef 265)
  br label %60

60:                                               ; preds = %30, %58, %56, %26, %12, %2
  %.2 = phi i32 [ %3, %2 ], [ %13, %12 ], [ %27, %26 ], [ %31, %30 ], [ %59, %58 ], [ 0, %56 ]
  ret i32 %.2
}

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

; Function Attrs: inlinehint mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare hidden zeroext i1 @is_powerof2(i64 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #4

declare void @env_options_init(ptr noundef) local_unnamed_addr #3

declare i32 @env_setup_pagesize(ptr noundef, i64 noundef) local_unnamed_addr #3

declare i32 @osal_fastmutex_init(ptr noundef) local_unnamed_addr #3

declare i32 @osal_fastmutex_destroy(ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare hidden ptr @lckless_stub(ptr noundef) local_unnamed_addr #2

declare i32 @lck_ipclock_stubinit(ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #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 = { 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 = { inlinehint mustprogress nofree nosync nounwind willreturn memory(none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { nounwind willreturn memory(none) }
attributes #8 = { nounwind }
attributes #9 = { nounwind allocsize(0,1) }

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


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