; LLVM IR from AlgoGenesis/C :: Binary Tree Algorithms/AVL Trees Algorithms (Program)

; 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.3 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [12 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_value(ptr noundef, i32 noundef) #1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  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
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %10

10:                                               ; preds = %70, %0
  br label %11

11:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.4, ptr noundef %3)
  %13 = load i8, ptr %3, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = icmp eq i32 %14, 105
  br i1 %15, label %16, label %22

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.6, ptr noundef %4)
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !10
  %21 = call ptr @insert_value(ptr noundef %19, i32 noundef %20)
  store ptr %21, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %67

22:                                               ; preds = %11
  %23 = load i8, ptr %3, align 1, !tbaa !9
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 %24, 100
  br i1 %25, label %26, label %41

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  %28 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.6, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !10
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !10
  %31 = call ptr @delete_value(ptr noundef %29, i32 noundef %30, ptr noundef %6)
  store ptr %31, ptr %2, align 8, !tbaa !5
  %32 = load i32, ptr %6, align 4, !tbaa !10
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %37

34:                                               ; preds = %26
  %35 = load i32, ptr %5, align 4, !tbaa !10
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, i32 noundef %35)
  br label %40

37:                                               ; preds = %26
  %38 = load i32, ptr %5, align 4, !tbaa !10
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i32 noundef %38)
  br label %40

40:                                               ; preds = %37, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %66

41:                                               ; preds = %22
  %42 = load i8, ptr %3, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = icmp eq i32 %43, 115
  br i1 %44, label %45, label %50

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  %47 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.6, ptr noundef %7)
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = load i32, ptr %7, align 4, !tbaa !10
  call void @search_value(ptr noundef %48, i32 noundef %49)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %65

50:                                               ; preds = %41
  %51 = load i8, ptr %3, align 1, !tbaa !9
  %52 = sext i8 %51 to i32
  %53 = icmp eq i32 %52, 111
  br i1 %53, label %54, label %57

54:                                               ; preds = %50
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  call void @inorder(ptr noundef %55)
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  br label %64

57:                                               ; preds = %50
  %58 = load i8, ptr %3, align 1, !tbaa !9
  %59 = sext i8 %58 to i32
  %60 = icmp eq i32 %59, 113
  br i1 %60, label %61, label %63

61:                                               ; preds = %57
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.12)
  store i32 3, ptr %8, align 4
  br label %68

63:                                               ; preds = %57
  br label %64

64:                                               ; preds = %63, %54
  br label %65

65:                                               ; preds = %64, %45
  br label %66

66:                                               ; preds = %65, %40
  br label %67

67:                                               ; preds = %66, %16
  store i32 0, ptr %8, align 4
  br label %68

68:                                               ; preds = %67, %61
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  %69 = load i32, ptr %8, align 4
  switch i32 %69, label %73 [
    i32 0, label %70
    i32 3, label %71
  ]

70:                                               ; preds = %68
  br label %10

71:                                               ; preds = %68
  store i32 0, ptr %1, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %72 = load i32, ptr %1, align 4
  ret i32 %72

73:                                               ; preds = %68
  unreachable
}

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

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"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"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"

@.str.3 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [12 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_value(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @search_value(ptr noundef, i32 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 ptr @delete_value(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i8, align 1
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %7

7:                                                ; preds = %29, %0
  %.05 = phi ptr [ null, %0 ], [ %.2, %29 ]
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.4, ptr noundef nonnull %1)
  %9 = load i8, ptr %1, align 1, !tbaa !5
  switch i8 %9, label %29 [
    i8 105, label %10
    i8 100, label %15
    i8 115, label %23
    i8 111, label %27
    i8 113, label %30
  ]

10:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.6, ptr noundef nonnull %2)
  %13 = load i32, ptr %2, align 4, !tbaa !8
  %14 = call ptr @insert_value(ptr noundef %.05, i32 noundef %13)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  br label %29

15:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.6, ptr noundef nonnull %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store i32 0, ptr %4, align 4, !tbaa !8
  %18 = load i32, ptr %3, align 4, !tbaa !8
  %19 = call ptr @delete_value(ptr noundef %.05, i32 noundef %18, ptr noundef nonnull %4)
  %20 = load i32, ptr %4, align 4, !tbaa !8
  %.not = icmp eq i32 %20, 0
  %21 = load i32, ptr %3, align 4, !tbaa !8
  %.str.9..str.8 = select i1 %.not, ptr @.str.9, ptr @.str.8
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.9..str.8, i32 noundef %21)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %29

23:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %24 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.6, ptr noundef nonnull %5)
  %26 = load i32, ptr %5, align 4, !tbaa !8
  call void @search_value(ptr noundef %.05, i32 noundef %26)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %29

27:                                               ; preds = %7
  call void @inorder(ptr noundef %.05)
  %28 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  br label %29

29:                                               ; preds = %10, %23, %27, %15, %7
  %.2 = phi ptr [ %14, %10 ], [ %19, %15 ], [ %.05, %23 ], [ %.05, %27 ], [ %.05, %7 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #3
  br label %7

30:                                               ; preds = %7
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12)
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #3
  ret i32 0
}

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

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


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