; LLVM IR from LamberttLiu/CS-Basic-SelfLearning :: 【DSA】数据结构与算法（C语言版本）/src/tree (tree_in_order_get_predecessor)

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

@pre = external dso_local global ptr, align 8
@finalNode = 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 [39 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [46 x i8], align 1

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @CreateBiTree() #1

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

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

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %32

12:                                               ; preds = %8
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [7 x i32], ptr %5, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !9
  store i32 %16, ptr %4, align 4, !tbaa !9
  store i32 %16, ptr %3, align 4, !tbaa !9
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = call zeroext i1 @GetPredecessor(ptr noundef %17, ptr noundef %3)
  %19 = zext i1 %18 to i32
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %21, label %25

21:                                               ; preds = %12
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = load i32, ptr %3, align 4, !tbaa !9
  %24 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %22, i32 noundef %23)
  br label %28

25:                                               ; preds = %12
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %26)
  br label %28

28:                                               ; preds = %25, %21
  store ptr null, ptr @pre, align 8, !tbaa !5
  store ptr null, ptr @finalNode, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %6, align 4, !tbaa !9
  br label %8, !llvm.loop !11

32:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 28, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, 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 = { "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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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"

@pre = external dso_local local_unnamed_addr global ptr, align 8
@finalNode = 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 [39 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [46 x i8], align 1

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @CreateBiTree() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = tail call ptr @CreateBiTree()
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %3 = load i32, ptr @__const.main.array, align 16, !tbaa !5
  store i32 %3, ptr %1, align 4, !tbaa !5
  %4 = call zeroext i1 @GetPredecessor(ptr noundef %2, ptr noundef nonnull %1)
  br i1 %4, label %5, label %8

5:                                                ; preds = %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %3, i32 noundef %6)
  br label %10

8:                                                ; preds = %0
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %3)
  br label %10

10:                                               ; preds = %8, %5
  store ptr null, ptr @pre, align 8, !tbaa !9
  store ptr null, ptr @finalNode, align 8, !tbaa !9
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 4), align 4, !tbaa !5
  store i32 %11, ptr %1, align 4, !tbaa !5
  %12 = call zeroext i1 @GetPredecessor(ptr noundef %2, ptr noundef nonnull %1)
  br i1 %12, label %15, label %13

13:                                               ; preds = %10
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %11)
  br label %18

15:                                               ; preds = %10
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %11, i32 noundef %16)
  br label %18

18:                                               ; preds = %15, %13
  store ptr null, ptr @pre, align 8, !tbaa !9
  store ptr null, ptr @finalNode, align 8, !tbaa !9
  %19 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 8), align 8, !tbaa !5
  store i32 %19, ptr %1, align 4, !tbaa !5
  %20 = call zeroext i1 @GetPredecessor(ptr noundef %2, ptr noundef nonnull %1)
  br i1 %20, label %23, label %21

21:                                               ; preds = %18
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %19)
  br label %26

23:                                               ; preds = %18
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %19, i32 noundef %24)
  br label %26

26:                                               ; preds = %23, %21
  store ptr null, ptr @pre, align 8, !tbaa !9
  store ptr null, ptr @finalNode, align 8, !tbaa !9
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 12), align 4, !tbaa !5
  store i32 %27, ptr %1, align 4, !tbaa !5
  %28 = call zeroext i1 @GetPredecessor(ptr noundef %2, ptr noundef nonnull %1)
  br i1 %28, label %31, label %29

29:                                               ; preds = %26
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %27)
  br label %34

31:                                               ; preds = %26
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %27, i32 noundef %32)
  br label %34

34:                                               ; preds = %31, %29
  store ptr null, ptr @pre, align 8, !tbaa !9
  store ptr null, ptr @finalNode, align 8, !tbaa !9
  %35 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 16), align 16, !tbaa !5
  store i32 %35, ptr %1, align 4, !tbaa !5
  %36 = call zeroext i1 @GetPredecessor(ptr noundef %2, ptr noundef nonnull %1)
  br i1 %36, label %39, label %37

37:                                               ; preds = %34
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %35)
  br label %42

39:                                               ; preds = %34
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %35, i32 noundef %40)
  br label %42

42:                                               ; preds = %39, %37
  store ptr null, ptr @pre, align 8, !tbaa !9
  store ptr null, ptr @finalNode, align 8, !tbaa !9
  %43 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 20), align 4, !tbaa !5
  store i32 %43, ptr %1, align 4, !tbaa !5
  %44 = call zeroext i1 @GetPredecessor(ptr noundef %2, ptr noundef nonnull %1)
  br i1 %44, label %47, label %45

45:                                               ; preds = %42
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %43)
  br label %50

47:                                               ; preds = %42
  %48 = load i32, ptr %1, align 4, !tbaa !5
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %43, i32 noundef %48)
  br label %50

50:                                               ; preds = %47, %45
  store ptr null, ptr @pre, align 8, !tbaa !9
  store ptr null, ptr @finalNode, align 8, !tbaa !9
  %51 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.array, i64 24), align 8, !tbaa !5
  store i32 %51, ptr %1, align 4, !tbaa !5
  %52 = call zeroext i1 @GetPredecessor(ptr noundef %2, ptr noundef nonnull %1)
  br i1 %52, label %55, label %53

53:                                               ; preds = %50
  %54 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %51)
  br label %58

55:                                               ; preds = %50
  %56 = load i32, ptr %1, align 4, !tbaa !5
  %57 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %51, i32 noundef %56)
  br label %58

58:                                               ; preds = %55, %53
  store ptr null, ptr @pre, align 8, !tbaa !9
  store ptr null, ptr @finalNode, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0
}

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


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