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

; 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.meta_ptr = type { i64, %union.anon, i64 }
%union.anon = type { ptr }
%struct.troika = type { i8, i8, i8, i8, i32, [3 x i64] }

@globals = external global %struct.libmdbx_globals, align 8
@__func__.meta_troika_dump = external hidden unnamed_addr constant [17 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [111 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: cold nounwind optsize uwtable
define dso_local void @meta_troika_dump(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.meta_ptr, align 8
  %6 = alloca %struct.meta_ptr, align 8
  %7 = alloca %struct.meta_ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  call void @meta_recent(ptr dead_on_unwind writable sret(%struct.meta_ptr) align 8 %5, ptr noundef %8, ptr noundef %9)
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  call void @meta_prefer_steady(ptr dead_on_unwind writable sret(%struct.meta_ptr) align 8 %6, ptr noundef %10, ptr noundef %11)
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  call void @meta_tail(ptr dead_on_unwind writable sret(%struct.meta_ptr) align 8 %7, ptr noundef %12, ptr noundef %13)
  br label %14

14:                                               ; preds = %2
  %15 = load i8, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 5), align 2, !tbaa !9
  %16 = zext i8 %15 to i32
  %17 = icmp sle i32 3, %16
  %18 = xor i1 %17, true
  %19 = xor i1 %18, true
  %20 = zext i1 %19 to i32
  %21 = sext i32 %20 to i64
  %22 = call i64 @llvm.expect.i64(i64 %21, i64 0)
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %115

24:                                               ; preds = %14
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.troika, ptr %25, i32 0, i32 5
  %27 = getelementptr inbounds [3 x i64], ptr %26, i64 0, i64 0
  %28 = load i64, ptr %27, align 8, !tbaa !14
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.troika, ptr %29, i32 0, i32 0
  %31 = load i8, ptr %30, align 8, !tbaa !15
  %32 = zext i8 %31 to i32
  %33 = and i32 %32, 1
  %34 = icmp ne i32 %33, 0
  %35 = zext i1 %34 to i64
  %36 = select i1 %34, i32 115, i32 119
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.troika, ptr %37, i32 0, i32 5
  %39 = getelementptr inbounds [3 x i64], ptr %38, i64 0, i64 1
  %40 = load i64, ptr %39, align 8, !tbaa !14
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.troika, ptr %41, i32 0, i32 0
  %43 = load i8, ptr %42, align 8, !tbaa !15
  %44 = zext i8 %43 to i32
  %45 = and i32 %44, 2
  %46 = icmp ne i32 %45, 0
  %47 = zext i1 %46 to i64
  %48 = select i1 %46, i32 115, i32 119
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.troika, ptr %49, i32 0, i32 5
  %51 = getelementptr inbounds [3 x i64], ptr %50, i64 0, i64 2
  %52 = load i64, ptr %51, align 8, !tbaa !14
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.troika, ptr %53, i32 0, i32 0
  %55 = load i8, ptr %54, align 8, !tbaa !15
  %56 = zext i8 %55 to i32
  %57 = and i32 %56, 4
  %58 = icmp ne i32 %57, 0
  %59 = zext i1 %58 to i64
  %60 = select i1 %58, i32 115, i32 119
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.troika, ptr %61, i32 0, i32 0
  %63 = load i8, ptr %62, align 8, !tbaa !15
  %64 = zext i8 %63 to i32
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.troika, ptr %65, i32 0, i32 1
  %67 = load i8, ptr %66, align 1, !tbaa !17
  %68 = zext i8 %67 to i32
  %69 = getelementptr inbounds %struct.meta_ptr, ptr %5, i32 0, i32 0
  %70 = load i64, ptr %69, align 8, !tbaa !18
  %71 = getelementptr inbounds %struct.meta_ptr, ptr %5, i32 0, i32 2
  %72 = load i64, ptr %71, align 8, !tbaa !20
  %73 = icmp ne i64 %72, 0
  %74 = zext i1 %73 to i64
  %75 = select i1 %73, i32 115, i32 119
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.troika, ptr %76, i32 0, i32 2
  %78 = load i8, ptr %77, align 2, !tbaa !21
  %79 = zext i8 %78 to i32
  %80 = getelementptr inbounds %struct.meta_ptr, ptr %6, i32 0, i32 0
  %81 = load i64, ptr %80, align 8, !tbaa !18
  %82 = getelementptr inbounds %struct.meta_ptr, ptr %6, i32 0, i32 2
  %83 = load i64, ptr %82, align 8, !tbaa !20
  %84 = icmp ne i64 %83, 0
  %85 = zext i1 %84 to i64
  %86 = select i1 %84, i32 115, i32 119
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.troika, ptr %87, i32 0, i32 3
  %89 = load i8, ptr %88, align 1, !tbaa !22
  %90 = zext i8 %89 to i32
  %91 = srem i32 %90, 3
  %92 = getelementptr inbounds %struct.meta_ptr, ptr %7, i32 0, i32 0
  %93 = load i64, ptr %92, align 8, !tbaa !18
  %94 = getelementptr inbounds %struct.meta_ptr, ptr %7, i32 0, i32 2
  %95 = load i64, ptr %94, align 8, !tbaa !20
  %96 = icmp ne i64 %95, 0
  %97 = zext i1 %96 to i64
  %98 = select i1 %96, i32 115, i32 119
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.troika, ptr %99, i32 0, i32 3
  %101 = load i8, ptr %100, align 1, !tbaa !22
  %102 = zext i8 %101 to i32
  %103 = and i32 %102, 128
  %104 = icmp ne i32 %103, 0
  %105 = zext i1 %104 to i64
  %106 = select i1 %104, i32 89, i32 78
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.troika, ptr %107, i32 0, i32 3
  %109 = load i8, ptr %108, align 1, !tbaa !22
  %110 = zext i8 %109 to i32
  %111 = and i32 %110, 64
  %112 = icmp ne i32 %111, 0
  %113 = zext i1 %112 to i64
  %114 = select i1 %112, i32 89, i32 78
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 3, ptr noundef @__func__.meta_troika_dump, i32 noundef 196, ptr noundef @.str.10, i64 noundef %28, i32 noundef %36, i64 noundef %40, i32 noundef %48, i64 noundef %52, i32 noundef %60, i32 noundef %64, i32 noundef %68, i64 noundef %70, i32 noundef %75, i32 noundef %79, i64 noundef %81, i32 noundef %86, i32 noundef %91, i64 noundef %93, i32 noundef %98, i32 noundef %106, i32 noundef %114)
  br label %115

115:                                              ; preds = %24, %14
  br label %116

116:                                              ; preds = %115
  br label %117

117:                                              ; preds = %116
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @meta_recent(ptr dead_on_unwind noalias writable sret(%struct.meta_ptr) align 8, ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @meta_prefer_steady(ptr dead_on_unwind noalias writable sret(%struct.meta_ptr) align 8, ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @meta_tail(ptr dead_on_unwind noalias writable sret(%struct.meta_ptr) align 8, ptr noundef, ptr noundef) #3

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

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

!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, !7, i64 26}
!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 = !{!13, !13, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"troika", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !11, i64 4, !7, i64 8}
!17 = !{!16, !7, i64 1}
!18 = !{!19, !13, i64 0}
!19 = !{!"meta_ptr", !13, i64 0, !7, i64 8, !13, i64 16}
!20 = !{!19, !13, i64 16}
!21 = !{!16, !7, i64 2}
!22 = !{!16, !7, i64 3}


; 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.meta_ptr = type { i64, %union.anon, i64 }
%union.anon = type { ptr }

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@__func__.meta_troika_dump = external hidden unnamed_addr constant [17 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [111 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: cold nounwind optsize uwtable
define dso_local void @meta_troika_dump(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.meta_ptr, align 8
  %4 = alloca %struct.meta_ptr, align 8
  %5 = alloca %struct.meta_ptr, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  call void @meta_recent(ptr dead_on_unwind nonnull writable sret(%struct.meta_ptr) align 8 %3, ptr noundef %0, ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  call void @meta_prefer_steady(ptr dead_on_unwind nonnull writable sret(%struct.meta_ptr) align 8 %4, ptr noundef %0, ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #4
  call void @meta_tail(ptr dead_on_unwind nonnull writable sret(%struct.meta_ptr) align 8 %5, ptr noundef %0, ptr noundef %1)
  %6 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !5
  %7 = icmp ugt i8 %6, 2
  br i1 %7, label %8, label %47, !prof !13

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !14
  %11 = load i8, ptr %1, align 8, !tbaa !15
  %12 = zext i8 %11 to i32
  %13 = and i32 %12, 1
  %.not = icmp eq i32 %13, 0
  %14 = select i1 %.not, i32 119, i32 115
  %15 = getelementptr inbounds i8, ptr %1, i64 16
  %16 = load i64, ptr %15, align 8, !tbaa !14
  %17 = and i32 %12, 2
  %.not18 = icmp eq i32 %17, 0
  %18 = select i1 %.not18, i32 119, i32 115
  %19 = getelementptr inbounds i8, ptr %1, i64 24
  %20 = load i64, ptr %19, align 8, !tbaa !14
  %21 = and i32 %12, 4
  %22 = xor i32 %21, 119
  %23 = getelementptr inbounds i8, ptr %1, i64 1
  %24 = load i8, ptr %23, align 1, !tbaa !17
  %25 = zext i8 %24 to i32
  %26 = load i64, ptr %3, align 8, !tbaa !18
  %27 = getelementptr inbounds i8, ptr %3, i64 16
  %28 = load i64, ptr %27, align 8, !tbaa !20
  %.not20 = icmp eq i64 %28, 0
  %29 = select i1 %.not20, i32 119, i32 115
  %30 = getelementptr inbounds i8, ptr %1, i64 2
  %31 = load i8, ptr %30, align 2, !tbaa !21
  %32 = zext i8 %31 to i32
  %33 = load i64, ptr %4, align 8, !tbaa !18
  %34 = getelementptr inbounds i8, ptr %4, i64 16
  %35 = load i64, ptr %34, align 8, !tbaa !20
  %.not21 = icmp eq i64 %35, 0
  %36 = select i1 %.not21, i32 119, i32 115
  %37 = getelementptr inbounds i8, ptr %1, i64 3
  %38 = load i8, ptr %37, align 1, !tbaa !22
  %39 = urem i8 %38, 3
  %.zext = zext nneg i8 %39 to i32
  %40 = load i64, ptr %5, align 8, !tbaa !18
  %41 = getelementptr inbounds i8, ptr %5, i64 16
  %42 = load i64, ptr %41, align 8, !tbaa !20
  %.not22 = icmp eq i64 %42, 0
  %43 = select i1 %.not22, i32 119, i32 115
  %.not23 = icmp sgt i8 %38, -1
  %44 = select i1 %.not23, i32 78, i32 89
  %45 = and i8 %38, 64
  %.not24 = icmp eq i8 %45, 0
  %46 = select i1 %.not24, i32 78, i32 89
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 3, ptr noundef nonnull @__func__.meta_troika_dump, i32 noundef 196, ptr noundef nonnull @.str.10, i64 noundef %10, i32 noundef %14, i64 noundef %16, i32 noundef %18, i64 noundef %20, i32 noundef %22, i32 noundef %12, i32 noundef %25, i64 noundef %26, i32 noundef %29, i32 noundef %32, i64 noundef %33, i32 noundef %36, i32 noundef %.zext, i64 noundef %40, i32 noundef %43, i32 noundef %44, i32 noundef %46) #4
  br label %47

47:                                               ; preds = %8, %2
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @meta_recent(ptr dead_on_unwind noalias writable sret(%struct.meta_ptr) align 8, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @meta_prefer_steady(ptr dead_on_unwind noalias writable sret(%struct.meta_ptr) align 8, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @meta_tail(ptr dead_on_unwind noalias writable sret(%struct.meta_ptr) align 8, ptr noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 }

!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 26}
!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 = !{!11, !11, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"troika", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !9, i64 4, !7, i64 8}
!17 = !{!16, !7, i64 1}
!18 = !{!19, !11, i64 0}
!19 = !{!"meta_ptr", !11, i64 0, !7, i64 8, !11, i64 16}
!20 = !{!19, !11, i64 16}
!21 = !{!16, !7, i64 2}
!22 = !{!16, !7, i64 3}


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