; LLVM IR from FOSS-UCSC/FOSSALGO :: data-structures/ds-btree/c (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"

@root = external dso_local global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @insert(i32 noundef) #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: nounwind uwtable
declare dso_local void @preorder(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @inorder(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @postorder(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @smallest(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @largest(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @search(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @deleteele(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  br label %6

6:                                                ; preds = %53, %0
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp ne i32 %7, 12
  br i1 %8, label %9, label %54

9:                                                ; preds = %6
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str.9)
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.12)
  %14 = call i32 (ptr, ...) @printf(ptr noundef @.str.13)
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.14)
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str.15)
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.16)
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.17)
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.18)
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.19, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %21 = load i32, ptr %3, align 4, !tbaa !5
  switch i32 %21, label %53 [
    i32 1, label %22
    i32 2, label %26
    i32 3, label %29
    i32 4, label %32
    i32 5, label %35
    i32 6, label %38
    i32 7, label %41
    i32 8, label %47
  ]

22:                                               ; preds = %9
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str.20)
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.19, ptr noundef %4)
  %25 = load i32, ptr %4, align 4, !tbaa !5
  call void @insert(i32 noundef %25)
  br label %53

26:                                               ; preds = %9
  %27 = load ptr, ptr @root, align 8, !tbaa !9
  store ptr %27, ptr %2, align 8, !tbaa !9
  %28 = load ptr, ptr %2, align 8, !tbaa !9
  call void @preorder(ptr noundef %28)
  br label %53

29:                                               ; preds = %9
  %30 = load ptr, ptr @root, align 8, !tbaa !9
  store ptr %30, ptr %2, align 8, !tbaa !9
  %31 = load ptr, ptr %2, align 8, !tbaa !9
  call void @inorder(ptr noundef %31)
  br label %53

32:                                               ; preds = %9
  %33 = load ptr, ptr @root, align 8, !tbaa !9
  store ptr %33, ptr %2, align 8, !tbaa !9
  %34 = load ptr, ptr %2, align 8, !tbaa !9
  call void @postorder(ptr noundef %34)
  br label %53

35:                                               ; preds = %9
  %36 = load ptr, ptr @root, align 8, !tbaa !9
  store ptr %36, ptr %2, align 8, !tbaa !9
  %37 = load ptr, ptr %2, align 8, !tbaa !9
  call void @smallest(ptr noundef %37)
  br label %53

38:                                               ; preds = %9
  %39 = load ptr, ptr @root, align 8, !tbaa !9
  store ptr %39, ptr %2, align 8, !tbaa !9
  %40 = load ptr, ptr %2, align 8, !tbaa !9
  call void @largest(ptr noundef %40)
  br label %53

41:                                               ; preds = %9
  %42 = load ptr, ptr @root, align 8, !tbaa !9
  store ptr %42, ptr %2, align 8, !tbaa !9
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.21)
  %44 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.19, ptr noundef %4)
  %45 = load ptr, ptr %2, align 8, !tbaa !9
  %46 = load i32, ptr %4, align 4, !tbaa !5
  call void @search(ptr noundef %45, i32 noundef %46)
  br label %53

47:                                               ; preds = %9
  %48 = load ptr, ptr @root, align 8, !tbaa !9
  store ptr %48, ptr %2, align 8, !tbaa !9
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.22)
  %50 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.19, ptr noundef %4)
  %51 = load ptr, ptr %2, align 8, !tbaa !9
  %52 = load i32, ptr %4, align 4, !tbaa !5
  call void @deleteele(ptr noundef %51, i32 noundef %52)
  br label %53

53:                                               ; preds = %47, %41, %38, %35, %32, %29, %26, %22, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %6, !llvm.loop !11

54:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %55 = load i32, ptr %1, align 4
  ret i32 %55
}

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@root = external dso_local local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @insert(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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @search(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @deleteele(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.lr.ph.preheader:
  %0 = alloca i32, align 4
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %0) #3
  store i32 0, ptr %0, align 4, !tbaa !5
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %39
  %3 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9)
  %4 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  %5 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  %6 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12)
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13)
  %8 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14)
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.15)
  %10 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.16)
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.17)
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.18)
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.19, ptr noundef nonnull %0)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %14 = load i32, ptr %0, align 4, !tbaa !5
  switch i32 %14, label %39 [
    i32 1, label %15
    i32 2, label %19
    i32 3, label %21
    i32 4, label %23
    i32 5, label %25
    i32 6, label %27
    i32 7, label %29
    i32 8, label %34
  ]

15:                                               ; preds = %.lr.ph
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.20)
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.19, ptr noundef nonnull %1)
  %18 = load i32, ptr %1, align 4, !tbaa !5
  call void @insert(i32 noundef %18)
  br label %thread-pre-split

19:                                               ; preds = %.lr.ph
  %20 = load ptr, ptr @root, align 8, !tbaa !9
  call void @preorder(ptr noundef %20)
  br label %thread-pre-split

21:                                               ; preds = %.lr.ph
  %22 = load ptr, ptr @root, align 8, !tbaa !9
  call void @inorder(ptr noundef %22)
  br label %thread-pre-split

23:                                               ; preds = %.lr.ph
  %24 = load ptr, ptr @root, align 8, !tbaa !9
  call void @postorder(ptr noundef %24)
  br label %thread-pre-split

25:                                               ; preds = %.lr.ph
  %26 = load ptr, ptr @root, align 8, !tbaa !9
  call void @smallest(ptr noundef %26)
  br label %thread-pre-split

27:                                               ; preds = %.lr.ph
  %28 = load ptr, ptr @root, align 8, !tbaa !9
  call void @largest(ptr noundef %28)
  br label %thread-pre-split

29:                                               ; preds = %.lr.ph
  %30 = load ptr, ptr @root, align 8, !tbaa !9
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.21)
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.19, ptr noundef nonnull %1)
  %33 = load i32, ptr %1, align 4, !tbaa !5
  call void @search(ptr noundef %30, i32 noundef %33)
  br label %thread-pre-split

34:                                               ; preds = %.lr.ph
  %35 = load ptr, ptr @root, align 8, !tbaa !9
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22)
  %37 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.19, ptr noundef nonnull %1)
  %38 = load i32, ptr %1, align 4, !tbaa !5
  call void @deleteele(ptr noundef %35, i32 noundef %38)
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %15, %19, %21, %23, %25, %27, %29, %34
  %.pr = load i32, ptr %0, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %thread-pre-split, %.lr.ph
  %40 = phi i32 [ %.pr, %thread-pre-split ], [ %14, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  %.not = icmp eq i32 %40, 12
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %0) #3
  ret i32 0
}

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

attributes #0 = { 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 = { 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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass