; 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.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.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 }
%union.mdbx_atomic_uint64_t = type { i64 }

@__func__.mdbx_env_delete = external hidden unnamed_addr constant [16 x i8], align 1

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

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

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

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

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

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_env_delete(ptr noundef %0, i32 noundef %1) #4 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %struct.MDBX_env, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %12 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %12, label %13 [
    i32 0, label %15
    i32 1, label %15
    i32 2, label %15
  ]

13:                                               ; preds = %2
  %14 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_env_delete, i32 noundef 353)
  store i32 %14, ptr %3, align 4
  br label %214

15:                                               ; preds = %2, %2, %2
  br label %16

16:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 1104, ptr %6) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #8
  store ptr %6, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %17, i8 0, i64 1104, i1 false)
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 1
  %20 = zext i1 %19 to i64
  %21 = select i1 %19, i32 4194304, i32 0
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.MDBX_env, ptr %22, i32 0, i32 1
  store i32 %21, ptr %23, align 4, !tbaa !11
  %24 = call i64 @mdbx_default_pagesize() #9
  %25 = trunc i64 %24 to i32
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.MDBX_env, ptr %26, i32 0, i32 2
  store i32 %25, ptr %27, align 8, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  store i32 -1, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i32 @env_handle_pathname(ptr noundef %28, ptr noundef %29, i32 noundef 0) #10
  store i32 %30, ptr %9, align 4, !tbaa !9
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 0
  %33 = xor i1 %32, true
  %34 = xor i1 %33, true
  %35 = zext i1 %34 to i32
  %36 = sext i32 %35 to i64
  %37 = call i64 @llvm.expect.i64(i64 %36, i64 1)
  %38 = icmp ne i64 %37, 0
  br i1 %38, label %39, label %195

39:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #8
  store i32 -1, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #8
  store i32 -1, ptr %11, align 4, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = icmp ugt i32 %40, 0
  br i1 %41, label %42, label %95

42:                                               ; preds = %39
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.MDBX_env, ptr %44, i32 0, i32 22
  %46 = getelementptr inbounds %struct.anon.1, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !24
  %48 = call i32 @osal_openfile(i32 noundef 5, ptr noundef %43, ptr noundef %47, ptr noundef %11, i32 noundef 0)
  store i32 %48, ptr %9, align 4, !tbaa !9
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = icmp eq i32 %49, 2
  br i1 %50, label %51, label %52

51:                                               ; preds = %42
  br label %54

52:                                               ; preds = %42
  %53 = load i32, ptr %9, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %52, %51
  %55 = phi i32 [ 0, %51 ], [ %53, %52 ]
  store i32 %55, ptr %9, align 4, !tbaa !9
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %72

58:                                               ; preds = %54
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MDBX_env, ptr %60, i32 0, i32 22
  %62 = getelementptr inbounds %struct.anon.1, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !25
  %64 = call i32 @osal_openfile(i32 noundef 5, ptr noundef %59, ptr noundef %63, ptr noundef %10, i32 noundef 0)
  store i32 %64, ptr %9, align 4, !tbaa !9
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = icmp eq i32 %65, 2
  br i1 %66, label %67, label %68

67:                                               ; preds = %58
  br label %70

68:                                               ; preds = %58
  %69 = load i32, ptr %9, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %68, %67
  %71 = phi i32 [ 0, %67 ], [ %69, %68 ]
  store i32 %71, ptr %9, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %70, %54
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = icmp eq i32 %73, 0
  br i1 %74, label %75, label %83

75:                                               ; preds = %72
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = icmp ne i32 %76, -1
  br i1 %77, label %78, label %83

78:                                               ; preds = %75
  %79 = load i32, ptr %10, align 4, !tbaa !9
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = icmp eq i32 %80, 2
  %82 = call i32 @osal_lockfile(i32 noundef %79, i1 noundef zeroext %81)
  store i32 %82, ptr %9, align 4, !tbaa !9
  br label %83

83:                                               ; preds = %78, %75, %72
  %84 = load i32, ptr %9, align 4, !tbaa !9
  %85 = icmp eq i32 %84, 0
  br i1 %85, label %86, label %94

86:                                               ; preds = %83
  %87 = load i32, ptr %11, align 4, !tbaa !9
  %88 = icmp ne i32 %87, -1
  br i1 %88, label %89, label %94

89:                                               ; preds = %86
  %90 = load i32, ptr %11, align 4, !tbaa !9
  %91 = load i32, ptr %5, align 4, !tbaa !9
  %92 = icmp eq i32 %91, 2
  %93 = call i32 @osal_lockfile(i32 noundef %90, i1 noundef zeroext %92)
  store i32 %93, ptr %9, align 4, !tbaa !9
  br label %94

94:                                               ; preds = %89, %86, %83
  br label %95

95:                                               ; preds = %94, %39
  %96 = load i32, ptr %9, align 4, !tbaa !9
  %97 = icmp eq i32 %96, 0
  br i1 %97, label %98, label %113

98:                                               ; preds = %95
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.MDBX_env, ptr %99, i32 0, i32 22
  %101 = getelementptr inbounds %struct.anon.1, ptr %100, i32 0, i32 1
  %102 = load ptr, ptr %101, align 8, !tbaa !24
  %103 = call i32 @osal_removefile(ptr noundef %102)
  store i32 %103, ptr %9, align 4, !tbaa !9
  %104 = load i32, ptr %9, align 4, !tbaa !9
  %105 = icmp eq i32 %104, 0
  br i1 %105, label %106, label %107

106:                                              ; preds = %98
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %112

107:                                              ; preds = %98
  %108 = load i32, ptr %9, align 4, !tbaa !9
  %109 = icmp eq i32 %108, 2
  br i1 %109, label %110, label %111

110:                                              ; preds = %107
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %111

111:                                              ; preds = %110, %107
  br label %112

112:                                              ; preds = %111, %106
  br label %113

113:                                              ; preds = %112, %95
  %114 = load i32, ptr %9, align 4, !tbaa !9
  %115 = icmp eq i32 %114, 0
  br i1 %115, label %116, label %131

116:                                              ; preds = %113
  %117 = load ptr, ptr %7, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.MDBX_env, ptr %117, i32 0, i32 22
  %119 = getelementptr inbounds %struct.anon.1, ptr %118, i32 0, i32 0
  %120 = load ptr, ptr %119, align 8, !tbaa !25
  %121 = call i32 @osal_removefile(ptr noundef %120)
  store i32 %121, ptr %9, align 4, !tbaa !9
  %122 = load i32, ptr %9, align 4, !tbaa !9
  %123 = icmp eq i32 %122, 0
  br i1 %123, label %124, label %125

124:                                              ; preds = %116
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %130

125:                                              ; preds = %116
  %126 = load i32, ptr %9, align 4, !tbaa !9
  %127 = icmp eq i32 %126, 2
  br i1 %127, label %128, label %129

128:                                              ; preds = %125
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %129

129:                                              ; preds = %128, %125
  br label %130

130:                                              ; preds = %129, %124
  br label %131

131:                                              ; preds = %130, %113
  %132 = load i32, ptr %9, align 4, !tbaa !9
  %133 = icmp eq i32 %132, 0
  br i1 %133, label %134, label %182

134:                                              ; preds = %131
  %135 = load ptr, ptr %7, align 8, !tbaa !5
  %136 = getelementptr inbounds %struct.MDBX_env, ptr %135, i32 0, i32 1
  %137 = load i32, ptr %136, align 4, !tbaa !11
  %138 = and i32 %137, 16384
  %139 = icmp ne i32 %138, 0
  br i1 %139, label %182, label %140

140:                                              ; preds = %134
  %141 = load ptr, ptr %4, align 8, !tbaa !5
  %142 = getelementptr inbounds i8, ptr %141, i64 0
  %143 = load i8, ptr %142, align 1, !tbaa !26
  %144 = sext i8 %143 to i32
  %145 = icmp ne i32 %144, 46
  br i1 %145, label %152, label %146

146:                                              ; preds = %140
  %147 = load ptr, ptr %4, align 8, !tbaa !5
  %148 = getelementptr inbounds i8, ptr %147, i64 1
  %149 = load i8, ptr %148, align 1, !tbaa !26
  %150 = sext i8 %149 to i32
  %151 = icmp ne i32 %150, 0
  br i1 %151, label %152, label %182

152:                                              ; preds = %146, %140
  %153 = load ptr, ptr %4, align 8, !tbaa !5
  %154 = getelementptr inbounds i8, ptr %153, i64 0
  %155 = load i8, ptr %154, align 1, !tbaa !26
  %156 = sext i8 %155 to i32
  %157 = icmp ne i32 %156, 46
  br i1 %157, label %170, label %158

158:                                              ; preds = %152
  %159 = load ptr, ptr %4, align 8, !tbaa !5
  %160 = getelementptr inbounds i8, ptr %159, i64 1
  %161 = load i8, ptr %160, align 1, !tbaa !26
  %162 = sext i8 %161 to i32
  %163 = icmp ne i32 %162, 46
  br i1 %163, label %170, label %164

164:                                              ; preds = %158
  %165 = load ptr, ptr %4, align 8, !tbaa !5
  %166 = getelementptr inbounds i8, ptr %165, i64 2
  %167 = load i8, ptr %166, align 1, !tbaa !26
  %168 = sext i8 %167 to i32
  %169 = icmp ne i32 %168, 0
  br i1 %169, label %170, label %182

170:                                              ; preds = %164, %158, %152
  %171 = load ptr, ptr %4, align 8, !tbaa !5
  %172 = call i32 @osal_removedirectory(ptr noundef %171)
  store i32 %172, ptr %9, align 4, !tbaa !9
  %173 = load i32, ptr %9, align 4, !tbaa !9
  %174 = icmp eq i32 %173, 0
  br i1 %174, label %175, label %176

175:                                              ; preds = %170
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %181

176:                                              ; preds = %170
  %177 = load i32, ptr %9, align 4, !tbaa !9
  %178 = icmp eq i32 %177, 2
  br i1 %178, label %179, label %180

179:                                              ; preds = %176
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %180

180:                                              ; preds = %179, %176
  br label %181

181:                                              ; preds = %180, %175
  br label %182

182:                                              ; preds = %181, %164, %146, %134, %131
  %183 = load i32, ptr %11, align 4, !tbaa !9
  %184 = icmp ne i32 %183, -1
  br i1 %184, label %185, label %188

185:                                              ; preds = %182
  %186 = load i32, ptr %11, align 4, !tbaa !9
  %187 = call i32 @osal_closefile(i32 noundef %186)
  br label %188

188:                                              ; preds = %185, %182
  %189 = load i32, ptr %10, align 4, !tbaa !9
  %190 = icmp ne i32 %189, -1
  br i1 %190, label %191, label %194

191:                                              ; preds = %188
  %192 = load i32, ptr %10, align 4, !tbaa !9
  %193 = call i32 @osal_closefile(i32 noundef %192)
  br label %194

194:                                              ; preds = %191, %188
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #8
  br label %200

195:                                              ; preds = %16
  %196 = load i32, ptr %9, align 4, !tbaa !9
  %197 = icmp eq i32 %196, 2
  br i1 %197, label %198, label %199

198:                                              ; preds = %195
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %199

199:                                              ; preds = %198, %195
  br label %200

200:                                              ; preds = %199, %194
  %201 = load ptr, ptr %7, align 8, !tbaa !5
  %202 = getelementptr inbounds %struct.MDBX_env, ptr %201, i32 0, i32 22
  %203 = getelementptr inbounds %struct.anon.1, ptr %202, i32 0, i32 3
  %204 = load ptr, ptr %203, align 8, !tbaa !27
  call void @free(ptr noundef %204) #8
  %205 = load i32, ptr %9, align 4, !tbaa !9
  %206 = icmp eq i32 %205, 0
  br i1 %206, label %207, label %209

207:                                              ; preds = %200
  %208 = load i32, ptr %8, align 4, !tbaa !9
  br label %211

209:                                              ; preds = %200
  %210 = load i32, ptr %9, align 4, !tbaa !9
  br label %211

211:                                              ; preds = %209, %207
  %212 = phi i32 [ %208, %207 ], [ %210, %209 ]
  %213 = call i32 @log_if_error(i32 noundef %212, ptr noundef @__func__.mdbx_env_delete, i32 noundef 420)
  store i32 %213, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #8
  call void @llvm.lifetime.end.p0(i64 1104, ptr %6) #8
  br label %214

214:                                              ; preds = %211, %13
  %215 = load i32, ptr %3, align 4
  ret i32 %215
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

; Function Attrs: nounwind willreturn memory(read)
declare i64 @mdbx_default_pagesize() #6

; Function Attrs: cold nounwind optsize uwtable
declare hidden i32 @env_handle_pathname(ptr noundef, ptr noundef, i32 noundef) #4

declare i32 @osal_openfile(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #7

declare i32 @osal_lockfile(i32 noundef, i1 noundef zeroext) #7

declare i32 @osal_removefile(ptr noundef) #7

declare i32 @osal_removedirectory(ptr noundef) #7

declare i32 @osal_closefile(i32 noundef) #7

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

!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 4}
!12 = !{!"MDBX_env", !7, i64 0, !10, i64 4, !10, i64 8, !13, i64 16, !10, i64 56, !10, i64 60, !13, i64 64, !6, i64 104, !15, i64 112, !15, i64 114, !15, i64 116, !15, i64 118, !15, i64 120, !15, i64 122, !7, i64 124, !7, i64 128, !7, i64 129, !15, i64 130, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !16, 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, !17, i64 264, !20, i64 320, !18, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !21, i64 392, !7, i64 400, !10, i64 440, !10, i64 444, !6, i64 448, !22, i64 456, !7, i64 496, !7, i64 536}
!13 = !{!"osal_mmap", !7, i64 0, !10, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!"", !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, !18, i64 36, !18, i64 37, !18, i64 38, !19, i64 40, !7, i64 48}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!"", !15, i64 0, !15, i64 2, !15, i64 4, !15, i64 6}
!20 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32}
!21 = !{!"", !14, i64 0}
!22 = !{!"osal_ioring", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!23 = !{!12, !10, i64 8}
!24 = !{!12, !6, i64 160}
!25 = !{!12, !6, i64 152}
!26 = !{!7, !7, i64 0}
!27 = !{!12, !6, i64 176}


; 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.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.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 }
%union.mdbx_atomic_uint64_t = type { i64 }

@__func__.mdbx_env_delete = external hidden unnamed_addr constant [16 x i8], align 1

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

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

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

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

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @mdbx_env_delete(ptr noundef %0, i32 noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.MDBX_env, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %switch = icmp ult i32 %1, 3
  br i1 %switch, label %8, label %6

6:                                                ; preds = %2
  %7 = tail call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_env_delete, i32 noundef 353)
  br label %82

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 1104, ptr nonnull %3) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1104) %3, i8 0, i64 1104, i1 false)
  %9 = icmp eq i32 %1, 1
  %10 = select i1 %9, i32 4194304, i32 0
  %11 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %10, ptr %11, align 4, !tbaa !5
  %12 = tail call i64 @mdbx_default_pagesize() #8
  %13 = trunc i64 %12 to i32
  %14 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %13, ptr %14, align 8, !tbaa !21
  %15 = call i32 @env_handle_pathname(ptr noundef nonnull %3, ptr noundef %0, i32 noundef 0) #9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %74, !prof !22

17:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #7
  store i32 -1, ptr %4, align 4, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #7
  store i32 -1, ptr %5, align 4, !tbaa !23
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.thread83, label %18

18:                                               ; preds = %17
  %19 = getelementptr inbounds i8, ptr %3, i64 160
  %20 = load ptr, ptr %19, align 8, !tbaa !24
  %21 = call i32 @osal_openfile(i32 noundef 5, ptr noundef nonnull %3, ptr noundef %20, ptr noundef nonnull %5, i32 noundef 0) #7
  %22 = and i32 %21, -3
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %.thread87

24:                                               ; preds = %18
  %25 = getelementptr inbounds i8, ptr %3, i64 152
  %26 = load ptr, ptr %25, align 8, !tbaa !25
  %27 = call i32 @osal_openfile(i32 noundef 5, ptr noundef nonnull %3, ptr noundef %26, ptr noundef nonnull %4, i32 noundef 0) #7
  %28 = icmp eq i32 %27, 2
  %29 = select i1 %28, i32 0, i32 %27
  %30 = icmp eq i32 %29, 0
  %31 = load i32, ptr %4, align 4
  %32 = icmp ne i32 %31, -1
  %or.cond = select i1 %30, i1 %32, i1 false
  br i1 %or.cond, label %33, label %36

33:                                               ; preds = %24
  %34 = icmp eq i32 %1, 2
  %35 = call i32 @osal_lockfile(i32 noundef %31, i1 noundef zeroext %34) #7
  br label %36

36:                                               ; preds = %33, %24
  %.1 = phi i32 [ %35, %33 ], [ %29, %24 ]
  %37 = icmp eq i32 %.1, 0
  %38 = load i32, ptr %5, align 4
  %39 = icmp ne i32 %38, -1
  %or.cond3 = select i1 %37, i1 %39, i1 false
  br i1 %or.cond3, label %40, label %43

40:                                               ; preds = %36
  %41 = icmp eq i32 %1, 2
  %42 = call i32 @osal_lockfile(i32 noundef %38, i1 noundef zeroext %41) #7
  br label %43

43:                                               ; preds = %36, %40
  %.2 = phi i32 [ %42, %40 ], [ %.1, %36 ]
  %44 = icmp eq i32 %.2, 0
  br i1 %44, label %.thread83, label %.thread87

.thread83:                                        ; preds = %17, %43
  %45 = getelementptr inbounds i8, ptr %3, i64 160
  %46 = load ptr, ptr %45, align 8, !tbaa !24
  %47 = call i32 @osal_removefile(ptr noundef %46) #7
  switch i32 %47, label %.thread87 [
    i32 0, label %select.unfold
    i32 2, label %select.unfold.fold.split
  ]

select.unfold.fold.split:                         ; preds = %.thread83
  br label %select.unfold

select.unfold:                                    ; preds = %.thread83, %select.unfold.fold.split
  %.051 = phi i32 [ %47, %.thread83 ], [ -1, %select.unfold.fold.split ]
  %48 = getelementptr inbounds i8, ptr %3, i64 152
  %49 = load ptr, ptr %48, align 8, !tbaa !25
  %50 = call i32 @osal_removefile(ptr noundef %49) #7
  switch i32 %50, label %.thread87 [
    i32 0, label %select.unfold90
    i32 2, label %select.unfold90.fold.split
  ]

select.unfold90.fold.split:                       ; preds = %select.unfold
  br label %select.unfold90

select.unfold90:                                  ; preds = %select.unfold, %select.unfold90.fold.split
  %.152.ph = phi i32 [ %50, %select.unfold ], [ %.051, %select.unfold90.fold.split ]
  %51 = load i32, ptr %11, align 4, !tbaa !5
  %52 = and i32 %51, 16384
  %.not70 = icmp eq i32 %52, 0
  br i1 %.not70, label %53, label %.thread87

53:                                               ; preds = %select.unfold90
  %54 = load i8, ptr %0, align 1, !tbaa !26
  %.not71 = icmp eq i8 %54, 46
  br i1 %.not71, label %55, label %61

55:                                               ; preds = %53
  %56 = getelementptr inbounds i8, ptr %0, i64 1
  %57 = load i8, ptr %56, align 1, !tbaa !26
  switch i8 %57, label %61 [
    i8 0, label %.thread87
    i8 46, label %58
  ]

58:                                               ; preds = %55
  %59 = getelementptr inbounds i8, ptr %0, i64 2
  %60 = load i8, ptr %59, align 1, !tbaa !26
  %.not75 = icmp eq i8 %60, 0
  br i1 %.not75, label %.thread87, label %61

61:                                               ; preds = %55, %53, %58
  %62 = call i32 @osal_removedirectory(ptr noundef nonnull %0) #7
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %.thread87, label %64

64:                                               ; preds = %61
  %65 = icmp eq i32 %62, 2
  %spec.store.select5 = select i1 %65, i32 0, i32 %62
  br label %.thread87

.thread87:                                        ; preds = %55, %select.unfold, %.thread83, %18, %43, %61, %64, %58, %select.unfold90
  %.253 = phi i32 [ %.152.ph, %select.unfold90 ], [ %.152.ph, %64 ], [ %.152.ph, %58 ], [ %.152.ph, %55 ], [ 0, %61 ], [ -1, %43 ], [ -1, %18 ], [ -1, %.thread83 ], [ %.051, %select.unfold ]
  %.5 = phi i32 [ 0, %select.unfold90 ], [ %spec.store.select5, %64 ], [ 0, %58 ], [ 0, %55 ], [ 0, %61 ], [ %.2, %43 ], [ %21, %18 ], [ %47, %.thread83 ], [ %50, %select.unfold ]
  %66 = load i32, ptr %5, align 4, !tbaa !23
  %.not76 = icmp eq i32 %66, -1
  br i1 %.not76, label %69, label %67

67:                                               ; preds = %.thread87
  %68 = call i32 @osal_closefile(i32 noundef %66) #7
  br label %69

69:                                               ; preds = %67, %.thread87
  %70 = load i32, ptr %4, align 4, !tbaa !23
  %.not77 = icmp eq i32 %70, -1
  br i1 %.not77, label %73, label %71

71:                                               ; preds = %69
  %72 = call i32 @osal_closefile(i32 noundef %70) #7
  br label %73

73:                                               ; preds = %71, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #7
  br label %76

74:                                               ; preds = %8
  %75 = icmp eq i32 %15, 2
  %spec.store.select6 = select i1 %75, i32 0, i32 %15
  br label %76

76:                                               ; preds = %74, %73
  %.354 = phi i32 [ %.253, %73 ], [ -1, %74 ]
  %.6 = phi i32 [ %.5, %73 ], [ %spec.store.select6, %74 ]
  %77 = getelementptr inbounds i8, ptr %3, i64 176
  %78 = load ptr, ptr %77, align 8, !tbaa !27
  call void @free(ptr noundef %78) #7
  %79 = icmp eq i32 %.6, 0
  %80 = select i1 %79, i32 %.354, i32 %.6
  %81 = call i32 @log_if_error(i32 noundef %80, ptr noundef nonnull @__func__.mdbx_env_delete, i32 noundef 420)
  call void @llvm.lifetime.end.p0(i64 1104, ptr nonnull %3) #7
  br label %82

82:                                               ; preds = %76, %6
  %.055 = phi i32 [ %7, %6 ], [ %81, %76 ]
  ret i32 %.055
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i64 @mdbx_default_pagesize() local_unnamed_addr #5

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

declare i32 @osal_openfile(i32 noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #6

declare i32 @osal_lockfile(i32 noundef, i1 noundef zeroext) local_unnamed_addr #6

declare i32 @osal_removefile(ptr noundef) local_unnamed_addr #6

declare i32 @osal_removedirectory(ptr noundef) local_unnamed_addr #6

declare i32 @osal_closefile(i32 noundef) local_unnamed_addr #6

attributes #0 = { inlinehint nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { mustprogress nofree nounwind willreturn memory(read) "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 = { "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 }
attributes #8 = { nounwind willreturn memory(read) }
attributes #9 = { cold }

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


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