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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @tree_empty(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @tree_iter_next(ptr noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.BinaryTreeIter, ptr %4, i32 0, i32 6
  %6 = load i8, ptr %5, align 1, !tbaa !9, !range !13, !noundef !14
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i1 false, ptr %2, align 1
  br label %95

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.BinaryTreeIter, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !15
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.BinaryTreeIter, ptr %13, i32 0, i32 3
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = icmp eq ptr %12, %15
  br i1 %16, label %17, label %20

17:                                               ; preds = %9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.BinaryTreeIter, ptr %18, i32 0, i32 6
  store i8 1, ptr %19, align 1, !tbaa !9
  store i1 false, ptr %2, align 1
  br label %95

20:                                               ; preds = %9
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.BinaryTreeIter, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %24 = call zeroext i1 @tree_empty(ptr noundef %23)
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.BinaryTreeIter, ptr %25, i32 0, i32 5
  %27 = zext i1 %24 to i8
  store i8 %27, ptr %26, align 8, !tbaa !18
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.BinaryTreeIter, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = getelementptr inbounds %struct.BinaryTreeNode, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !19
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %62

34:                                               ; preds = %20
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.BinaryTreeIter, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = getelementptr inbounds %struct.BinaryTreeNode, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !19
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.BinaryTreeIter, ptr %40, i32 0, i32 1
  store ptr %39, ptr %41, align 8, !tbaa !15
  br label %42

42:                                               ; preds = %49, %34
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.BinaryTreeIter, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = getelementptr inbounds %struct.BinaryTreeNode, ptr %45, i32 0, i32 3
  %47 = load ptr, ptr %46, align 8, !tbaa !22
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %57

49:                                               ; preds = %42
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.BinaryTreeIter, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  %53 = getelementptr inbounds %struct.BinaryTreeNode, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !22
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.BinaryTreeIter, ptr %55, i32 0, i32 1
  store ptr %54, ptr %56, align 8, !tbaa !15
  br label %42, !llvm.loop !23

57:                                               ; preds = %42
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.BinaryTreeIter, ptr %58, i32 0, i32 4
  %60 = load i64, ptr %59, align 8, !tbaa !25
  %61 = add i64 %60, 1
  store i64 %61, ptr %59, align 8, !tbaa !25
  store i1 true, ptr %2, align 1
  br label %95

62:                                               ; preds = %20
  br label %63

63:                                               ; preds = %87, %62
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.BinaryTreeIter, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = getelementptr inbounds %struct.BinaryTreeNode, ptr %66, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !26
  %69 = getelementptr inbounds %struct.BinaryTreeNode, ptr %68, i32 0, i32 3
  %70 = load ptr, ptr %69, align 8, !tbaa !22
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.BinaryTreeIter, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  %74 = icmp eq ptr %70, %73
  br i1 %74, label %75, label %87

75:                                               ; preds = %63
  %76 = load ptr, ptr %3, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.BinaryTreeIter, ptr %76, i32 0, i32 1
  %78 = load ptr, ptr %77, align 8, !tbaa !15
  %79 = getelementptr inbounds %struct.BinaryTreeNode, ptr %78, i32 0, i32 4
  %80 = load ptr, ptr %79, align 8, !tbaa !26
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.BinaryTreeIter, ptr %81, i32 0, i32 1
  store ptr %80, ptr %82, align 8, !tbaa !15
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.BinaryTreeIter, ptr %83, i32 0, i32 4
  %85 = load i64, ptr %84, align 8, !tbaa !25
  %86 = add i64 %85, 1
  store i64 %86, ptr %84, align 8, !tbaa !25
  store i1 true, ptr %2, align 1
  br label %95

87:                                               ; preds = %63
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.BinaryTreeIter, ptr %88, i32 0, i32 1
  %90 = load ptr, ptr %89, align 8, !tbaa !15
  %91 = getelementptr inbounds %struct.BinaryTreeNode, ptr %90, i32 0, i32 4
  %92 = load ptr, ptr %91, align 8, !tbaa !26
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.BinaryTreeIter, ptr %93, i32 0, i32 1
  store ptr %92, ptr %94, align 8, !tbaa !15
  br label %63

95:                                               ; preds = %75, %57, %17, %8
  %96 = load i1, ptr %2, align 1
  ret i1 %96
}

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

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


; 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
declare dso_local zeroext i1 @tree_empty(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @tree_iter_next(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 41
  %3 = load i8, ptr %2, align 1, !tbaa !5, !range !12, !noundef !13
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %40, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = icmp eq ptr %7, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %5
  store i8 1, ptr %2, align 1, !tbaa !5
  br label %40

12:                                               ; preds = %5
  %13 = load ptr, ptr %0, align 8, !tbaa !16
  %14 = tail call zeroext i1 @tree_empty(ptr noundef %13)
  %15 = getelementptr inbounds i8, ptr %0, i64 40
  %16 = zext i1 %14 to i8
  store i8 %16, ptr %15, align 8, !tbaa !17
  %17 = load ptr, ptr %6, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %.not = icmp eq ptr %19, null
  br i1 %.not, label %.preheader, label %.preheader24

.preheader:                                       ; preds = %12
  %20 = getelementptr inbounds i8, ptr %17, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !21
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !22
  %24 = icmp eq ptr %23, %17
  br i1 %24, label %._crit_edge, label %.lr.ph

.preheader24:                                     ; preds = %12, %.preheader24
  %storemerge = phi ptr [ %26, %.preheader24 ], [ %19, %12 ]
  %25 = getelementptr inbounds i8, ptr %storemerge, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !22
  %.not23 = icmp eq ptr %26, null
  br i1 %.not23, label %27, label %.preheader24, !llvm.loop !23

27:                                               ; preds = %.preheader24
  store ptr %storemerge, ptr %6, align 8, !tbaa !14
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  %29 = load i64, ptr %28, align 8, !tbaa !25
  %30 = add i64 %29, 1
  store i64 %30, ptr %28, align 8, !tbaa !25
  br label %40

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.lcssa = phi ptr [ %21, %.preheader ], [ %36, %.lr.ph ]
  store ptr %.lcssa, ptr %6, align 8, !tbaa !14
  %31 = getelementptr inbounds i8, ptr %0, i64 32
  %32 = load i64, ptr %31, align 8, !tbaa !25
  %33 = add i64 %32, 1
  store i64 %33, ptr %31, align 8, !tbaa !25
  br label %40

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %34 = phi ptr [ %36, %.lr.ph ], [ %21, %.preheader ]
  %35 = getelementptr inbounds i8, ptr %34, i64 24
  %36 = load ptr, ptr %35, align 8, !tbaa !21
  %37 = getelementptr inbounds i8, ptr %36, i64 16
  %38 = load ptr, ptr %37, align 8, !tbaa !22
  %39 = icmp eq ptr %38, %34
  br i1 %39, label %._crit_edge, label %.lr.ph

40:                                               ; preds = %1, %._crit_edge, %27, %11
  %.0 = phi i1 [ false, %11 ], [ true, %27 ], [ true, %._crit_edge ], [ false, %1 ]
  ret i1 %.0
}

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

!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, !11, i64 41}
!6 = !{!"BinaryTreeIter", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !11, i64 41}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !7, i64 24}
!16 = !{!6, !7, i64 0}
!17 = !{!6, !11, i64 40}
!18 = !{!19, !7, i64 8}
!19 = !{!"BinaryTreeNode", !20, i64 0, !8, i64 4, !7, i64 8, !7, i64 16, !7, i64 24}
!20 = !{!"int", !8, i64 0}
!21 = !{!19, !7, i64 24}
!22 = !{!19, !7, i64 16}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!6, !10, i64 32}


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