; LLVM IR from KishanBGajera/2024-366-Days-Of-DSA :: Data Structures/Non-Linear/Tree/Binary Search Tree/C (main)

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @printTree(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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %4 = call ptr @getNode(i32 noundef 50)
  store ptr %4, ptr %2, align 8, !tbaa !5
  %5 = call i64 @time(ptr noundef null) #3
  %6 = trunc i64 %5 to i32
  call void @srand(i32 noundef %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %16, %0
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 20
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %19

11:                                               ; preds = %7
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call i32 @rand() #3
  %14 = srem i32 %13, 100
  %15 = call ptr @insertToBST(ptr noundef %12, i32 noundef %14)
  br label %16

16:                                               ; preds = %11
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !11

19:                                               ; preds = %10
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  call void @printTree(ptr noundef %20, i32 noundef 0)
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  call void @inorderTraversal(ptr noundef %21)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  ret i32 0
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) #2

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @rand() #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 = { 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call ptr @getNode(i32 noundef 50)
  %2 = tail call i64 @time(ptr noundef null) #2
  %3 = trunc i64 %2 to i32
  tail call void @srand(i32 noundef %3) #2
  %4 = tail call i32 @rand() #2
  %5 = srem i32 %4, 100
  %6 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %5)
  %7 = tail call i32 @rand() #2
  %8 = srem i32 %7, 100
  %9 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %8)
  %10 = tail call i32 @rand() #2
  %11 = srem i32 %10, 100
  %12 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %11)
  %13 = tail call i32 @rand() #2
  %14 = srem i32 %13, 100
  %15 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %14)
  %16 = tail call i32 @rand() #2
  %17 = srem i32 %16, 100
  %18 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %17)
  %19 = tail call i32 @rand() #2
  %20 = srem i32 %19, 100
  %21 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %20)
  %22 = tail call i32 @rand() #2
  %23 = srem i32 %22, 100
  %24 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %23)
  %25 = tail call i32 @rand() #2
  %26 = srem i32 %25, 100
  %27 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %26)
  %28 = tail call i32 @rand() #2
  %29 = srem i32 %28, 100
  %30 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %29)
  %31 = tail call i32 @rand() #2
  %32 = srem i32 %31, 100
  %33 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %32)
  %34 = tail call i32 @rand() #2
  %35 = srem i32 %34, 100
  %36 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %35)
  %37 = tail call i32 @rand() #2
  %38 = srem i32 %37, 100
  %39 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %38)
  %40 = tail call i32 @rand() #2
  %41 = srem i32 %40, 100
  %42 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %41)
  %43 = tail call i32 @rand() #2
  %44 = srem i32 %43, 100
  %45 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %44)
  %46 = tail call i32 @rand() #2
  %47 = srem i32 %46, 100
  %48 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %47)
  %49 = tail call i32 @rand() #2
  %50 = srem i32 %49, 100
  %51 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %50)
  %52 = tail call i32 @rand() #2
  %53 = srem i32 %52, 100
  %54 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %53)
  %55 = tail call i32 @rand() #2
  %56 = srem i32 %55, 100
  %57 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %56)
  %58 = tail call i32 @rand() #2
  %59 = srem i32 %58, 100
  %60 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %59)
  %61 = tail call i32 @rand() #2
  %62 = srem i32 %61, 100
  %63 = tail call ptr @insertToBST(ptr noundef %1, i32 noundef %62)
  tail call void @printTree(ptr noundef %1, i32 noundef 0)
  tail call void @inorderTraversal(ptr noundef %1)
  ret i32 0
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #1

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 = { 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 #2 = { 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)"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass