; LLVM IR from MakeContributions/DSA :: algorithms/C/tree (binary-search-tree)

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

@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 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(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @insert(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @is_full(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @depth(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @is_perfect(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @print(ptr noundef) #1

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local void @deallocate(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store ptr null, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = call ptr @insert(ptr noundef %3, i32 noundef 37)
  store ptr %4, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = call ptr @insert(ptr noundef %5, i32 noundef 19)
  store ptr %6, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = call ptr @insert(ptr noundef %7, i32 noundef 4)
  store ptr %8, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = call ptr @insert(ptr noundef %9, i32 noundef 22)
  store ptr %10, ptr %2, align 8, !tbaa !5
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = call ptr @insert(ptr noundef %11, i32 noundef 51)
  store ptr %12, ptr %2, align 8, !tbaa !5
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call ptr @insert(ptr noundef %13, i32 noundef 55)
  store ptr %14, ptr %2, align 8, !tbaa !5
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call ptr @insert(ptr noundef %15, i32 noundef 42)
  store ptr %16, ptr %2, align 8, !tbaa !5
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = call zeroext i1 @is_full(ptr noundef %17)
  br i1 %18, label %19, label %21

19:                                               ; preds = %0
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %23

21:                                               ; preds = %0
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %23

23:                                               ; preds = %21, %19
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = call i32 @depth(ptr noundef %25)
  %27 = sub nsw i32 %26, 1
  %28 = call zeroext i1 @is_perfect(ptr noundef %24, i32 noundef %27, i32 noundef 0)
  br i1 %28, label %29, label %31

29:                                               ; preds = %23
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %33

31:                                               ; preds = %23
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %33

33:                                               ; preds = %31, %29
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  call void @print(ptr noundef %34)
  call void @deallocate(ptr noundef %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  ret i32 0
}

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

!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"}


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

@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 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: nounwind uwtable
declare dso_local ptr @insert(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @is_full(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @depth(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @is_perfect(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @print(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @deallocate(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #3
  %2 = tail call ptr @insert(ptr noundef null, i32 noundef 37)
  %3 = tail call ptr @insert(ptr noundef %2, i32 noundef 19)
  %4 = tail call ptr @insert(ptr noundef %3, i32 noundef 4)
  %5 = tail call ptr @insert(ptr noundef %4, i32 noundef 22)
  %6 = tail call ptr @insert(ptr noundef %5, i32 noundef 51)
  %7 = tail call ptr @insert(ptr noundef %6, i32 noundef 55)
  %8 = tail call ptr @insert(ptr noundef %7, i32 noundef 42)
  store ptr %8, ptr %1, align 8, !tbaa !5
  %9 = tail call zeroext i1 @is_full(ptr noundef %8)
  %.str.1..str.2 = select i1 %9, ptr @.str.1, ptr @.str.2
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.1..str.2)
  %11 = tail call i32 @depth(ptr noundef %8)
  %12 = add nsw i32 %11, -1
  %13 = tail call zeroext i1 @is_perfect(ptr noundef %8, i32 noundef %12, i32 noundef 0)
  %.str.4.sink = select i1 %13, ptr @.str.3, ptr @.str.4
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.4.sink)
  tail call void @print(ptr noundef %8)
  call void @deallocate(ptr noundef nonnull %1)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #3
  ret i32 0
}

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


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