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

; 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.0 }
%struct.anon.0 = 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.cursor_couple = type { %struct.MDBX_cursor, ptr, %struct.inner_cursor }
%struct.MDBX_cursor = type { i32, %union.anon, i8, i8, ptr, ptr, ptr, ptr, ptr, [32 x ptr], [32 x i16], ptr, ptr }
%union.anon = type { i16 }
%struct.inner_cursor = type { %struct.MDBX_cursor, %struct.tree }
%struct.tree = type { i16, i16, i32, i32, i32, i32, i32, i64, i64, i64 }
%struct.cursor_set_result = type { i32, i8 }

@globals = external global %struct.libmdbx_globals, align 8
@__func__.mdbx_get = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [25 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: alwaysinline nounwind uwtable
declare hidden i32 @check_txn(ptr noundef, i32 noundef) #3

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mdbx_get(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #5 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca [510 x i8], align 16
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %struct.cursor_couple, align 8
  %14 = alloca %struct.cursor_set_result, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 510, ptr %10) #6
  br label %15

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

25:                                               ; preds = %15
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds [510 x i8], ptr %10, i64 0, i64 0
  %29 = call ptr @mdbx_dump_val(ptr noundef %27, ptr noundef %28, i64 noundef 255)
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef @__func__.mdbx_get, i32 noundef 69, ptr noundef @.str.3, i32 noundef %26, ptr noundef %29)
  br label %30

30:                                               ; preds = %25, %15
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %39

35:                                               ; preds = %32
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  %38 = xor i1 %37, true
  br label %39

39:                                               ; preds = %35, %32
  %40 = phi i1 [ true, %32 ], [ %38, %35 ]
  %41 = xor i1 %40, true
  %42 = xor i1 %41, true
  %43 = zext i1 %42 to i32
  %44 = sext i32 %43 to i64
  %45 = call i64 @llvm.expect.i64(i64 %44, i64 0)
  %46 = icmp ne i64 %45, 0
  br i1 %46, label %47, label %49

47:                                               ; preds = %39
  %48 = call i32 @log_if_error(i32 noundef 22, ptr noundef @__func__.mdbx_get, i32 noundef 72)
  store i32 %48, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %90

49:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = call i32 @check_txn(ptr noundef %50, i32 noundef 51)
  store i32 %51, ptr %12, align 4, !tbaa !9
  %52 = load i32, ptr %12, align 4, !tbaa !9
  %53 = icmp ne i32 %52, 0
  %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 %63

60:                                               ; preds = %49
  %61 = load i32, ptr %12, align 4, !tbaa !9
  %62 = call i32 @log_if_error(i32 noundef %61, ptr noundef @__func__.mdbx_get, i32 noundef 76)
  store i32 %62, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %89

63:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 824, ptr %13) #6
  %64 = getelementptr inbounds %struct.cursor_couple, ptr %13, i32 0, i32 0
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = zext i32 %66 to i64
  %68 = call i32 @cursor_init(ptr noundef %64, ptr noundef %65, i64 noundef %67)
  store i32 %68, ptr %12, align 4, !tbaa !9
  %69 = load i32, ptr %12, align 4, !tbaa !9
  %70 = icmp ne i32 %69, 0
  %71 = xor i1 %70, true
  %72 = xor i1 %71, true
  %73 = zext i1 %72 to i32
  %74 = sext i32 %73 to i64
  %75 = call i64 @llvm.expect.i64(i64 %74, i64 0)
  %76 = icmp ne i64 %75, 0
  br i1 %76, label %77, label %80

77:                                               ; preds = %63
  %78 = load i32, ptr %12, align 4, !tbaa !9
  %79 = call i32 @log_if_error(i32 noundef %78, ptr noundef @__func__.mdbx_get, i32 noundef 81)
  store i32 %79, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %88

80:                                               ; preds = %63
  %81 = getelementptr inbounds %struct.cursor_couple, ptr %13, i32 0, i32 0
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = call i64 @cursor_seek(ptr noundef %81, ptr noundef %82, ptr noundef %83, i32 noundef 15)
  store i64 %84, ptr %14, align 4
  %85 = getelementptr inbounds %struct.cursor_set_result, ptr %14, i32 0, i32 0
  %86 = load i32, ptr %85, align 4, !tbaa !15
  %87 = call i32 @log_if_error(i32 noundef %86, ptr noundef @__func__.mdbx_get, i32 noundef 83)
  store i32 %87, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %88

88:                                               ; preds = %80, %77
  call void @llvm.lifetime.end.p0(i64 824, ptr %13) #6
  br label %89

89:                                               ; preds = %88, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %90

90:                                               ; preds = %89, %47
  call void @llvm.lifetime.end.p0(i64 510, ptr %10) #6
  %91 = load i32, ptr %5, align 4
  ret i32 %91
}

declare ptr @mdbx_dump_val(ptr noundef, ptr noundef, i64 noundef) #4

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

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 = { alwaysinline 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 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 }

!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, !7, i64 26}
!12 = !{!"libmdbx_globals", !7, i64 0, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !13, i64 27, !10, i64 28, !7, i64 32, !7, i64 40, !14, i64 80, !6, i64 88}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"cursor_set_result", !10, i64 0, !13, i64 4}


; 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.0 }
%struct.anon.0 = 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.cursor_couple = type { %struct.MDBX_cursor, ptr, %struct.inner_cursor }
%struct.MDBX_cursor = type { i32, %union.anon, i8, i8, ptr, ptr, ptr, ptr, ptr, [32 x ptr], [32 x i16], ptr, ptr }
%union.anon = type { i16 }
%struct.inner_cursor = type { %struct.MDBX_cursor, %struct.tree }
%struct.tree = type { i16, i16, i32, i32, i32, i32, i32, i64, i64, i64 }

@globals = external local_unnamed_addr global %struct.libmdbx_globals, align 8
@__func__.mdbx_get = external hidden unnamed_addr constant [9 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [25 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: alwaysinline nounwind uwtable
declare hidden i32 @check_txn(ptr noundef, i32 noundef) local_unnamed_addr #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mdbx_get(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #4 {
  %5 = alloca [510 x i8], align 16
  %6 = alloca %struct.cursor_couple, align 8
  call void @llvm.lifetime.start.p0(i64 510, ptr nonnull %5) #5
  %7 = load i8, ptr getelementptr inbounds (i8, ptr @globals, i64 26), align 2, !tbaa !5
  %8 = icmp ugt i8 %7, 4
  br i1 %8, label %9, label %11, !prof !13

9:                                                ; preds = %4
  %10 = call ptr @mdbx_dump_val(ptr noundef %2, ptr noundef nonnull %5, i64 noundef 255) #5
  call void (i32, ptr, i32, ptr, ...) @debug_log(i32 noundef 5, ptr noundef nonnull @__func__.mdbx_get, i32 noundef 69, ptr noundef nonnull @.str.3, i32 noundef %1, ptr noundef %10) #5
  br label %11

11:                                               ; preds = %9, %4
  %.not = icmp eq ptr %2, null
  %.not15 = icmp eq ptr %3, null
  %12 = or i1 %.not, %.not15
  br i1 %12, label %13, label %15, !prof !13

13:                                               ; preds = %11
  %14 = call i32 @log_if_error(i32 noundef 22, ptr noundef nonnull @__func__.mdbx_get, i32 noundef 72)
  br label %28

15:                                               ; preds = %11
  %16 = call i32 @check_txn(ptr noundef %0, i32 noundef 51)
  %.not16 = icmp eq i32 %16, 0
  br i1 %.not16, label %19, label %17, !prof !14

17:                                               ; preds = %15
  %18 = call i32 @log_if_error(i32 noundef %16, ptr noundef nonnull @__func__.mdbx_get, i32 noundef 76)
  br label %28

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 824, ptr nonnull %6) #5
  %20 = zext i32 %1 to i64
  %21 = call i32 @cursor_init(ptr noundef nonnull %6, ptr noundef %0, i64 noundef %20) #5
  %.not17 = icmp eq i32 %21, 0
  br i1 %.not17, label %24, label %22, !prof !14

22:                                               ; preds = %19
  %23 = call i32 @log_if_error(i32 noundef %21, ptr noundef nonnull @__func__.mdbx_get, i32 noundef 81)
  br label %27

24:                                               ; preds = %19
  %25 = call i64 @cursor_seek(ptr noundef nonnull %6, ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef 15) #5
  %.sroa.0.0.extract.trunc = trunc i64 %25 to i32
  %26 = call i32 @log_if_error(i32 noundef %.sroa.0.0.extract.trunc, ptr noundef nonnull @__func__.mdbx_get, i32 noundef 83)
  br label %27

27:                                               ; preds = %24, %22
  %.0 = phi i32 [ %23, %22 ], [ %26, %24 ]
  call void @llvm.lifetime.end.p0(i64 824, ptr nonnull %6) #5
  br label %28

28:                                               ; preds = %17, %27, %13
  %.2 = phi i32 [ %14, %13 ], [ %18, %17 ], [ %.0, %27 ]
  call void @llvm.lifetime.end.p0(i64 510, ptr nonnull %5) #5
  ret i32 %.2
}

declare ptr @mdbx_dump_val(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

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

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 = { alwaysinline 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 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 }

!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 = !{!"branch_weights", !"expected", i32 2000, i32 1}


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