; LLVM IR from dpt/Containers :: libraries/datastruct/dstree/breadthwalk-internal.ll_dstree (breadthwalk_internal)

; 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.nodedepth = type { ptr, i32 }
%struct.dstree = type { ptr, i32, ptr, ptr, ptr }
%struct.dstree__node = type { [2 x ptr], %struct.item }
%struct.item = type { ptr, i64, ptr }

@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [99 x i8], align 1
@__PRETTY_FUNCTION__.dstree__breadthwalk_internal = external hidden unnamed_addr constant [89 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @dstree__breadthwalk_internal(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.nodedepth, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.nodedepth, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %117

16:                                               ; preds = %3
  %17 = call ptr @queue_create(i32 noundef 100, i64 noundef 16)
  store ptr %17, ptr %9, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %16
  store i64 1, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %117

21:                                               ; preds = %16
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.dstree, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  br label %28

27:                                               ; preds = %21
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 39, ptr noundef @__PRETTY_FUNCTION__.dstree__breadthwalk_internal) #5
  unreachable

28:                                               ; preds = %26
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.dstree, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.nodedepth, ptr %10, i32 0, i32 0
  store ptr %31, ptr %32, align 8, !tbaa !12
  %33 = getelementptr inbounds %struct.nodedepth, ptr %10, i32 0, i32 1
  store i32 0, ptr %33, align 8, !tbaa !14
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = call i64 @queue_enqueue(ptr noundef %34, ptr noundef %10)
  store i64 %35, ptr %8, align 8, !tbaa !15
  %36 = load i64, ptr %8, align 8, !tbaa !15
  %37 = icmp ne i64 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %28
  %39 = load i64, ptr %8, align 8, !tbaa !15
  store i64 %39, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %117

40:                                               ; preds = %28
  br label %41

41:                                               ; preds = %114, %40
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = call i32 @queue_empty(ptr noundef %42)
  %44 = icmp ne i32 %43, 0
  %45 = xor i1 %44, true
  br i1 %45, label %46, label %115

46:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = call i64 @queue_dequeue(ptr noundef %47, ptr noundef %10)
  store i64 %48, ptr %8, align 8, !tbaa !15
  %49 = load i64, ptr %8, align 8, !tbaa !15
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %51, label %53

51:                                               ; preds = %46
  %52 = load i64, ptr %8, align 8, !tbaa !15
  store i64 %52, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %112

53:                                               ; preds = %46
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.nodedepth, ptr %10, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !12
  %57 = getelementptr inbounds %struct.nodedepth, ptr %10, i32 0, i32 1
  %58 = load i32, ptr %57, align 8, !tbaa !14
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = call i64 %54(ptr noundef %56, i32 noundef %58, ptr noundef %59)
  store i64 %60, ptr %8, align 8, !tbaa !15
  %61 = load i64, ptr %8, align 8, !tbaa !15
  %62 = icmp ne i64 %61, 0
  br i1 %62, label %63, label %65

63:                                               ; preds = %53
  %64 = load i64, ptr %8, align 8, !tbaa !15
  store i64 %64, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %112

65:                                               ; preds = %53
  %66 = getelementptr inbounds %struct.nodedepth, ptr %10, i32 0, i32 1
  %67 = load i32, ptr %66, align 8, !tbaa !14
  %68 = add nsw i32 %67, 1
  %69 = getelementptr inbounds %struct.nodedepth, ptr %12, i32 0, i32 1
  store i32 %68, ptr %69, align 8, !tbaa !14
  %70 = getelementptr inbounds %struct.nodedepth, ptr %10, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !12
  %72 = getelementptr inbounds %struct.dstree__node, ptr %71, i32 0, i32 0
  %73 = getelementptr inbounds [2 x ptr], ptr %72, i64 0, i64 0
  %74 = load ptr, ptr %73, align 8, !tbaa !5
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %90

76:                                               ; preds = %65
  %77 = getelementptr inbounds %struct.nodedepth, ptr %10, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !12
  %79 = getelementptr inbounds %struct.dstree__node, ptr %78, i32 0, i32 0
  %80 = getelementptr inbounds [2 x ptr], ptr %79, i64 0, i64 0
  %81 = load ptr, ptr %80, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.nodedepth, ptr %12, i32 0, i32 0
  store ptr %81, ptr %82, align 8, !tbaa !12
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = call i64 @queue_enqueue(ptr noundef %83, ptr noundef %12)
  store i64 %84, ptr %8, align 8, !tbaa !15
  %85 = load i64, ptr %8, align 8, !tbaa !15
  %86 = icmp ne i64 %85, 0
  br i1 %86, label %87, label %89

87:                                               ; preds = %76
  %88 = load i64, ptr %8, align 8, !tbaa !15
  store i64 %88, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %112

89:                                               ; preds = %76
  br label %90

90:                                               ; preds = %89, %65
  %91 = getelementptr inbounds %struct.nodedepth, ptr %10, i32 0, i32 0
  %92 = load ptr, ptr %91, align 8, !tbaa !12
  %93 = getelementptr inbounds %struct.dstree__node, ptr %92, i32 0, i32 0
  %94 = getelementptr inbounds [2 x ptr], ptr %93, i64 0, i64 1
  %95 = load ptr, ptr %94, align 8, !tbaa !5
  %96 = icmp ne ptr %95, null
  br i1 %96, label %97, label %111

97:                                               ; preds = %90
  %98 = getelementptr inbounds %struct.nodedepth, ptr %10, i32 0, i32 0
  %99 = load ptr, ptr %98, align 8, !tbaa !12
  %100 = getelementptr inbounds %struct.dstree__node, ptr %99, i32 0, i32 0
  %101 = getelementptr inbounds [2 x ptr], ptr %100, i64 0, i64 1
  %102 = load ptr, ptr %101, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.nodedepth, ptr %12, i32 0, i32 0
  store ptr %102, ptr %103, align 8, !tbaa !12
  %104 = load ptr, ptr %9, align 8, !tbaa !5
  %105 = call i64 @queue_enqueue(ptr noundef %104, ptr noundef %12)
  store i64 %105, ptr %8, align 8, !tbaa !15
  %106 = load i64, ptr %8, align 8, !tbaa !15
  %107 = icmp ne i64 %106, 0
  br i1 %107, label %108, label %110

108:                                              ; preds = %97
  %109 = load i64, ptr %8, align 8, !tbaa !15
  store i64 %109, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %112

110:                                              ; preds = %97
  br label %111

111:                                              ; preds = %110, %90
  store i32 0, ptr %11, align 4
  br label %112

112:                                              ; preds = %111, %108, %87, %63, %51
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  %113 = load i32, ptr %11, align 4
  switch i32 %113, label %117 [
    i32 0, label %114
  ]

114:                                              ; preds = %112
  br label %41, !llvm.loop !17

115:                                              ; preds = %41
  %116 = load ptr, ptr %9, align 8, !tbaa !5
  call void @queue_destroy(ptr noundef %116)
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %117

117:                                              ; preds = %115, %112, %38, %20, %15
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %118 = load i64, ptr %4, align 8
  ret i64 %118
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare ptr @queue_create(i32 noundef, i64 noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

declare i64 @queue_enqueue(ptr noundef, ptr noundef) #2

declare i32 @queue_empty(ptr noundef) #2

declare i64 @queue_dequeue(ptr noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare void @queue_destroy(ptr noundef) #2

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 nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"dstree", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"nodedepth", !6, i64 0, !11, i64 8}
!14 = !{!13, !11, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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

%struct.nodedepth = type { ptr, i32 }

@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [99 x i8], align 1
@__PRETTY_FUNCTION__.dstree__breadthwalk_internal = external hidden unnamed_addr constant [89 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @dstree__breadthwalk_internal(ptr noundef readonly %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.nodedepth, align 8
  %5 = alloca %struct.nodedepth, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  %6 = icmp eq ptr %0, null
  br i1 %6, label %39, label %7

7:                                                ; preds = %3
  %8 = tail call ptr @queue_create(i32 noundef 100, i64 noundef 16) #4
  %9 = icmp eq ptr %8, null
  br i1 %9, label %39, label %10

10:                                               ; preds = %7
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %12, label %13

12:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 39, ptr noundef nonnull @__PRETTY_FUNCTION__.dstree__breadthwalk_internal) #5
  unreachable

13:                                               ; preds = %10
  store ptr %11, ptr %4, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 0, ptr %14, align 8, !tbaa !13
  %15 = call i64 @queue_enqueue(ptr noundef nonnull %8, ptr noundef nonnull %4) #4
  %.not34 = icmp eq i64 %15, 0
  br i1 %.not34, label %.preheader, label %39

.preheader:                                       ; preds = %13
  %16 = call i32 @queue_empty(ptr noundef nonnull %8) #4
  %.not3544 = icmp eq i32 %16, 0
  br i1 %.not3544, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %17 = getelementptr inbounds i8, ptr %5, i64 8
  br label %18

18:                                               ; preds = %.lr.ph, %37
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %19 = call i64 @queue_dequeue(ptr noundef nonnull %8, ptr noundef nonnull %4) #4
  %.not36 = icmp eq i64 %19, 0
  br i1 %.not36, label %20, label %.thread

20:                                               ; preds = %18
  %21 = load ptr, ptr %4, align 8, !tbaa !11
  %22 = load i32, ptr %14, align 8, !tbaa !13
  %23 = call i64 %1(ptr noundef %21, i32 noundef %22, ptr noundef %2) #4
  %.not37 = icmp eq i64 %23, 0
  br i1 %.not37, label %24, label %.thread

24:                                               ; preds = %20
  %25 = load i32, ptr %14, align 8, !tbaa !13
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %17, align 8, !tbaa !13
  %27 = load ptr, ptr %4, align 8, !tbaa !11
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %.not38 = icmp eq ptr %28, null
  br i1 %.not38, label %31, label %29

29:                                               ; preds = %24
  store ptr %28, ptr %5, align 8, !tbaa !11
  %30 = call i64 @queue_enqueue(ptr noundef nonnull %8, ptr noundef nonnull %5) #4
  %.not39 = icmp eq i64 %30, 0
  br i1 %.not39, label %._crit_edge45, label %.thread

._crit_edge45:                                    ; preds = %29
  %.pre = load ptr, ptr %4, align 8, !tbaa !11
  br label %31

31:                                               ; preds = %._crit_edge45, %24
  %32 = phi ptr [ %.pre, %._crit_edge45 ], [ %27, %24 ]
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %.not40 = icmp eq ptr %34, null
  br i1 %.not40, label %37, label %35

35:                                               ; preds = %31
  store ptr %34, ptr %5, align 8, !tbaa !11
  %36 = call i64 @queue_enqueue(ptr noundef nonnull %8, ptr noundef nonnull %5) #4
  %.not41 = icmp eq i64 %36, 0
  br i1 %.not41, label %37, label %.thread

.thread:                                          ; preds = %18, %20, %29, %35
  %.1.ph = phi i64 [ %36, %35 ], [ %30, %29 ], [ %23, %20 ], [ %19, %18 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  br label %39

37:                                               ; preds = %31, %35
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  %38 = call i32 @queue_empty(ptr noundef nonnull %8) #4
  %.not35 = icmp eq i32 %38, 0
  br i1 %.not35, label %18, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %37, %.preheader
  call void @queue_destroy(ptr noundef nonnull %8) #4
  br label %39

39:                                               ; preds = %.thread, %13, %7, %3, %._crit_edge
  %.2 = phi i64 [ 0, %._crit_edge ], [ 0, %3 ], [ 1, %7 ], [ %15, %13 ], [ %.1.ph, %.thread ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  ret i64 %.2
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare ptr @queue_create(i32 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare i64 @queue_enqueue(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @queue_empty(ptr noundef) local_unnamed_addr #2

declare i64 @queue_dequeue(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare void @queue_destroy(ptr noundef) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !7, i64 0}
!6 = !{!"dstree", !7, i64 0, !10, i64 8, !7, 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 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"nodedepth", !7, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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