; LLVM IR from LeoVen/C-Macro-Collections :: examples (dfs)

; 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, i64, i32, ptr, ptr }
%struct.BinaryTreeNode = type { i32, i8, ptr, ptr, ptr }
%struct.BinaryTreeFVal = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.CMCAllocNode = type { ptr, ptr, ptr, ptr }

; 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 @tree_clear(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.BinaryTree, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store ptr null, ptr %4, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %114, %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %115

13:                                               ; preds = %10
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.BinaryTreeNode, ptr %14, i32 0, i32 3
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %27

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.BinaryTreeNode, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  store ptr %21, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.BinaryTreeNode, ptr %23, i32 0, i32 3
  store ptr %22, ptr %24, align 8, !tbaa !13
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %25, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %26, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %114

27:                                               ; preds = %13
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.BinaryTreeNode, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %43

32:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.BinaryTreeNode, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  store ptr %35, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.BinaryTreeNode, ptr %37, i32 0, i32 3
  store ptr %36, ptr %38, align 8, !tbaa !13
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.BinaryTreeNode, ptr %39, i32 0, i32 2
  store ptr null, ptr %40, align 8, !tbaa !15
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %41, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %42, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %113

43:                                               ; preds = %27
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %69

46:                                               ; preds = %43
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.BinaryTree, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = getelementptr inbounds %struct.BinaryTreeFVal, ptr %49, i32 0, i32 3
  %51 = load ptr, ptr %50, align 8, !tbaa !17
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %62

53:                                               ; preds = %46
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.BinaryTree, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = getelementptr inbounds %struct.BinaryTreeFVal, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !17
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.BinaryTreeNode, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !19
  call void %58(i32 noundef %61)
  br label %62

62:                                               ; preds = %53, %46
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.BinaryTree, ptr %63, i32 0, i32 4
  %65 = load ptr, ptr %64, align 8, !tbaa !20
  %66 = getelementptr inbounds %struct.CMCAllocNode, ptr %65, i32 0, i32 3
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  call void %67(ptr noundef %68)
  store ptr null, ptr %3, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %62, %43
  br label %70

70:                                               ; preds = %111, %69
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = icmp ne ptr %71, null
  br i1 %72, label %73, label %112

73:                                               ; preds = %70
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.BinaryTree, ptr %74, i32 0, i32 3
  %76 = load ptr, ptr %75, align 8, !tbaa !16
  %77 = getelementptr inbounds %struct.BinaryTreeFVal, ptr %76, i32 0, i32 3
  %78 = load ptr, ptr %77, align 8, !tbaa !17
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %89

80:                                               ; preds = %73
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.BinaryTree, ptr %81, i32 0, i32 3
  %83 = load ptr, ptr %82, align 8, !tbaa !16
  %84 = getelementptr inbounds %struct.BinaryTreeFVal, ptr %83, i32 0, i32 3
  %85 = load ptr, ptr %84, align 8, !tbaa !17
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.BinaryTreeNode, ptr %86, i32 0, i32 0
  %88 = load i32, ptr %87, align 8, !tbaa !19
  call void %85(i32 noundef %88)
  br label %89

89:                                               ; preds = %80, %73
  %90 = load ptr, ptr %2, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.BinaryTree, ptr %90, i32 0, i32 4
  %92 = load ptr, ptr %91, align 8, !tbaa !20
  %93 = getelementptr inbounds %struct.CMCAllocNode, ptr %92, i32 0, i32 3
  %94 = load ptr, ptr %93, align 8, !tbaa !21
  %95 = load ptr, ptr %3, align 8, !tbaa !5
  call void %94(ptr noundef %95)
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.BinaryTreeNode, ptr %96, i32 0, i32 2
  %98 = load ptr, ptr %97, align 8, !tbaa !15
  %99 = icmp ne ptr %98, null
  br i1 %99, label %100, label %106

100:                                              ; preds = %89
  %101 = load ptr, ptr %4, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.BinaryTreeNode, ptr %101, i32 0, i32 2
  %103 = load ptr, ptr %102, align 8, !tbaa !15
  store ptr %103, ptr %3, align 8, !tbaa !5
  %104 = load ptr, ptr %4, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.BinaryTreeNode, ptr %104, i32 0, i32 2
  store ptr null, ptr %105, align 8, !tbaa !15
  br label %112

106:                                              ; preds = %89
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %107, ptr %3, align 8, !tbaa !5
  %108 = load ptr, ptr %4, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.BinaryTreeNode, ptr %108, i32 0, i32 3
  %110 = load ptr, ptr %109, align 8, !tbaa !13
  store ptr %110, ptr %4, align 8, !tbaa !5
  br label %111

111:                                              ; preds = %106
  br label %70, !llvm.loop !23

112:                                              ; preds = %100, %70
  br label %113

113:                                              ; preds = %112, %32
  br label %114

114:                                              ; preds = %113, %18
  br label %10, !llvm.loop !25

115:                                              ; preds = %10
  %116 = load ptr, ptr %2, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.BinaryTree, ptr %116, i32 0, i32 1
  store i64 0, ptr %117, align 8, !tbaa !26
  %118 = load ptr, ptr %2, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.BinaryTree, ptr %118, i32 0, i32 0
  store ptr null, ptr %119, align 8, !tbaa !9
  %120 = load ptr, ptr %2, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.BinaryTree, ptr %120, i32 0, i32 2
  store i32 0, ptr %121, align 8, !tbaa !27
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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 }

!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, !11, i64 8, !12, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"BinaryTreeNode", !12, i64 0, !7, i64 4, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!14, !6, i64 8}
!16 = !{!10, !6, i64 24}
!17 = !{!18, !6, i64 24}
!18 = !{!"BinaryTreeFVal", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!19 = !{!14, !12, i64 0}
!20 = !{!10, !6, i64 32}
!21 = !{!22, !6, i64 24}
!22 = !{!"CMCAllocNode", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}
!26 = !{!10, !11, i64 8}
!27 = !{!10, !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"

; Function Attrs: nounwind uwtable
define dso_local void @tree_clear(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not55 = icmp eq ptr %2, null
  br i1 %.not55, label %._crit_edge, label %.lr.ph58

.lr.ph58:                                         ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  br label %5

5:                                                ; preds = %.loopexit, %.lr.ph58
  %.057 = phi ptr [ %2, %.lr.ph58 ], [ %.3, %.loopexit ]
  %.03556 = phi ptr [ null, %.lr.ph58 ], [ %.237, %.loopexit ]
  %6 = getelementptr inbounds i8, ptr %.057, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %.not43 = icmp eq ptr %7, null
  br i1 %.not43, label %9, label %8

8:                                                ; preds = %5
  store ptr %.03556, ptr %6, align 8, !tbaa !12
  br label %.loopexit

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %.057, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %.not44 = icmp eq ptr %11, null
  br i1 %.not44, label %13, label %12

12:                                               ; preds = %9
  store ptr %.03556, ptr %6, align 8, !tbaa !12
  store ptr null, ptr %10, align 8, !tbaa !14
  br label %.loopexit

13:                                               ; preds = %9
  %14 = icmp eq ptr %.03556, null
  br i1 %14, label %15, label %.lr.ph

15:                                               ; preds = %13
  %16 = load ptr, ptr %3, align 8, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %16, i64 24
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %.not45 = icmp eq ptr %18, null
  br i1 %.not45, label %._crit_edge.loopexit, label %19

19:                                               ; preds = %15
  %20 = load i32, ptr %.057, align 8, !tbaa !18
  tail call void %18(i32 noundef %20) #2
  br label %._crit_edge.loopexit

.lr.ph:                                           ; preds = %13, %34
  %.254 = phi ptr [ %.13653, %34 ], [ %.057, %13 ]
  %.13653 = phi ptr [ %36, %34 ], [ %.03556, %13 ]
  %21 = load ptr, ptr %3, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %21, i64 24
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %.not47 = icmp eq ptr %23, null
  br i1 %.not47, label %26, label %24

24:                                               ; preds = %.lr.ph
  %25 = load i32, ptr %.254, align 8, !tbaa !18
  tail call void %23(i32 noundef %25) #2
  br label %26

26:                                               ; preds = %24, %.lr.ph
  %27 = load ptr, ptr %4, align 8, !tbaa !19
  %28 = getelementptr inbounds i8, ptr %27, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !20
  tail call void %29(ptr noundef nonnull %.254) #2
  %30 = getelementptr inbounds i8, ptr %.13653, i64 8
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %.not48 = icmp eq ptr %31, null
  br i1 %.not48, label %34, label %32

32:                                               ; preds = %26
  %33 = getelementptr inbounds i8, ptr %.13653, i64 8
  store ptr null, ptr %33, align 8, !tbaa !14
  br label %.loopexit

34:                                               ; preds = %26
  %35 = getelementptr inbounds i8, ptr %.13653, i64 16
  %36 = load ptr, ptr %35, align 8, !tbaa !12
  %.not46 = icmp eq ptr %36, null
  br i1 %.not46, label %.loopexit, label %.lr.ph, !llvm.loop !22

.loopexit:                                        ; preds = %34, %12, %32, %8
  %.237 = phi ptr [ %.057, %8 ], [ %.057, %12 ], [ %.13653, %32 ], [ null, %34 ]
  %.3 = phi ptr [ %7, %8 ], [ %11, %12 ], [ %31, %32 ], [ %.13653, %34 ]
  br label %5, !llvm.loop !24

._crit_edge.loopexit:                             ; preds = %15, %19
  %37 = load ptr, ptr %4, align 8, !tbaa !19
  %38 = getelementptr inbounds i8, ptr %37, i64 24
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  tail call void %39(ptr noundef nonnull %.057) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %0, i8 0, i64 20, i1 false)
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 0}
!6 = !{!"BinaryTree", !7, i64 0, !10, i64 8, !11, 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 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !7, i64 16}
!13 = !{!"BinaryTreeNode", !11, i64 0, !8, i64 4, !7, i64 8, !7, i64 16, !7, i64 24}
!14 = !{!13, !7, i64 8}
!15 = !{!6, !7, i64 24}
!16 = !{!17, !7, i64 24}
!17 = !{!"BinaryTreeFVal", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!18 = !{!13, !11, i64 0}
!19 = !{!6, !7, i64 32}
!20 = !{!21, !7, i64 24}
!21 = !{!"CMCAllocNode", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


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