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

; 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 = external hidden unnamed_addr constant [49 x i8], align 1
@__func__.debug_log_va = external hidden unnamed_addr constant [13 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [49 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
define dso_local void @debug_log_va(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %5
  %13 = call i32 @osal_fastmutex_acquire(ptr noundef getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 9))
  %14 = icmp eq i32 %13, 0
  %15 = xor i1 %14, true
  %16 = xor i1 %15, true
  %17 = xor i1 %16, true
  %18 = zext i1 %17 to i32
  %19 = sext i32 %18 to i64
  %20 = call i64 @llvm.expect.i64(i64 %19, i64 0)
  %21 = icmp ne i64 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %12
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str, ptr noundef @__func__.debug_log_va, i32 noundef 7) #6
  unreachable

23:                                               ; preds = %12
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 8), align 8, !tbaa !11
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %54

27:                                               ; preds = %24
  %28 = load ptr, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 11), align 8, !tbaa !12
  %29 = icmp eq ptr %28, null
  br i1 %29, label %30, label %37

30:                                               ; preds = %27
  %31 = load ptr, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 8), align 8, !tbaa !11
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = load ptr, ptr %7, align 8, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = load ptr, ptr %9, align 8, !tbaa !9
  %36 = load ptr, ptr %10, align 8, !tbaa !9
  call void %31(i32 noundef %32, ptr noundef %33, i32 noundef %34, ptr noundef %35, ptr noundef %36)
  br label %53

37:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  %38 = load ptr, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 11), align 8, !tbaa !12
  %39 = load i64, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 10), align 8, !tbaa !16
  %40 = load ptr, ptr %9, align 8, !tbaa !9
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  %42 = call i32 @vsnprintf(ptr noundef %38, i64 noundef %39, ptr noundef %40, ptr noundef %41) #7
  store i32 %42, ptr %11, align 4, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !5
  %44 = icmp sgt i32 %43, 0
  br i1 %44, label %45, label %52

45:                                               ; preds = %37
  %46 = load ptr, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 8), align 8, !tbaa !11
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = load ptr, ptr %7, align 8, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = load ptr, ptr getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 11), align 8, !tbaa !12
  %51 = load i32, ptr %11, align 4, !tbaa !5
  call void %46(i32 noundef %47, ptr noundef %48, i32 noundef %49, ptr noundef %50, i32 noundef %51)
  br label %52

52:                                               ; preds = %45, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  br label %53

53:                                               ; preds = %52, %30
  br label %88

54:                                               ; preds = %24
  %55 = load ptr, ptr %7, align 8, !tbaa !9
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %65

57:                                               ; preds = %54
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = icmp sgt i32 %58, 0
  br i1 %59, label %60, label %65

60:                                               ; preds = %57
  %61 = load ptr, ptr @stderr, align 8, !tbaa !9
  %62 = load ptr, ptr %7, align 8, !tbaa !9
  %63 = load i32, ptr %8, align 4, !tbaa !5
  %64 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %61, ptr noundef @.str.1, ptr noundef %62, i32 noundef %63) #7
  br label %81

65:                                               ; preds = %57, %54
  %66 = load ptr, ptr %7, align 8, !tbaa !9
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %72

68:                                               ; preds = %65
  %69 = load ptr, ptr @stderr, align 8, !tbaa !9
  %70 = load ptr, ptr %7, align 8, !tbaa !9
  %71 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %69, ptr noundef @.str.2, ptr noundef %70) #7
  br label %80

72:                                               ; preds = %65
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = icmp sgt i32 %73, 0
  br i1 %74, label %75, label %79

75:                                               ; preds = %72
  %76 = load ptr, ptr @stderr, align 8, !tbaa !9
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %76, ptr noundef @.str.3, i32 noundef %77) #7
  br label %79

79:                                               ; preds = %75, %72
  br label %80

80:                                               ; preds = %79, %68
  br label %81

81:                                               ; preds = %80, %60
  %82 = load ptr, ptr @stderr, align 8, !tbaa !9
  %83 = load ptr, ptr %9, align 8, !tbaa !9
  %84 = load ptr, ptr %10, align 8, !tbaa !9
  %85 = call i32 @vfprintf(ptr noundef %82, ptr noundef %83, ptr noundef %84) #7
  %86 = load ptr, ptr @stderr, align 8, !tbaa !9
  %87 = call i32 @fflush(ptr noundef %86)
  br label %88

88:                                               ; preds = %81, %53
  br label %89

89:                                               ; preds = %88
  %90 = call i32 @osal_fastmutex_release(ptr noundef getelementptr inbounds (%struct.libmdbx_globals, ptr @globals, i32 0, i32 9))
  %91 = icmp eq i32 %90, 0
  %92 = xor i1 %91, true
  %93 = xor i1 %92, true
  %94 = xor i1 %93, true
  %95 = zext i1 %94 to i32
  %96 = sext i32 %95 to i64
  %97 = call i64 @llvm.expect.i64(i64 %96, i64 0)
  %98 = icmp ne i64 %97, 0
  br i1 %98, label %99, label %100

99:                                               ; preds = %89
  call void @mdbx_assert_fail(ptr noundef null, ptr noundef @.str.4, ptr noundef @__func__.debug_log_va, i32 noundef 49) #6
  unreachable

100:                                              ; preds = %89
  br label %101

101:                                              ; preds = %100
  ret void
}

declare i32 @osal_fastmutex_acquire(ptr noundef) #1

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

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

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

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

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #5

; Function Attrs: nounwind
declare i32 @vfprintf(ptr noundef, ptr noundef, ptr noundef) #5

declare i32 @fflush(ptr noundef) #1

declare i32 @osal_fastmutex_release(ptr noundef) #1

attributes #0 = { 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 #1 = { "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(none) }
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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { noreturn }
attributes #7 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 88}
!13 = !{!"libmdbx_globals", !7, i64 0, !6, i64 16, !6, i64 20, !7, i64 24, !7, i64 25, !7, i64 26, !14, i64 27, !6, i64 28, !7, i64 32, !7, i64 40, !15, i64 80, !10, i64 88}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!13, !15, i64 80}


; 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 global %struct.libmdbx_globals, align 8
@.str = external hidden unnamed_addr constant [49 x i8], align 1
@__func__.debug_log_va = external hidden unnamed_addr constant [13 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [49 x i8], align 1

; Function Attrs: cold nounwind optsize uwtable
define dso_local void @debug_log_va(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = tail call i32 @osal_fastmutex_acquire(ptr noundef nonnull getelementptr inbounds (i8, ptr @globals, i64 40)) #4
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %8, label %7, !prof !5

7:                                                ; preds = %5
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str, ptr noundef nonnull @__func__.debug_log_va, i32 noundef 7) #5
  unreachable

8:                                                ; preds = %5
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @globals, i64 32), align 8, !tbaa !6
  %.not27 = icmp eq ptr %9, null
  br i1 %.not27, label %21, label %10

10:                                               ; preds = %8
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @globals, i64 88), align 8, !tbaa !9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  tail call void %9(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #4
  br label %40

14:                                               ; preds = %10
  %15 = load i64, ptr getelementptr inbounds (i8, ptr @globals, i64 80), align 8, !tbaa !15
  %16 = tail call i32 @vsnprintf(ptr noundef nonnull %11, i64 noundef %15, ptr noundef %3, ptr noundef %4) #4
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %40

18:                                               ; preds = %14
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @globals, i64 32), align 8, !tbaa !6
  %20 = load ptr, ptr getelementptr inbounds (i8, ptr @globals, i64 88), align 8, !tbaa !9
  tail call void %19(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %20, i32 noundef %16) #4
  br label %40

21:                                               ; preds = %8
  %22 = icmp ne ptr %1, null
  %23 = icmp sgt i32 %2, 0
  %or.cond = and i1 %22, %23
  br i1 %or.cond, label %24, label %27

24:                                               ; preds = %21
  %25 = load ptr, ptr @stderr, align 8, !tbaa !16
  %26 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.1, ptr noundef nonnull %1, i32 noundef %2) #6
  br label %35

27:                                               ; preds = %21
  br i1 %22, label %28, label %31

28:                                               ; preds = %27
  %29 = load ptr, ptr @stderr, align 8, !tbaa !16
  %30 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %29, ptr noundef nonnull @.str.2, ptr noundef nonnull %1) #6
  br label %35

31:                                               ; preds = %27
  br i1 %23, label %32, label %35

32:                                               ; preds = %31
  %33 = load ptr, ptr @stderr, align 8, !tbaa !16
  %34 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef nonnull @.str.3, i32 noundef %2) #6
  br label %35

35:                                               ; preds = %28, %32, %31, %24
  %36 = load ptr, ptr @stderr, align 8, !tbaa !16
  %37 = tail call i32 @vfprintf(ptr noundef %36, ptr noundef %3, ptr noundef %4) #6
  %38 = load ptr, ptr @stderr, align 8, !tbaa !16
  %39 = tail call i32 @fflush(ptr noundef %38)
  br label %40

40:                                               ; preds = %14, %18, %35, %13
  %41 = tail call i32 @osal_fastmutex_release(ptr noundef nonnull getelementptr inbounds (i8, ptr @globals, i64 40)) #4
  %.not28 = icmp eq i32 %41, 0
  br i1 %.not28, label %43, label %42, !prof !5

42:                                               ; preds = %40
  tail call void @mdbx_assert_fail(ptr noundef null, ptr noundef nonnull @.str.4, ptr noundef nonnull @__func__.debug_log_va, i32 noundef 49) #5
  unreachable

43:                                               ; preds = %40
  ret void
}

declare i32 @osal_fastmutex_acquire(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare noundef i32 @vsnprintf(ptr nocapture noundef, i64 noundef, ptr nocapture noundef readonly, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @vfprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ptr noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #3

declare i32 @osal_fastmutex_release(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { "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 "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 = { nofree 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 = { nounwind }
attributes #5 = { noreturn nounwind }
attributes #6 = { cold 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, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !14, i64 88}
!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, !14, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!10, !13, i64 80}
!16 = !{!14, !14, i64 0}


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