; LLVM IR from wuzhouhui/leetcode :: 102_bin_tree_lev_order_tra (levelOrder)

; 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.TreeNode = type { i32, ptr, ptr }

@q2tail = external hidden global ptr, align 8
@q2head = external hidden global ptr, align 8
@q1tail = external hidden global ptr, align 8
@q1head = external hidden global ptr, align 8
@ret = external hidden global ptr, align 8
@colsize = external hidden global ptr, align 8
@maxcollen = external hidden global i32, align 4
@maxretlen = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local ptr @levelOrder(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, 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
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %16, label %13

13:                                               ; preds = %3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr null, ptr %14, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %15, align 4, !tbaa !9
  store ptr null, ptr %4, align 8
  br label %54

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  br label %17

17:                                               ; preds = %16
  store ptr null, ptr @q2tail, align 8, !tbaa !5
  store ptr null, ptr @q2head, align 8, !tbaa !5
  store ptr null, ptr @q1tail, align 8, !tbaa !5
  store ptr null, ptr @q1head, align 8, !tbaa !5
  store ptr null, ptr @ret, align 8, !tbaa !5
  store ptr null, ptr @colsize, align 8, !tbaa !5
  store i32 0, ptr @maxcollen, align 4, !tbaa !9
  store i32 0, ptr @maxretlen, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  call void @enq1(ptr noundef %20)
  store i32 -1, ptr %8, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %44, %19
  %22 = load ptr, ptr @q1head, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %47

24:                                               ; preds = %21
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %30, %24
  %28 = load ptr, ptr @q1head, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %44

30:                                               ; preds = %27
  %31 = call ptr @deq1()
  store ptr %31, ptr %10, align 8, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %9, align 4, !tbaa !9
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TreeNode, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !11
  call void @setval(i32 noundef %32, i32 noundef %33, i32 noundef %37)
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.TreeNode, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  call void @enq2(ptr noundef %40)
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TreeNode, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  call void @enq2(ptr noundef %43)
  br label %27, !llvm.loop !15

44:                                               ; preds = %27
  %45 = load ptr, ptr @q2head, align 8, !tbaa !5
  store ptr %45, ptr @q1head, align 8, !tbaa !5
  %46 = load ptr, ptr @q2tail, align 8, !tbaa !5
  store ptr %46, ptr @q1tail, align 8, !tbaa !5
  store ptr null, ptr @q2tail, align 8, !tbaa !5
  store ptr null, ptr @q2head, align 8, !tbaa !5
  br label %21, !llvm.loop !17

47:                                               ; preds = %21
  %48 = load ptr, ptr @colsize, align 8, !tbaa !5
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %48, ptr %49, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %51, ptr %52, align 4, !tbaa !9
  %53 = load ptr, ptr @ret, align 8, !tbaa !5
  store ptr %53, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %54

54:                                               ; preds = %47, %13
  %55 = load ptr, ptr %4, align 8
  ret ptr %55
}

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

; Function Attrs: nounwind uwtable
declare hidden void @enq1(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @setval(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden void @enq2(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare hidden ptr @deq1() #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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"TreeNode", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !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"

@q2tail = external hidden local_unnamed_addr global ptr, align 8
@q2head = external hidden local_unnamed_addr global ptr, align 8
@q1tail = external hidden local_unnamed_addr global ptr, align 8
@q1head = external hidden local_unnamed_addr global ptr, align 8
@ret = external hidden local_unnamed_addr global ptr, align 8
@colsize = external hidden local_unnamed_addr global ptr, align 8
@maxcollen = external hidden local_unnamed_addr global i32, align 4
@maxretlen = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local ptr @levelOrder(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %5

4:                                                ; preds = %3
  store ptr null, ptr %1, align 8, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %20

5:                                                ; preds = %3
  store ptr null, ptr @q2tail, align 8, !tbaa !5
  store ptr null, ptr @q2head, align 8, !tbaa !5
  store ptr null, ptr @q1tail, align 8, !tbaa !5
  store ptr null, ptr @q1head, align 8, !tbaa !5
  store ptr null, ptr @ret, align 8, !tbaa !5
  store ptr null, ptr @colsize, align 8, !tbaa !5
  store i32 0, ptr @maxcollen, align 4, !tbaa !9
  store i32 0, ptr @maxretlen, align 4, !tbaa !9
  tail call void @enq1(ptr noundef nonnull %0)
  %.pr = load ptr, ptr @q1head, align 8, !tbaa !5
  %.not1620 = icmp eq ptr %.pr, null
  br i1 %.not1620, label %._crit_edge24, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5, %._crit_edge
  %.01421 = phi i32 [ %6, %._crit_edge ], [ -1, %5 ]
  %6 = add nsw i32 %.01421, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.01319 = phi i32 [ %8, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %7 = tail call ptr @deq1()
  %8 = add nuw nsw i32 %.01319, 1
  %9 = load i32, ptr %7, align 8, !tbaa !11
  tail call void @setval(i32 noundef %6, i32 noundef %.01319, i32 noundef %9)
  %10 = getelementptr inbounds i8, ptr %7, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  tail call void @enq2(ptr noundef %11)
  %12 = getelementptr inbounds i8, ptr %7, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  tail call void @enq2(ptr noundef %13)
  %14 = load ptr, ptr @q1head, align 8, !tbaa !5
  %.not17 = icmp eq ptr %14, null
  br i1 %.not17, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph
  %15 = load ptr, ptr @q2head, align 8, !tbaa !5
  store ptr %15, ptr @q1head, align 8, !tbaa !5
  %16 = load ptr, ptr @q2tail, align 8, !tbaa !5
  store ptr %16, ptr @q1tail, align 8, !tbaa !5
  store ptr null, ptr @q2tail, align 8, !tbaa !5
  store ptr null, ptr @q2head, align 8, !tbaa !5
  %.not16 = icmp eq ptr %15, null
  br i1 %.not16, label %._crit_edge24.loopexit, label %.lr.ph.preheader, !llvm.loop !17

._crit_edge24.loopexit:                           ; preds = %._crit_edge
  %17 = add nsw i32 %.01421, 2
  br label %._crit_edge24

._crit_edge24:                                    ; preds = %._crit_edge24.loopexit, %5
  %.014.lcssa = phi i32 [ 0, %5 ], [ %17, %._crit_edge24.loopexit ]
  %18 = load ptr, ptr @colsize, align 8, !tbaa !5
  store ptr %18, ptr %1, align 8, !tbaa !5
  store i32 %.014.lcssa, ptr %2, align 4, !tbaa !9
  %19 = load ptr, ptr @ret, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %._crit_edge24, %4
  %.0 = phi ptr [ %19, %._crit_edge24 ], [ null, %4 ]
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @enq1(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @setval(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden void @enq2(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden ptr @deq1() local_unnamed_addr #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"TreeNode", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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