; LLVM IR from ksw2000/Data-Structure-in-C :: Tree (AVL-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.avlTree = type { ptr, ptr, ptr, ptr, ptr }

@__const.main.list = external hidden unnamed_addr constant [13 x %struct.person], align 16
@.str.7 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.8 = 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: 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) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @avlTree_create(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @print_detail(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @print(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #2 {
  %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 @avlTree_create(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.avlTree, 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.avlTree, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  call void @print_detail(ptr noundef %26)
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.avlTree, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  call void @print(ptr noundef %29)
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %53, %23
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %56

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

53:                                               ; preds = %34
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %5, align 4, !tbaa !5
  br label %30, !llvm.loop !17

56:                                               ; preds = %30
  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
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 #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 = !{!"avlTree", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!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.7 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.8 = 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: 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) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @avlTree_create(ptr noundef) local_unnamed_addr #2

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %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 @avlTree_create(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 @print_detail(ptr noundef %29)
  %30 = load ptr, ptr %2, align 8, !tbaa !10
  call void @print(ptr noundef %30)
  %31 = getelementptr inbounds i8, ptr %2, i64 24
  %32 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %34)
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %38)
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %42)
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %46)
  %47 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %48 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %50)
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %54)
  %55 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %56 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %58)
  %59 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %60 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %62)
  %63 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %64 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %66)
  %67 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %68 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %70)
  %71 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %72 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %74)
  %75 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %76 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %78)
  %79 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %80 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, 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 @print(ptr noundef %82)
  %83 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  call void @llvm.lifetime.end.p0(i64 468, ptr nonnull %1) #4
  ret i32 0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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 = !{!"avlTree", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!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