; LLVM IR from ksw2000/Data-Structure-in-C :: Tree (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"

%struct.person = type { [32 x i8], i32 }
%struct.binaryTree = type { ptr, ptr, ptr, ptr }

@__const.main.list = external hidden unnamed_addr constant [13 x %struct.person], align 16
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 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 @__BinaryTree__(ptr noundef) #1

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

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

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

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

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

11:                                               ; preds = %7
  %12 = load ptr, ptr %4, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.binaryTree, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = getelementptr inbounds [13 x %struct.person], ptr %2, i64 0, i64 0
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds %struct.person, ptr %16, i64 %18
  call void %14(ptr noundef %15, ptr noundef %19)
  br label %20

20:                                               ; preds = %11
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %5, align 4, !tbaa !5
  br label %7, !llvm.loop !13

23:                                               ; preds = %7
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.binaryTree, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  call void @inorder(ptr noundef %26)
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %51, %23
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %54

32:                                               ; preds = %28
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [13 x %struct.person], ptr %2, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.person, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds [32 x i8], ptr %36, i64 0, i64 0
  %38 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %37)
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.binaryTree, ptr %39, i32 0, i32 3
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  %42 = load ptr, ptr %4, align 8, !tbaa !9
  %43 = getelementptr inbounds [13 x %struct.person], ptr %2, i64 0, i64 0
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds %struct.person, ptr %43, i64 %45
  call void %41(ptr noundef %42, ptr noundef %46)
  %47 = load ptr, ptr %4, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.binaryTree, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  call void @inorder(ptr noundef %49)
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %51

51:                                               ; preds = %32
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %5, align 4, !tbaa !5
  br label %28, !llvm.loop !17

54:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 468, 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 = { 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"binaryTree", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !10, i64 0}
!16 = !{!12, !10, i64 24}
!17 = distinct !{!17, !14}


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

%struct.person = type { [32 x i8], i32 }

@__const.main.list = external hidden unnamed_addr constant [13 x %struct.person], align 16
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 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 @__BinaryTree__(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @inorder(ptr 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
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = alloca [13 x %struct.person], align 16
  call void @llvm.lifetime.start.p0(i64 468, ptr nonnull %1) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(468) %1, ptr noundef nonnull align 16 dereferenceable(468) @__const.main.list, i64 468, i1 false)
  %2 = tail call ptr @__BinaryTree__(ptr noundef nonnull @personCmpFunc)
  %3 = getelementptr inbounds i8, ptr %2, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  call void %4(ptr noundef %2, ptr noundef nonnull %1) #4
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 36
  call void %5(ptr noundef %2, ptr noundef nonnull %6) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 72
  call void %7(ptr noundef %2, ptr noundef nonnull %8) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %1, i64 108
  call void %9(ptr noundef %2, ptr noundef nonnull %10) #4
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %1, i64 144
  call void %11(ptr noundef %2, ptr noundef nonnull %12) #4
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %1, i64 180
  call void %13(ptr noundef %2, ptr noundef nonnull %14) #4
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %1, i64 216
  call void %15(ptr noundef %2, ptr noundef nonnull %16) #4
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %1, i64 252
  call void %17(ptr noundef %2, ptr noundef nonnull %18) #4
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %1, i64 288
  call void %19(ptr noundef %2, ptr noundef nonnull %20) #4
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %1, i64 324
  call void %21(ptr noundef %2, ptr noundef nonnull %22) #4
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %1, i64 360
  call void %23(ptr noundef %2, ptr noundef nonnull %24) #4
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %1, i64 396
  call void %25(ptr noundef %2, ptr noundef nonnull %26) #4
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %1, i64 432
  call void %27(ptr noundef %2, ptr noundef nonnull %28) #4
  %29 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %29)
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %31 = getelementptr inbounds i8, ptr %2, i64 24
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %1)
  %33 = load ptr, ptr %31, align 8, !tbaa !11
  call void %33(ptr noundef nonnull %2, ptr noundef nonnull %1) #4
  %34 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %34)
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %6)
  %37 = load ptr, ptr %31, align 8, !tbaa !11
  call void %37(ptr noundef nonnull %2, ptr noundef nonnull %6) #4
  %38 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %38)
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %8)
  %41 = load ptr, ptr %31, align 8, !tbaa !11
  call void %41(ptr noundef nonnull %2, ptr noundef nonnull %8) #4
  %42 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %42)
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %10)
  %45 = load ptr, ptr %31, align 8, !tbaa !11
  call void %45(ptr noundef nonnull %2, ptr noundef nonnull %10) #4
  %46 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %46)
  %47 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %48 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %12)
  %49 = load ptr, ptr %31, align 8, !tbaa !11
  call void %49(ptr noundef nonnull %2, ptr noundef nonnull %12) #4
  %50 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %50)
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %14)
  %53 = load ptr, ptr %31, align 8, !tbaa !11
  call void %53(ptr noundef nonnull %2, ptr noundef nonnull %14) #4
  %54 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %54)
  %55 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %56 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %16)
  %57 = load ptr, ptr %31, align 8, !tbaa !11
  call void %57(ptr noundef nonnull %2, ptr noundef nonnull %16) #4
  %58 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %58)
  %59 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %60 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %18)
  %61 = load ptr, ptr %31, align 8, !tbaa !11
  call void %61(ptr noundef nonnull %2, ptr noundef nonnull %18) #4
  %62 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %62)
  %63 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %64 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %20)
  %65 = load ptr, ptr %31, align 8, !tbaa !11
  call void %65(ptr noundef nonnull %2, ptr noundef nonnull %20) #4
  %66 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %66)
  %67 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %68 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %22)
  %69 = load ptr, ptr %31, align 8, !tbaa !11
  call void %69(ptr noundef nonnull %2, ptr noundef nonnull %22) #4
  %70 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %70)
  %71 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %72 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %24)
  %73 = load ptr, ptr %31, align 8, !tbaa !11
  call void %73(ptr noundef nonnull %2, ptr noundef nonnull %24) #4
  %74 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %74)
  %75 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %76 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %26)
  %77 = load ptr, ptr %31, align 8, !tbaa !11
  call void %77(ptr noundef nonnull %2, ptr noundef nonnull %26) #4
  %78 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %78)
  %79 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  %80 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef nonnull %28)
  %81 = load ptr, ptr %31, align 8, !tbaa !11
  call void %81(ptr noundef nonnull %2, ptr noundef nonnull %28) #4
  %82 = load ptr, ptr %2, align 8, !tbaa !10
  call void @inorder(ptr noundef %82)
  %83 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  call void @llvm.lifetime.end.p0(i64 468, ptr nonnull %1) #4
  ret i32 0
}

; Function Attrs: mustprogress 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 = { 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 = { mustprogress 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, !7, i64 16}
!6 = !{!"binaryTree", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!6, !7, i64 24}


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