; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C/Algorithms/Graph-Algorithms (tree_traversal)

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

%struct.node = type { i32, ptr, ptr }

@root = external dso_local global ptr, align 8
@__const.main.array = external hidden unnamed_addr constant [7 x i32], align 16
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [24 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 ptr @search(i32 noundef) #0

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca [7 x i32], align 16
  %4 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 28, ptr %3) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.main.array, i64 28, i1 false)
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %13, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 7
  br i1 %7, label %8, label %16

8:                                                ; preds = %5
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [7 x i32], ptr %3, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  call void @insert(i32 noundef %12)
  br label %13

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

16:                                               ; preds = %5
  store i32 31, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = call ptr @search(i32 noundef %17)
  store ptr %18, ptr %4, align 8, !tbaa !11
  %19 = load ptr, ptr %4, align 8, !tbaa !11
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %27

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !11
  %23 = getelementptr inbounds %struct.node, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !13
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %24)
  %26 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %30

27:                                               ; preds = %16
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %28)
  br label %30

30:                                               ; preds = %27, %21
  store i32 15, ptr %2, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = call ptr @search(i32 noundef %31)
  store ptr %32, ptr %4, align 8, !tbaa !11
  %33 = load ptr, ptr %4, align 8, !tbaa !11
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %41

35:                                               ; preds = %30
  %36 = load ptr, ptr %4, align 8, !tbaa !11
  %37 = getelementptr inbounds %struct.node, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !13
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %38)
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %44

41:                                               ; preds = %30
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %42)
  br label %44

44:                                               ; preds = %41, %35
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %46 = load ptr, ptr @root, align 8, !tbaa !11
  call void @pre_order_traversal(ptr noundef %46)
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  %48 = load ptr, ptr @root, align 8, !tbaa !11
  call void @inorder_traversal(ptr noundef %48)
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  %50 = load ptr, ptr @root, align 8, !tbaa !11
  call void @post_order_traversal(ptr noundef %50)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 28, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"node", !6, i64 0, !12, i64 8, !12, i64 16}


; 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
@__const.main.array = external hidden unnamed_addr constant [7 x i32], align 16
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [22 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [24 x i8], align 1

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = load i32, ptr @__const.main.array, align 16, !tbaa !5
  tail call void @insert(i32 noundef %1)
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 4), align 4, !tbaa !5
  tail call void @insert(i32 noundef %2)
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 8), align 8, !tbaa !5
  tail call void @insert(i32 noundef %3)
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 12), align 4, !tbaa !5
  tail call void @insert(i32 noundef %4)
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 16), align 16, !tbaa !5
  tail call void @insert(i32 noundef %5)
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 20), align 4, !tbaa !5
  tail call void @insert(i32 noundef %6)
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 24), align 8, !tbaa !5
  tail call void @insert(i32 noundef %7)
  %8 = tail call ptr @search(i32 noundef 31)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %13, label %9

9:                                                ; preds = %0
  %10 = load i32, ptr %8, align 8, !tbaa !9
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %10)
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %15

13:                                               ; preds = %0
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef 31)
  br label %15

15:                                               ; preds = %13, %9
  %16 = tail call ptr @search(i32 noundef 15)
  %.not12 = icmp eq ptr %16, null
  br i1 %.not12, label %21, label %17

17:                                               ; preds = %15
  %18 = load i32, ptr %16, align 8, !tbaa !9
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %18)
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %23

21:                                               ; preds = %15
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef 15)
  br label %23

23:                                               ; preds = %21, %17
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %25 = load ptr, ptr @root, align 8, !tbaa !12
  tail call void @pre_order_traversal(ptr noundef %25)
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  %27 = load ptr, ptr @root, align 8, !tbaa !12
  tail call void @inorder_traversal(ptr noundef %27)
  %28 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  %29 = load ptr, ptr @root, align 8, !tbaa !12
  tail call void @post_order_traversal(ptr noundef %29)
  ret i32 0
}

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

!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, !6, i64 0}
!10 = !{!"node", !6, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}


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