; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_graph)

; 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.HandleGraphTraversal = type { ptr, ptr, ptr, i32 }
%struct.MArray = type { i32, i16, %union.anon.0 }
%union.anon.0 = type { ptr }
%struct.GraphNode = type { ptr, ptr, ptr, i32, i32, i32, 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 ptr @GraphBFTraversal(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.HandleGraphTraversal, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %23

19:                                               ; preds = %4
  %20 = call ptr @ArrayCreate(i32 noundef 0, i32 noundef 4, ptr noundef null)
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.HandleGraphTraversal, ptr %21, i32 0, i32 0
  store ptr %20, ptr %22, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %19, %4
  br label %24

24:                                               ; preds = %23
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.HandleGraphTraversal, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.MArray, ptr %27, i32 0, i32 0
  store i32 0, ptr %28, align 8, !tbaa !12
  br label %29

29:                                               ; preds = %24
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.HandleGraphTraversal, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.GraphNode, ptr %33, i32 0, i32 5
  %35 = call ptr @m_ArrayPushBack(ptr noundef %32, ptr noundef %34)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !15
  br label %36

36:                                               ; preds = %121, %29
  %37 = load i32, ptr %10, align 4, !tbaa !15
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.HandleGraphTraversal, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.MArray, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !12
  %43 = icmp slt i32 %37, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %36
  store i32 4, ptr %11, align 4
  br label %124

45:                                               ; preds = %36
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.HandleGraphTraversal, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.HandleGraphTraversal, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.MArray, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = load i32, ptr %10, align 4, !tbaa !15
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %53, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !15
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds ptr, ptr %48, i64 %58
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  store ptr %60, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.HandleGraphTraversal, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !18
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.GraphNode, ptr %64, i32 0, i32 5
  %66 = load i32, ptr %65, align 8, !tbaa !19
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %63, i64 %67
  store i32 1, ptr %68, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = call i32 %69(ptr noundef %70, ptr noundef %71)
  store i32 %72, ptr %12, align 4, !tbaa !15
  %73 = load i32, ptr %12, align 4, !tbaa !15
  %74 = icmp ne i32 %73, 0
  br i1 %74, label %75, label %77

75:                                               ; preds = %45
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %76, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %118

77:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !15
  br label %78

78:                                               ; preds = %114, %77
  %79 = load i32, ptr %13, align 4, !tbaa !15
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.GraphNode, ptr %80, i32 0, i32 3
  %82 = load i32, ptr %81, align 8, !tbaa !21
  %83 = icmp slt i32 %79, %82
  br i1 %83, label %85, label %84

84:                                               ; preds = %78
  store i32 7, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %117

85:                                               ; preds = %78
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.GraphNode, ptr %86, i32 0, i32 1
  %88 = load ptr, ptr %87, align 8, !tbaa !22
  %89 = load i32, ptr %13, align 4, !tbaa !15
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds ptr, ptr %88, i64 %90
  %92 = load ptr, ptr %91, align 8, !tbaa !5
  store ptr %92, ptr %14, align 8, !tbaa !5
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.HandleGraphTraversal, ptr %93, i32 0, i32 1
  %95 = load ptr, ptr %94, align 8, !tbaa !18
  %96 = load ptr, ptr %14, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.GraphNode, ptr %96, i32 0, i32 5
  %98 = load i32, ptr %97, align 8, !tbaa !19
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds i32, ptr %95, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !15
  %102 = icmp eq i32 %101, 1
  br i1 %102, label %103, label %104

103:                                              ; preds = %85
  store i32 9, ptr %11, align 4
  br label %111

104:                                              ; preds = %85
  %105 = load ptr, ptr %6, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.HandleGraphTraversal, ptr %105, i32 0, i32 0
  %107 = load ptr, ptr %106, align 8, !tbaa !9
  %108 = load ptr, ptr %14, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.GraphNode, ptr %108, i32 0, i32 5
  %110 = call ptr @m_ArrayPushBack(ptr noundef %107, ptr noundef %109)
  store i32 0, ptr %11, align 4
  br label %111

111:                                              ; preds = %104, %103
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %112 = load i32, ptr %11, align 4
  switch i32 %112, label %129 [
    i32 0, label %113
    i32 9, label %114
  ]

113:                                              ; preds = %111
  br label %114

114:                                              ; preds = %113, %111
  %115 = load i32, ptr %13, align 4, !tbaa !15
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %13, align 4, !tbaa !15
  br label %78, !llvm.loop !23

117:                                              ; preds = %84
  store i32 0, ptr %11, align 4
  br label %118

118:                                              ; preds = %117, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %119 = load i32, ptr %11, align 4
  switch i32 %119, label %124 [
    i32 0, label %120
  ]

120:                                              ; preds = %118
  br label %121

121:                                              ; preds = %120
  %122 = load i32, ptr %10, align 4, !tbaa !15
  %123 = add nsw i32 %122, 1
  store i32 %123, ptr %10, align 4, !tbaa !15
  br label %36, !llvm.loop !25

124:                                              ; preds = %118, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %125 = load i32, ptr %11, align 4
  switch i32 %125, label %129 [
    i32 4, label %126
    i32 1, label %127
  ]

126:                                              ; preds = %124
  store ptr null, ptr %5, align 8
  br label %127

127:                                              ; preds = %126, %124
  %128 = load ptr, ptr %5, align 8
  ret ptr %128

129:                                              ; preds = %124, %111
  unreachable
}

declare ptr @ArrayCreate(i32 noundef, i32 noundef, ptr noundef) #2

declare ptr @m_ArrayPushBack(ptr noundef, 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 = { "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 = !{!"HandleGraphTraversal", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"MArray", !11, i64 0, !14, i64 4, !7, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !6, i64 16}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !6, i64 8}
!19 = !{!20, !11, i64 32}
!20 = !{!"GraphNode", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 40}
!21 = !{!20, !11, i64 24}
!22 = !{!20, !6, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !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
define dso_local noundef ptr @GraphBFTraversal(ptr nocapture noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %9

7:                                                ; preds = %4
  %8 = tail call ptr @ArrayCreate(i32 noundef 0, i32 noundef 4, ptr noundef null) #2
  store ptr %8, ptr %0, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %4, %7
  %10 = phi ptr [ %5, %4 ], [ %8, %7 ]
  store i32 0, ptr %10, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %1, i64 32
  %12 = tail call ptr @m_ArrayPushBack(ptr noundef nonnull %10, ptr noundef nonnull %11) #2
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load ptr, ptr %0, align 8, !tbaa !5
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %.not3436 = icmp sgt i32 %15, 0
  br i1 %.not3436, label %.lr.ph39, label %.thread

.lr.ph39:                                         ; preds = %9
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  br label %17

17:                                               ; preds = %.lr.ph39, %._crit_edge
  %indvars.iv43 = phi i64 [ 0, %.lr.ph39 ], [ %indvars.iv.next44, %._crit_edge ]
  %18 = phi ptr [ %14, %.lr.ph39 ], [ %56, %._crit_edge ]
  %19 = load ptr, ptr %13, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %18, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv43
  %23 = load i32, ptr %22, align 4, !tbaa !16
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %19, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = load ptr, ptr %16, align 8, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %26, i64 32
  %29 = load i32, ptr %28, align 8, !tbaa !19
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %27, i64 %30
  store i32 1, ptr %31, align 4, !tbaa !16
  %32 = tail call i32 %2(ptr noundef %26, ptr noundef %3) #2
  %.not = icmp eq i32 %32, 0
  br i1 %.not, label %.preheader, label %.thread

.preheader:                                       ; preds = %17
  %33 = getelementptr inbounds i8, ptr %26, i64 24
  %34 = load i32, ptr %33, align 8, !tbaa !21
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %36 = getelementptr inbounds i8, ptr %26, i64 8
  br label %37

37:                                               ; preds = %.lr.ph, %52
  %38 = phi i32 [ %34, %.lr.ph ], [ %53, %52 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %52 ]
  %39 = load ptr, ptr %36, align 8, !tbaa !22
  %40 = getelementptr inbounds ptr, ptr %39, i64 %indvars.iv
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  %42 = load ptr, ptr %16, align 8, !tbaa !18
  %43 = getelementptr inbounds i8, ptr %41, i64 32
  %44 = load i32, ptr %43, align 8, !tbaa !19
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %42, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !16
  %48 = icmp eq i32 %47, 1
  br i1 %48, label %52, label %49

49:                                               ; preds = %37
  %50 = load ptr, ptr %0, align 8, !tbaa !5
  %51 = tail call ptr @m_ArrayPushBack(ptr noundef %50, ptr noundef nonnull %43) #2
  %.pre = load i32, ptr %33, align 8, !tbaa !21
  br label %52

52:                                               ; preds = %37, %49
  %53 = phi i32 [ %38, %37 ], [ %.pre, %49 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %54 = sext i32 %53 to i64
  %55 = icmp slt i64 %indvars.iv.next, %54
  br i1 %55, label %37, label %._crit_edge, !llvm.loop !23

._crit_edge:                                      ; preds = %52, %.preheader
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %56 = load ptr, ptr %0, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 8, !tbaa !11
  %58 = sext i32 %57 to i64
  %.not34 = icmp slt i64 %indvars.iv.next44, %58
  br i1 %.not34, label %17, label %.thread, !llvm.loop !25

.thread:                                          ; preds = %._crit_edge, %17, %9
  %spec.select = phi ptr [ null, %9 ], [ %26, %17 ], [ null, %._crit_edge ]
  ret ptr %spec.select
}

declare ptr @ArrayCreate(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare ptr @m_ArrayPushBack(ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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 = !{!"HandleGraphTraversal", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"MArray", !10, i64 0, !13, i64 4, !8, i64 8}
!13 = !{!"short", !8, i64 0}
!14 = !{!6, !7, i64 16}
!15 = !{!8, !8, i64 0}
!16 = !{!10, !10, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!6, !7, i64 8}
!19 = !{!20, !10, i64 32}
!20 = !{!"GraphNode", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !7, i64 40}
!21 = !{!20, !10, i64 24}
!22 = !{!20, !7, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass