; LLVM IR from adventure-db/adventure :: src/db/store (btree)

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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [42 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [58 x i8], align 1

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #1

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @btree_add(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #2 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %29, label %15

15:                                               ; preds = %4
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = call ptr @__errno_location() #4
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  br label %25

21:                                               ; preds = %15
  %22 = call ptr @__errno_location() #4
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = call ptr @strerror(i32 noundef %23) #5
  br label %25

25:                                               ; preds = %21, %20
  %26 = phi ptr [ @.str.2, %20 ], [ %24, %21 ]
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 556, ptr noundef %26) #5
  %28 = call ptr @__errno_location() #4
  store i32 0, ptr %28, align 4, !tbaa !11
  br label %64

29:                                               ; preds = %4
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %46, label %32

32:                                               ; preds = %29
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = call ptr @__errno_location() #4
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %32
  br label %42

38:                                               ; preds = %32
  %39 = call ptr @__errno_location() #4
  %40 = load i32, ptr %39, align 4, !tbaa !11
  %41 = call ptr @strerror(i32 noundef %40) #5
  br label %42

42:                                               ; preds = %38, %37
  %43 = phi ptr [ @.str.2, %37 ], [ %41, %38 ]
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 557, ptr noundef %43) #5
  %45 = call ptr @__errno_location() #4
  store i32 0, ptr %45, align 4, !tbaa !11
  br label %64

46:                                               ; preds = %29
  store i64 0, ptr %10, align 8, !tbaa !9
  store i64 0, ptr %11, align 8, !tbaa !9
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i64, ptr %7, align 8, !tbaa !9
  %49 = load i64, ptr %8, align 8, !tbaa !9
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = call i64 @btree_recur_add(ptr noundef %47, i64 noundef %48, i64 noundef %49, i64 noundef %50, ptr noundef %10, ptr noundef %11)
  store i64 %51, ptr %12, align 8, !tbaa !9
  %52 = load i64, ptr %11, align 8, !tbaa !9
  %53 = icmp ne i64 %52, 0
  br i1 %53, label %54, label %62

54:                                               ; preds = %46
  %55 = load ptr, ptr @stderr, align 8, !tbaa !5
  %56 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %55, ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 563) #5
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = load i64, ptr %10, align 8, !tbaa !9
  %60 = load i64, ptr %11, align 8, !tbaa !9
  %61 = call i64 @btree_root_create(ptr noundef %57, i64 noundef %58, i64 noundef %59, i64 noundef %60)
  store i64 %61, ptr %10, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %54, %46
  %63 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %63, ptr %5, align 8
  br label %66

64:                                               ; preds = %42, %25
  %65 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %65, ptr %5, align 8
  br label %66

66:                                               ; preds = %64, %62
  %67 = load i64, ptr %5, align 8
  ret i64 %67
}

; Function Attrs: nounwind uwtable
declare hidden i64 @btree_recur_add(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @btree_root_create(ptr noundef, i64 noundef, i64 noundef, i64 noundef) #3

attributes #0 = { 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 #1 = { nounwind willreturn memory(none) "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 = { 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 = { 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 = { nounwind willreturn memory(none) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [42 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [58 x i8], align 1

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i64 @btree_add(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #3 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %7, label %17

7:                                                ; preds = %4
  %8 = load ptr, ptr @stderr, align 8, !tbaa !5
  %9 = tail call ptr @__errno_location() #5
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %14, label %12

12:                                               ; preds = %7
  %13 = tail call ptr @strerror(i32 noundef %10) #6
  br label %14

14:                                               ; preds = %7, %12
  %15 = phi ptr [ %13, %12 ], [ @.str.2, %7 ]
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 556, ptr noundef %15) #7
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %37

17:                                               ; preds = %4
  %.not13 = icmp eq i64 %1, 0
  br i1 %.not13, label %18, label %28

18:                                               ; preds = %17
  %19 = load ptr, ptr @stderr, align 8, !tbaa !5
  %20 = tail call ptr @__errno_location() #5
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %25, label %23

23:                                               ; preds = %18
  %24 = tail call ptr @strerror(i32 noundef %21) #6
  br label %25

25:                                               ; preds = %18, %23
  %26 = phi ptr [ %24, %23 ], [ @.str.2, %18 ]
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 557, ptr noundef %26) #7
  store i32 0, ptr %20, align 4, !tbaa !9
  br label %37

28:                                               ; preds = %17
  store i64 0, ptr %5, align 8, !tbaa !11
  store i64 0, ptr %6, align 8, !tbaa !11
  %29 = call i64 @btree_recur_add(ptr noundef nonnull %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %30 = load i64, ptr %6, align 8, !tbaa !11
  %.not14 = icmp eq i64 %30, 0
  br i1 %.not14, label %._crit_edge, label %31

._crit_edge:                                      ; preds = %28
  %.pre = load i64, ptr %5, align 8, !tbaa !11
  br label %37

31:                                               ; preds = %28
  %32 = load ptr, ptr @stderr, align 8, !tbaa !5
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 563) #7
  %34 = load i64, ptr %5, align 8, !tbaa !11
  %35 = load i64, ptr %6, align 8, !tbaa !11
  %36 = call i64 @btree_root_create(ptr noundef nonnull %0, i64 noundef %29, i64 noundef %34, i64 noundef %35)
  br label %37

37:                                               ; preds = %31, %._crit_edge, %14, %25
  %.0 = phi i64 [ 0, %25 ], [ %1, %14 ], [ %.pre, %._crit_edge ], [ %36, %31 ]
  ret i64 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i64 @btree_recur_add(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

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

attributes #0 = { 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 #1 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { 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 #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 = { 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 #5 = { nounwind willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { 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 = !{!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass