; 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_envinfo = type { %struct.anon.27, i64, i64, i64, i64, i64, [3 x i64], [3 x i64], i32, i32, i32, i32, %struct.anon.28, i64, i64, i32, i32, i32, i32, %struct.anon.30, %struct.anon.31 }
%struct.anon.27 = type { i64, i64, i64, i64, i64 }
%struct.anon.28 = type { %struct.anon.29, [3 x %struct.anon.29] }
%struct.anon.29 = type { i64, i64 }
%struct.anon.30 = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }
%struct.anon.31 = type { i64, i64 }

@globals = external global %struct.libmdbx_globals, align 8
@.str.16 = external hidden unnamed_addr constant [22 x i8], align 1
@__func__.env_info = external hidden unnamed_addr constant [9 x i8], align 1

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @env_info(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #4 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %struct.MDBX_envinfo, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 352, ptr %12) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  %18 = call i32 @env_info_snap(ptr noundef %15, ptr noundef %16, ptr noundef %12, i64 noundef 352, ptr noundef %17)
  store i32 %18, ptr %13, align 4, !tbaa !11
  %19 = load i32, ptr %13, align 4, !tbaa !11
  %20 = icmp ne i32 %19, 0
  %21 = xor i1 %20, true
  %22 = xor i1 %21, true
  %23 = zext i1 %22 to i32
  %24 = sext i32 %23 to i64
  %25 = call i64 @llvm.expect.i64(i64 %24, i64 0)
  %26 = icmp ne i64 %25, 0
  br i1 %26, label %27, label %29

27:                                               ; preds = %5
  %28 = load i32, ptr %13, align 4, !tbaa !11
  store i32 %28, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

29:                                               ; preds = %5
  br label %30

30:                                               ; preds = %29
  %31 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !13
  %32 = zext i8 %31 to i32
  %33 = and i32 %32, 1
  %34 = icmp ne i32 %33, 0
  %35 = xor i1 %34, true
  %36 = xor i1 %35, true
  %37 = zext i1 %36 to i32
  %38 = sext i32 %37 to i64
  %39 = call i64 @llvm.expect.i64(i64 %38, i64 1)
  %40 = icmp ne i64 %39, 0
  br i1 %40, label %41, label %57

41:                                               ; preds = %30
  br label %42

42:                                               ; preds = %41
  %43 = load i64, ptr %10, align 8, !tbaa !9
  %44 = icmp uge i64 352, %43
  %45 = xor i1 %44, true
  %46 = xor i1 %45, true
  %47 = xor i1 %46, true
  %48 = zext i1 %47 to i32
  %49 = sext i32 %48 to i64
  %50 = call i64 @llvm.expect.i64(i64 %49, i64 0)
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %52, label %54

52:                                               ; preds = %42
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mdbx_assert_fail(ptr noundef %53, ptr noundef @.str.16, ptr noundef @__func__.env_info, i32 noundef 800) #8
  unreachable

54:                                               ; preds = %42
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56, %30
  br label %58

58:                                               ; preds = %57
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %98, %59
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = load i64, ptr %10, align 8, !tbaa !9
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = call i32 @env_info_snap(ptr noundef %62, ptr noundef %63, ptr noundef %64, i64 noundef %65, ptr noundef %66)
  store i32 %67, ptr %13, align 4, !tbaa !11
  %68 = load i32, ptr %13, align 4, !tbaa !11
  %69 = icmp ne i32 %68, 0
  %70 = xor i1 %69, true
  %71 = xor i1 %70, true
  %72 = zext i1 %71 to i32
  %73 = sext i32 %72 to i64
  %74 = call i64 @llvm.expect.i64(i64 %73, i64 0)
  %75 = icmp ne i64 %74, 0
  br i1 %75, label %76, label %78

76:                                               ; preds = %61
  %77 = load i32, ptr %13, align 4, !tbaa !11
  store i32 %77, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

78:                                               ; preds = %61
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.MDBX_envinfo, ptr %79, i32 0, i32 15
  %81 = load i32, ptr %80, align 8, !tbaa !16
  %82 = getelementptr inbounds %struct.MDBX_envinfo, ptr %12, i32 0, i32 15
  store i32 %81, ptr %82, align 8, !tbaa !16
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.MDBX_envinfo, ptr %83, i32 0, i32 17
  %85 = load i32, ptr %84, align 8, !tbaa !22
  %86 = getelementptr inbounds %struct.MDBX_envinfo, ptr %12, i32 0, i32 17
  store i32 %85, ptr %86, align 8, !tbaa !22
  %87 = load ptr, ptr %9, align 8, !tbaa !5
  %88 = load i64, ptr %10, align 8, !tbaa !9
  %89 = call i32 @memcmp(ptr noundef %12, ptr noundef %87, i64 noundef %88) #9
  %90 = icmp eq i32 %89, 0
  %91 = xor i1 %90, true
  %92 = xor i1 %91, true
  %93 = zext i1 %92 to i32
  %94 = sext i32 %93 to i64
  %95 = call i64 @llvm.expect.i64(i64 %94, i64 1)
  %96 = icmp ne i64 %95, 0
  br i1 %96, label %97, label %98

97:                                               ; preds = %78
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %101

98:                                               ; preds = %78
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  %100 = load i64, ptr %10, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %99, i64 %100, i1 false)
  br label %60

101:                                              ; preds = %97, %76, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 352, ptr %12) #7
  %102 = load i32, ptr %6, align 4
  ret i32 %102
}

; Function Attrs: nounwind uwtable
declare hidden i32 @env_info_snap(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) #5

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #6

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

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !7, i64 25}
!14 = !{!"libmdbx_globals", !7, i64 0, !12, i64 16, !12, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !15, i64 27, !12, i64 28, !7, i64 32, !7, i64 40, !10, i64 80, !6, i64 88}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!17, !12, i64 224}
!17 = !{!"MDBX_envinfo", !18, i64 0, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !7, i64 80, !7, i64 104, !12, i64 128, !12, i64 132, !12, i64 136, !12, i64 140, !19, i64 144, !10, i64 208, !10, i64 216, !12, i64 224, !12, i64 228, !12, i64 232, !12, i64 236, !21, i64 240, !20, i64 336}
!18 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!19 = !{!"", !20, i64 0, !7, i64 16}
!20 = !{!"", !10, i64 0, !10, i64 8}
!21 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88}
!22 = !{!17, !12, i64 232}


; 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 }
%struct.MDBX_envinfo = type { %struct.anon.27, i64, i64, i64, i64, i64, [3 x i64], [3 x i64], i32, i32, i32, i32, %struct.anon.28, i64, i64, i32, i32, i32, i32, %struct.anon.30, %struct.anon.31 }
%struct.anon.27 = type { i64, i64, i64, i64, i64 }
%struct.anon.28 = type { %struct.anon.29, [3 x %struct.anon.29] }
%struct.anon.29 = type { i64, i64 }
%struct.anon.30 = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }
%struct.anon.31 = type { i64, i64 }

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: cold nounwind optsize uwtable
define dso_local i32 @env_info(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #3 {
  %6 = alloca %struct.MDBX_envinfo, align 8
  call void @llvm.lifetime.start.p0(i64 352, ptr nonnull %6) #6
  %7 = call i32 @env_info_snap(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %6, i64 noundef 352, ptr noundef %4)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %.loopexit, !prof !5

8:                                                ; preds = %5
  %9 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !6
  %10 = and i8 %9, 1
  %.not22 = icmp ne i8 %10, 0
  %11 = icmp ugt i64 %3, 352
  %or.cond = and i1 %11, %.not22
  br i1 %or.cond, label %17, label %.preheader, !prof !14

.preheader:                                       ; preds = %8
  %12 = getelementptr inbounds i8, ptr %2, i64 224
  %13 = call i32 @env_info_snap(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4)
  %.not2324 = icmp eq i32 %13, 0
  br i1 %.not2324, label %.lr.ph, label %.loopexit, !prof !15

.lr.ph:                                           ; preds = %.preheader
  %14 = getelementptr inbounds i8, ptr %6, i64 224
  %15 = getelementptr inbounds i8, ptr %2, i64 232
  %16 = getelementptr inbounds i8, ptr %6, i64 232
  br label %18

17:                                               ; preds = %8
  call void @mdbx_assert_fail(ptr noundef %0, ptr noundef nonnull @.str.16, ptr noundef nonnull @__func__.env_info, i32 noundef 800) #7
  unreachable

18:                                               ; preds = %.lr.ph, %22
  %19 = load i32, ptr %12, align 8, !tbaa !16
  store i32 %19, ptr %14, align 8, !tbaa !16
  %20 = load i32, ptr %15, align 8, !tbaa !22
  store i32 %20, ptr %16, align 8, !tbaa !22
  %bcmp = call i32 @bcmp(ptr nonnull %6, ptr %2, i64 %3)
  %21 = icmp eq i32 %bcmp, 0
  br i1 %21, label %.loopexit, label %22, !prof !5

22:                                               ; preds = %18
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %6, ptr nonnull align 8 %2, i64 %3, i1 false)
  %23 = call i32 @env_info_snap(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %2, i64 noundef %3, ptr noundef %4)
  %.not23 = icmp eq i32 %23, 0
  br i1 %.not23, label %18, label %.loopexit, !prof !23

.loopexit:                                        ; preds = %22, %18, %.preheader, %5
  %.0 = phi i32 [ %7, %5 ], [ %13, %.preheader ], [ %23, %22 ], [ 0, %18 ]
  call void @llvm.lifetime.end.p0(i64 352, ptr nonnull %6) #6
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @env_info_snap(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noreturn "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { 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 = { 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 = { nofree nounwind willreturn memory(argmem: read) }
attributes #6 = { nounwind }
attributes #7 = { noreturn 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 2000, i32 1}
!6 = !{!7, !8, i64 25}
!7 = !{!"libmdbx_globals", !8, i64 0, !10, i64 16, !10, i64 20, !8, i64 24, !8, i64 25, !8, i64 26, !11, i64 27, !10, i64 28, !8, i64 32, !8, i64 40, !12, i64 80, !13, i64 88}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!"any pointer", !8, i64 0}
!14 = !{!"branch_weights", i32 2000, i32 4002001}
!15 = !{!"branch_weights", i32 127, i32 1}
!16 = !{!17, !10, i64 224}
!17 = !{!"MDBX_envinfo", !18, i64 0, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !8, i64 80, !8, i64 104, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !19, i64 144, !12, i64 208, !12, i64 216, !10, i64 224, !10, i64 228, !10, i64 232, !10, i64 236, !21, i64 240, !20, i64 336}
!18 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32}
!19 = !{!"", !20, i64 0, !8, i64 16}
!20 = !{!"", !12, i64 0, !12, i64 8}
!21 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88}
!22 = !{!17, !10, i64 232}
!23 = !{!"branch_weights", i32 255873, i32 127}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LowerExpectIntrinsicPass,ReassociatePass,SROAPass,SimplifyCFGPass