; LLVM IR from erthink/libmdbx :: src (cogs)

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

@globals = external global %struct.libmdbx_globals, align 8
@.str.10 = external hidden unnamed_addr constant [182 x i8], align 1
@__func__.combine_durability_flags = external hidden unnamed_addr constant [25 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: noreturn
declare void @mdbx_assert_fail(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @combine_durability_flags(i32 noundef %0, i32 noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = or i32 %6, %7
  store i32 %8, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = and i32 %9, 1114112
  %11 = icmp eq i32 %10, 1114112
  br i1 %11, label %12, label %24

12:                                               ; preds = %2
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = and i32 %13, 1114112
  %15 = icmp eq i32 %14, 1114112
  br i1 %15, label %24, label %16

16:                                               ; preds = %12
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = and i32 %17, 1114112
  %19 = icmp eq i32 %18, 1114112
  br i1 %19, label %24, label %20

20:                                               ; preds = %16
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sub i32 %21, 1114112
  %23 = or i32 %22, 65536
  store i32 %23, ptr %5, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %20, %16, %12, %2
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = and i32 %25, 1572864
  %27 = icmp eq i32 %26, 1572864
  br i1 %27, label %28, label %36

28:                                               ; preds = %24
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = and i32 %29, 1114112
  %31 = icmp eq i32 %30, 1114112
  br i1 %31, label %36, label %32

32:                                               ; preds = %28
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sub i32 %33, 1048576
  %35 = or i32 %34, 65536
  store i32 %35, ptr %5, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %32, %28, %24
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = and i32 %37, 1114112
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %43

40:                                               ; preds = %36
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = or i32 %41, 262144
  store i32 %42, ptr %5, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %40, %36
  br label %44

44:                                               ; preds = %43
  %45 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 4), align 1, !tbaa !9
  %46 = zext i8 %45 to i32
  %47 = and i32 %46, 1
  %48 = icmp ne i32 %47, 0
  %49 = xor i1 %48, true
  %50 = xor i1 %49, true
  %51 = zext i1 %50 to i32
  %52 = sext i32 %51 to i64
  %53 = call i64 @llvm.expect.i64(i64 %52, i64 1)
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %55, label %83

55:                                               ; preds = %44
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = and i32 %57, 1114112
  %59 = icmp eq i32 %58, 1114112
  br i1 %59, label %60, label %69

60:                                               ; preds = %56
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = and i32 %61, 1114112
  %63 = icmp eq i32 %62, 1114112
  br i1 %63, label %69, label %64

64:                                               ; preds = %60
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = and i32 %65, 1114112
  %67 = icmp eq i32 %66, 1114112
  %68 = xor i1 %67, true
  br label %69

69:                                               ; preds = %64, %60, %56
  %70 = phi i1 [ false, %60 ], [ false, %56 ], [ %68, %64 ]
  %71 = xor i1 %70, true
  %72 = xor i1 %71, true
  %73 = xor i1 %72, true
  %74 = xor i1 %73, true
  %75 = zext i1 %74 to i32
  %76 = sext i32 %75 to i64
  %77 = call i64 @llvm.expect.i64(i64 %76, i64 0)
  %78 = icmp ne i64 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %69
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.10, ptr noundef @__func__.combine_durability_flags, i32 noundef 307) #5
  unreachable

80:                                               ; preds = %69
  br label %81

81:                                               ; preds = %80
  br label %82

82:                                               ; preds = %81
  br label %83

83:                                               ; preds = %82, %44
  br label %84

84:                                               ; preds = %83
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %86
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #2 = { noreturn "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { 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 = { nounwind }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 25}
!10 = !{!"libmdbx_globals", !7, i64 0, !6, i64 16, !6, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !11, i64 27, !6, i64 28, !7, i64 32, !7, i64 40, !12, i64 80, !13, i64 88}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"any pointer", !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 }

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@.str.10 = external hidden unnamed_addr constant [182 x i8], align 1
@__func__.combine_durability_flags = external hidden unnamed_addr constant [25 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @combine_durability_flags(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = or i32 %1, %0
  %4 = and i32 %3, 1114112
  %5 = icmp ne i32 %4, 1114112
  %6 = and i32 %0, 1114112
  %7 = icmp eq i32 %6, 1114112
  %8 = and i32 %1, 1114112
  %9 = icmp eq i32 %8, 1114112
  %10 = or i1 %9, %5
  %or.cond18 = or i1 %7, %10
  %11 = add nsw i32 %3, -1048576
  %.0 = select i1 %or.cond18, i32 %3, i32 %11
  %12 = and i32 %.0, 1572864
  %13 = icmp ne i32 %12, 1572864
  %14 = and i32 %.0, 1114112
  %15 = icmp eq i32 %14, 1114112
  %or.cond20 = or i1 %13, %15
  %16 = or i32 %.0, 65536
  %17 = add nsw i32 %16, -1048576
  %.1 = select i1 %or.cond20, i32 %.0, i32 %17
  %18 = and i32 %.1, 1114112
  %.not = icmp eq i32 %18, 0
  %19 = or i32 %.1, 262144
  %.2 = select i1 %.not, i32 %.1, i32 %19
  %20 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 25), align 1, !tbaa !5
  %21 = and i8 %20, 1
  %.not15 = icmp eq i8 %21, 0
  br i1 %.not15, label %.critedge, label %22, !prof !13

22:                                               ; preds = %2
  %23 = and i32 %.2, 1114112
  %24 = icmp ne i32 %23, 1114112
  %25 = or i1 %9, %24
  %or.cond24.not = or i1 %7, %25
  br i1 %or.cond24.not, label %.critedge, label %26, !prof !14

26:                                               ; preds = %22
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.10, ptr noundef nonnull @__func__.combine_durability_flags, i32 noundef 307) #2
  unreachable

.critedge:                                        ; preds = %22, %2
  ret i32 %.2
}

attributes #0 = { 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 #1 = { 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 = { 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 = !{!6, !7, i64 25}
!6 = !{!"libmdbx_globals", !7, i64 0, !9, i64 16, !9, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !10, i64 27, !9, i64 28, !7, i64 32, !7, i64 40, !11, i64 80, !12, i64 88}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!14 = !{!"branch_weights", i32 4001, i32 1}


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