; LLVM IR from bartobri/data-structures-c :: graph/breadth-first-queue-list-traversal (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.node = type { i32, ptr }

@adj = external hidden global ptr, align 8
@visited = external hidden global ptr, align 8

; 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 void @traverse(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @QUEUEinit()
  %6 = load i32, ptr %3, align 4, !tbaa !5
  call void @QUEUEput(i32 noundef %6)
  br label %7

7:                                                ; preds = %53, %2
  %8 = call i32 @QUEUEempty()
  %9 = icmp ne i32 %8, 0
  %10 = xor i1 %9, true
  br i1 %10, label %11, label %54

11:                                               ; preds = %7
  %12 = call i32 @QUEUEget()
  store i32 %12, ptr %3, align 4, !tbaa !5
  %13 = load ptr, ptr @visited, align 8, !tbaa !9
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i32, ptr %13, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %53

19:                                               ; preds = %11
  %20 = load ptr, ptr %4, align 8, !tbaa !9
  %21 = load i32, ptr %3, align 4, !tbaa !5
  call void %20(i32 noundef %21)
  %22 = load ptr, ptr @visited, align 8, !tbaa !9
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i32, ptr %22, i64 %24
  store i32 1, ptr %25, align 4, !tbaa !5
  %26 = load ptr, ptr @adj, align 8, !tbaa !9
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds ptr, ptr %26, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  store ptr %30, ptr %5, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %48, %19
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %52

34:                                               ; preds = %31
  %35 = load ptr, ptr @visited, align 8, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.node, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr %35, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %47

43:                                               ; preds = %34
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.node, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !11
  call void @QUEUEput(i32 noundef %46)
  br label %47

47:                                               ; preds = %43, %34
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %5, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.node, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !13
  store ptr %51, ptr %5, align 8, !tbaa !9
  br label %31, !llvm.loop !14

52:                                               ; preds = %31
  br label %53

53:                                               ; preds = %52, %11
  br label %7, !llvm.loop !16

54:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare void @QUEUEinit() #2

declare void @QUEUEput(i32 noundef) #2

declare i32 @QUEUEempty() #2

declare i32 @QUEUEget() #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"node", !6, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@adj = external hidden local_unnamed_addr global ptr, align 8
@visited = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @traverse(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  tail call void @QUEUEinit() #2
  tail call void @QUEUEput(i32 noundef %0) #2
  %3 = tail call i32 @QUEUEempty() #2
  %.not13 = icmp eq i32 %3, 0
  br i1 %.not13, label %.lr.ph14, label %._crit_edge

.lr.ph14:                                         ; preds = %2, %.loopexit
  %4 = tail call i32 @QUEUEget() #2
  %5 = load ptr, ptr @visited, align 8, !tbaa !5
  %6 = sext i32 %4 to i64
  %7 = getelementptr inbounds i32, ptr %5, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %.loopexit

10:                                               ; preds = %.lr.ph14
  tail call void %1(i32 noundef %4) #2
  %11 = load ptr, ptr @visited, align 8, !tbaa !5
  %12 = getelementptr inbounds i32, ptr %11, i64 %6
  store i32 1, ptr %12, align 4, !tbaa !9
  %13 = load ptr, ptr @adj, align 8, !tbaa !5
  %14 = getelementptr inbounds ptr, ptr %13, i64 %6
  %.010 = load ptr, ptr %14, align 8, !tbaa !5
  %.not911 = icmp eq ptr %.010, null
  br i1 %.not911, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %10, %22
  %15 = phi ptr [ %23, %22 ], [ %11, %10 ]
  %.012 = phi ptr [ %.0, %22 ], [ %.010, %10 ]
  %16 = load i32, ptr %.012, align 8, !tbaa !11
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr %15, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %.lr.ph
  tail call void @QUEUEput(i32 noundef %16) #2
  %.pre = load ptr, ptr @visited, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %.lr.ph, %21
  %23 = phi ptr [ %15, %.lr.ph ], [ %.pre, %21 ]
  %24 = getelementptr inbounds i8, ptr %.012, i64 8
  %.0 = load ptr, ptr %24, align 8, !tbaa !5
  %.not9 = icmp eq ptr %.0, null
  br i1 %.not9, label %.loopexit, label %.lr.ph, !llvm.loop !13

.loopexit:                                        ; preds = %22, %10, %.lr.ph14
  %25 = tail call i32 @QUEUEempty() #2
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %.lr.ph14, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.loopexit, %2
  ret void
}

declare void @QUEUEinit() local_unnamed_addr #1

declare void @QUEUEput(i32 noundef) local_unnamed_addr #1

declare i32 @QUEUEempty() local_unnamed_addr #1

declare i32 @QUEUEget() 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, !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 = !{!"node", !10, i64 0, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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