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

@.str.3 = external hidden unnamed_addr constant [3 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @tree_print(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %16, ptr noundef @.str.3, ptr noundef %17) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.BinaryTree, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  store ptr %21, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #3
  store i8 0, ptr %13, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store i64 0, ptr %14, align 8, !tbaa !15
  br label %22

22:                                               ; preds = %108, %5
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %109

25:                                               ; preds = %22
  %26 = load i8, ptr %13, align 1, !tbaa !13, !range !16, !noundef !17
  %27 = trunc i8 %26 to i1
  br i1 %27, label %39, label %28

28:                                               ; preds = %25
  br label %29

29:                                               ; preds = %34, %28
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.BinaryTreeNode, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %38

34:                                               ; preds = %29
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.BinaryTreeNode, ptr %35, i32 0, i32 3
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  store ptr %37, ptr %12, align 8, !tbaa !5
  br label %29, !llvm.loop !20

38:                                               ; preds = %29
  br label %39

39:                                               ; preds = %38, %25
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.BinaryTree, ptr %40, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !22
  %43 = getelementptr inbounds %struct.BinaryTreeFVal, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !23
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.BinaryTreeNode, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !25
  %49 = call zeroext i1 %44(ptr noundef %45, i32 noundef %48)
  br i1 %49, label %51, label %50

50:                                               ; preds = %39
  store i1 false, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %113

51:                                               ; preds = %39
  %52 = load i64, ptr %14, align 8, !tbaa !15
  %53 = add i64 %52, 1
  store i64 %53, ptr %14, align 8, !tbaa !15
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.BinaryTree, ptr %54, i32 0, i32 1
  %56 = load i64, ptr %55, align 8, !tbaa !26
  %57 = icmp ult i64 %53, %56
  br i1 %57, label %58, label %62

58:                                               ; preds = %51
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %59, ptr noundef @.str.3, ptr noundef %60) #3
  br label %62

62:                                               ; preds = %58, %51
  store i8 1, ptr %13, align 1, !tbaa !13
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.BinaryTreeNode, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !27
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %71

67:                                               ; preds = %62
  store i8 0, ptr %13, align 1, !tbaa !13
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.BinaryTreeNode, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !27
  store ptr %70, ptr %12, align 8, !tbaa !5
  br label %108

71:                                               ; preds = %62
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.BinaryTreeNode, ptr %72, i32 0, i32 4
  %74 = load ptr, ptr %73, align 8, !tbaa !28
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %106

76:                                               ; preds = %71
  br label %77

77:                                               ; preds = %92, %76
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.BinaryTreeNode, ptr %78, i32 0, i32 4
  %80 = load ptr, ptr %79, align 8, !tbaa !28
  %81 = icmp ne ptr %80, null
  br i1 %81, label %82, label %90

82:                                               ; preds = %77
  %83 = load ptr, ptr %12, align 8, !tbaa !5
  %84 = load ptr, ptr %12, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.BinaryTreeNode, ptr %84, i32 0, i32 4
  %86 = load ptr, ptr %85, align 8, !tbaa !28
  %87 = getelementptr inbounds %struct.BinaryTreeNode, ptr %86, i32 0, i32 2
  %88 = load ptr, ptr %87, align 8, !tbaa !27
  %89 = icmp eq ptr %83, %88
  br label %90

90:                                               ; preds = %82, %77
  %91 = phi i1 [ false, %77 ], [ %89, %82 ]
  br i1 %91, label %92, label %96

92:                                               ; preds = %90
  %93 = load ptr, ptr %12, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.BinaryTreeNode, ptr %93, i32 0, i32 4
  %95 = load ptr, ptr %94, align 8, !tbaa !28
  store ptr %95, ptr %12, align 8, !tbaa !5
  br label %77, !llvm.loop !29

96:                                               ; preds = %90
  %97 = load ptr, ptr %12, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.BinaryTreeNode, ptr %97, i32 0, i32 4
  %99 = load ptr, ptr %98, align 8, !tbaa !28
  %100 = icmp ne ptr %99, null
  br i1 %100, label %102, label %101

101:                                              ; preds = %96
  br label %109

102:                                              ; preds = %96
  %103 = load ptr, ptr %12, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.BinaryTreeNode, ptr %103, i32 0, i32 4
  %105 = load ptr, ptr %104, align 8, !tbaa !28
  store ptr %105, ptr %12, align 8, !tbaa !5
  br label %107

106:                                              ; preds = %71
  br label %109

107:                                              ; preds = %102
  br label %108

108:                                              ; preds = %107, %67
  br label %22, !llvm.loop !30

109:                                              ; preds = %106, %101, %22
  %110 = load ptr, ptr %8, align 8, !tbaa !5
  %111 = load ptr, ptr %11, align 8, !tbaa !5
  %112 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %110, ptr noundef @.str.3, ptr noundef %111) #3
  store i1 true, ptr %6, align 1
  store i32 1, ptr %15, align 4
  br label %113

113:                                              ; preds = %109, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %114 = load i1, ptr %6, align 1
  ret i1 %114
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = { 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, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!19, !6, i64 16}
!19 = !{!"BinaryTreeNode", !12, i64 0, !7, i64 4, !6, i64 8, !6, i64 16, !6, i64 24}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !6, i64 24}
!23 = !{!24, !6, i64 16}
!24 = !{!"BinaryTreeFVal", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!25 = !{!19, !12, i64 0}
!26 = !{!10, !11, i64 8}
!27 = !{!19, !6, i64 8}
!28 = !{!19, !6, i64 24}
!29 = distinct !{!29, !21}
!30 = distinct !{!30, !21}


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

@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @tree_print(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.3, ptr noundef %2) #2
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %.not41 = icmp eq ptr %7, null
  br i1 %.not41, label %.critedge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  br label %.critedge

.critedge:                                        ; preds = %.critedge.backedge, %.lr.ph
  %.044 = phi i64 [ 0, %.lr.ph ], [ %18, %.critedge.backedge ]
  %.02543 = phi i1 [ false, %.lr.ph ], [ %26, %.critedge.backedge ]
  %.02642 = phi ptr [ %7, %.lr.ph ], [ %.02642.be, %.critedge.backedge ]
  br i1 %.02543, label %.loopexit, label %.preheader37

.preheader37:                                     ; preds = %.critedge, %.preheader37
  %.127 = phi ptr [ %11, %.preheader37 ], [ %.02642, %.critedge ]
  %10 = getelementptr inbounds i8, ptr %.127, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %.not33 = icmp eq ptr %11, null
  br i1 %.not33, label %.loopexit, label %.preheader37, !llvm.loop !14

.loopexit:                                        ; preds = %.preheader37, %.critedge
  %.2 = phi ptr [ %.02642, %.critedge ], [ %.127, %.preheader37 ]
  %12 = load ptr, ptr %8, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = load i32, ptr %.2, align 8, !tbaa !19
  %16 = tail call zeroext i1 %14(ptr noundef %1, i32 noundef %15) #2
  br i1 %16, label %17, label %.loopexit39

17:                                               ; preds = %.loopexit
  %18 = add i64 %.044, 1
  %19 = load i64, ptr %9, align 8, !tbaa !20
  %20 = icmp ult i64 %18, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %17
  %22 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.3, ptr noundef %3) #2
  br label %23

23:                                               ; preds = %21, %17
  %24 = getelementptr inbounds i8, ptr %.2, i64 8
  %25 = load ptr, ptr %24, align 8, !tbaa !21
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %.critedge.backedge

.critedge.backedge:                               ; preds = %32, %23
  %.02642.be = phi ptr [ %25, %23 ], [ %31, %32 ]
  br label %.critedge

27:                                               ; preds = %23
  %28 = getelementptr inbounds i8, ptr %.2, i64 24
  %29 = load ptr, ptr %28, align 8, !tbaa !22
  %.not34 = icmp eq ptr %29, null
  br i1 %.not34, label %.critedge.thread, label %.preheader

.preheader:                                       ; preds = %27, %32
  %.3 = phi ptr [ %31, %32 ], [ %.2, %27 ]
  %30 = getelementptr inbounds i8, ptr %.3, i64 24
  %31 = load ptr, ptr %30, align 8, !tbaa !22
  %.not35 = icmp eq ptr %31, null
  br i1 %.not35, label %.critedge.thread, label %32

32:                                               ; preds = %.preheader
  %33 = getelementptr inbounds i8, ptr %31, i64 8
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = icmp eq ptr %.3, %34
  br i1 %35, label %.preheader, label %.critedge.backedge, !llvm.loop !23

.critedge.thread:                                 ; preds = %27, %.preheader, %5
  %36 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %1, ptr noundef nonnull @.str.3, ptr noundef %4) #2
  br label %.loopexit39

.loopexit39:                                      ; preds = %.loopexit, %.critedge.thread
  %.028 = phi i1 [ true, %.critedge.thread ], [ false, %.loopexit ]
  ret i1 %.028
}

attributes #0 = { 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 #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, !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 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !7, i64 24}
!17 = !{!18, !7, i64 16}
!18 = !{!"BinaryTreeFVal", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!19 = !{!13, !11, i64 0}
!20 = !{!6, !10, i64 8}
!21 = !{!13, !7, i64 8}
!22 = !{!13, !7, i64 24}
!23 = distinct !{!23, !15}


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