; 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.binaryTree = type { ptr, ptr, ptr, ptr }
%struct.bstNode = type { ptr, ptr, ptr }

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [48 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
define dso_local void @binaryTree_delete(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.binaryTree, ptr %9, i32 0, i32 0
  store ptr %10, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.binaryTree, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %6, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %45, %2
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %27

17:                                               ; preds = %14
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.binaryTree, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.bstNode, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = call i32 %20(ptr noundef %21, ptr noundef %24)
  %26 = icmp ne i32 %25, 0
  br label %27

27:                                               ; preds = %17, %14
  %28 = phi i1 [ false, %14 ], [ %26, %17 ]
  br i1 %28, label %29, label %49

29:                                               ; preds = %27
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.binaryTree, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.bstNode, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !12
  %37 = call i32 %32(ptr noundef %33, ptr noundef %36)
  %38 = icmp slt i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %29
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.bstNode, ptr %40, i32 0, i32 1
  br label %45

42:                                               ; preds = %29
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.bstNode, ptr %43, i32 0, i32 2
  br label %45

45:                                               ; preds = %42, %39
  %46 = phi ptr [ %41, %39 ], [ %44, %42 ]
  store ptr %46, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  store ptr %48, ptr %6, align 8, !tbaa !5
  br label %14, !llvm.loop !14

49:                                               ; preds = %27
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %55, label %52

52:                                               ; preds = %49
  %53 = load ptr, ptr @stderr, align 8, !tbaa !5
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef @.str) #4
  call void @exit(i32 noundef 1) #5
  unreachable

55:                                               ; preds = %49
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.bstNode, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %65

60:                                               ; preds = %55
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.bstNode, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !17
  %64 = icmp ne ptr %63, null
  br i1 %64, label %82, label %65

65:                                               ; preds = %60, %55
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.bstNode, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !17
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %74

70:                                               ; preds = %65
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.bstNode, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !17
  br label %78

74:                                               ; preds = %65
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.bstNode, ptr %75, i32 0, i32 2
  %77 = load ptr, ptr %76, align 8, !tbaa !16
  br label %78

78:                                               ; preds = %74, %70
  %79 = phi ptr [ %73, %70 ], [ %77, %74 ]
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %79, ptr %80, align 8, !tbaa !5
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %81) #4
  br label %110

82:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.bstNode, ptr %83, i32 0, i32 2
  store ptr %84, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.bstNode, ptr %85, i32 0, i32 2
  %87 = load ptr, ptr %86, align 8, !tbaa !16
  store ptr %87, ptr %8, align 8, !tbaa !5
  br label %88

88:                                               ; preds = %96, %82
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.bstNode, ptr %89, i32 0, i32 1
  %91 = load ptr, ptr %90, align 8, !tbaa !17
  %92 = icmp ne ptr %91, null
  br i1 %92, label %93, label %99

93:                                               ; preds = %88
  %94 = load ptr, ptr %8, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.bstNode, ptr %94, i32 0, i32 1
  store ptr %95, ptr %7, align 8, !tbaa !5
  br label %96

96:                                               ; preds = %93
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = load ptr, ptr %97, align 8, !tbaa !5
  store ptr %98, ptr %8, align 8, !tbaa !5
  br label %88, !llvm.loop !18

99:                                               ; preds = %88
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.bstNode, ptr %100, i32 0, i32 0
  %102 = load ptr, ptr %101, align 8, !tbaa !12
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.bstNode, ptr %103, i32 0, i32 0
  store ptr %102, ptr %104, align 8, !tbaa !12
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.bstNode, ptr %105, i32 0, i32 2
  %107 = load ptr, ptr %106, align 8, !tbaa !16
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %107, ptr %108, align 8, !tbaa !5
  %109 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %109) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %110

110:                                              ; preds = %99, %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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 = { 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 = { noreturn 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 }
attributes #5 = { noreturn 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, !6, i64 0}
!10 = !{!"binaryTree", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!10, !6, i64 8}
!12 = !{!13, !6, i64 0}
!13 = !{!"bstNode", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!13, !6, i64 16}
!17 = !{!13, !6, i64 8}
!18 = distinct !{!18, !15}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [48 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @binaryTree_delete(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.03144 = load ptr, ptr %0, align 8, !tbaa !5
  %.not45 = icmp eq ptr %.03144, null
  br i1 %.not45, label %.critedge41, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  %5 = load ptr, ptr %.03144, align 8, !tbaa !11
  %6 = tail call i32 %4(ptr noundef %1, ptr noundef %5) #4
  %.not3654 = icmp eq i32 %6, 0
  br i1 %.not3654, label %.critedge, label %.lr.ph56

7:                                                ; preds = %.lr.ph56
  %8 = load ptr, ptr %3, align 8, !tbaa !9
  %9 = load ptr, ptr %.031, align 8, !tbaa !11
  %10 = tail call i32 %8(ptr noundef %1, ptr noundef %9) #4
  %.not36 = icmp eq i32 %10, 0
  br i1 %.not36, label %.critedge.loopexit, label %.lr.ph56, !llvm.loop !13

.lr.ph56:                                         ; preds = %.lr.ph, %7
  %.0314755 = phi ptr [ %.031, %7 ], [ %.03144, %.lr.ph ]
  %11 = load ptr, ptr %3, align 8, !tbaa !9
  %12 = load ptr, ptr %.0314755, align 8, !tbaa !11
  %13 = tail call i32 %11(ptr noundef %1, ptr noundef %12) #4
  %14 = icmp slt i32 %13, 0
  %.v = select i1 %14, i64 8, i64 16
  %15 = getelementptr inbounds i8, ptr %.0314755, i64 %.v
  %.031 = load ptr, ptr %15, align 8, !tbaa !5
  %.not = icmp eq ptr %.031, null
  br i1 %.not, label %.critedge41, label %7, !llvm.loop !13

.critedge41:                                      ; preds = %.lr.ph56, %2
  %16 = load ptr, ptr @stderr, align 8, !tbaa !5
  %17 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef nonnull @.str) #5
  tail call void @exit(i32 noundef 1) #6
  unreachable

.critedge.loopexit:                               ; preds = %7
  %18 = getelementptr inbounds i8, ptr %.0314755, i64 %.v
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph
  %.03147.lcssa = phi ptr [ %.03144, %.lr.ph ], [ %.031, %.critedge.loopexit ]
  %.03246.lcssa = phi ptr [ %0, %.lr.ph ], [ %18, %.critedge.loopexit ]
  %19 = getelementptr inbounds i8, ptr %.03147.lcssa, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %.not37 = icmp eq ptr %20, null
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.03147.lcssa, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !16
  br i1 %.not37, label %.critedge._crit_edge, label %21

21:                                               ; preds = %.critedge
  %.not38 = icmp eq ptr %.pre, null
  br i1 %.not38, label %.critedge._crit_edge, label %.preheader

.critedge._crit_edge:                             ; preds = %.critedge, %21
  %22 = phi ptr [ null, %21 ], [ %.pre, %.critedge ]
  %.not39 = icmp eq ptr %22, null
  %spec.select = select i1 %.not39, ptr %20, ptr %22
  store ptr %spec.select, ptr %.03246.lcssa, align 8, !tbaa !5
  br label %29

.preheader:                                       ; preds = %21, %.preheader
  %.030 = phi ptr [ %23, %.preheader ], [ %19, %21 ]
  %.0 = phi ptr [ %24, %.preheader ], [ %20, %21 ]
  %23 = getelementptr inbounds i8, ptr %.0, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %.not40 = icmp eq ptr %24, null
  br i1 %.not40, label %25, label %.preheader, !llvm.loop !17

25:                                               ; preds = %.preheader
  %26 = load ptr, ptr %.0, align 8, !tbaa !11
  store ptr %26, ptr %.03147.lcssa, align 8, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %.0, i64 16
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  store ptr %28, ptr %.030, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %25, %.critedge._crit_edge
  %.0.lcssa.sink = phi ptr [ %.0, %25 ], [ %.03147.lcssa, %.critedge._crit_edge ]
  tail call void @free(ptr noundef nonnull %.0.lcssa.sink) #4
  ret void
}

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #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 = { 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 #2 = { noreturn 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #5 = { cold nounwind }
attributes #6 = { noreturn 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, !6, i64 8}
!10 = !{!"binaryTree", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!12, !6, i64 0}
!12 = !{!"bstNode", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !6, i64 16}
!16 = !{!12, !6, i64 8}
!17 = distinct !{!17, !14}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass