; LLVM IR from rodrigo-lc/simulation-program-using-graphs :: include/graph (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.graphs = type { i32, ptr }

@.str.11 = external hidden unnamed_addr constant [28 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

declare void @perror(ptr noundef) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

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

declare ptr @getHead(ptr noundef) #1

declare ptr @getData(ptr noundef) #1

declare ptr @getNext(ptr noundef) #1

declare ptr @vertexGetEdges(ptr noundef) #1

declare ptr @edgeGetAdjacent(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @bfs(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %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 ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  call void @perror(ptr noundef @.str.11)
  call void @exit(i32 noundef 1) #4
  unreachable

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %16 = call ptr @createQueue()
  store ptr %16, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.graphs, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = call ptr @getHead(ptr noundef %19)
  store ptr %20, ptr %7, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %24, %15
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %24, label %31

24:                                               ; preds = %21
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = call ptr @getData(ptr noundef %25)
  store ptr %26, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  call void @vertexSetGroup(ptr noundef %27, i32 noundef 2147483647)
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  call void @vertexSetDad(ptr noundef %28, ptr noundef null)
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = call ptr @getNext(ptr noundef %29)
  store ptr %30, ptr %7, align 8, !tbaa !5
  br label %21, !llvm.loop !12

31:                                               ; preds = %21
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.graphs, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = call ptr @getHead(ptr noundef %34)
  store ptr %35, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %36, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  call void @vertexSetGroup(ptr noundef %37, i32 noundef 0)
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  call void @enqueue(ptr noundef %38, ptr noundef %39)
  br label %40

40:                                               ; preds = %75, %31
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call i32 @isQueueEmpty(ptr noundef %41)
  %43 = icmp ne i32 %42, 0
  %44 = xor i1 %43, true
  br i1 %44, label %45, label %76

45:                                               ; preds = %40
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = call ptr @dequeue(ptr noundef %46)
  store ptr %47, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = call ptr @vertexGetEdges(ptr noundef %48)
  store ptr %49, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = call ptr @getHead(ptr noundef %50)
  store ptr %51, ptr %9, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %72, %45
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %75

55:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = call ptr @getData(ptr noundef %56)
  %58 = call ptr @edgeGetAdjacent(ptr noundef %57)
  store ptr %58, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = call i32 @vertexGetGroup(ptr noundef %59)
  store i32 %60, ptr %11, align 4, !tbaa !14
  %61 = load i32, ptr %11, align 4, !tbaa !14
  %62 = icmp eq i32 %61, 2147483647
  br i1 %62, label %63, label %72

63:                                               ; preds = %55
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = call i32 @vertexGetGroup(ptr noundef %65)
  %67 = add nsw i32 %66, 1
  call void @vertexSetGroup(ptr noundef %64, i32 noundef %67)
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  call void @vertexSetDad(ptr noundef %68, ptr noundef %69)
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  call void @enqueue(ptr noundef %70, ptr noundef %71)
  br label %72

72:                                               ; preds = %63, %55
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = call ptr @getNext(ptr noundef %73)
  store ptr %74, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %52, !llvm.loop !15

75:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %40, !llvm.loop !16

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

declare ptr @createQueue() #1

declare void @vertexSetGroup(ptr noundef, i32 noundef) #1

declare void @vertexSetDad(ptr noundef, ptr noundef) #1

declare void @enqueue(ptr noundef, ptr noundef) #1

declare i32 @isQueueEmpty(ptr noundef) #1

declare ptr @dequeue(ptr noundef) #1

declare i32 @vertexGetGroup(ptr noundef) #1

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


; 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.11 = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

declare ptr @getHead(ptr noundef) local_unnamed_addr #2

declare ptr @getData(ptr noundef) local_unnamed_addr #2

declare ptr @getNext(ptr noundef) local_unnamed_addr #2

declare ptr @vertexGetEdges(ptr noundef) local_unnamed_addr #2

declare ptr @edgeGetAdjacent(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @bfs(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %4, label %5

4:                                                ; preds = %2
  tail call void @perror(ptr noundef nonnull @.str.11) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

5:                                                ; preds = %2
  %6 = tail call ptr @createQueue() #6
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = tail call ptr @getHead(ptr noundef %8) #6
  %.not30 = icmp eq ptr %9, null
  br i1 %.not30, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.031 = phi ptr [ %11, %.lr.ph ], [ %9, %5 ]
  %10 = tail call ptr @getData(ptr noundef nonnull %.031) #6
  tail call void @vertexSetGroup(ptr noundef %10, i32 noundef 2147483647) #6
  tail call void @vertexSetDad(ptr noundef %10, ptr noundef null) #6
  %11 = tail call ptr @getNext(ptr noundef nonnull %.031) #6
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %5
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = tail call ptr @getHead(ptr noundef %12) #6
  tail call void @vertexSetGroup(ptr noundef %1, i32 noundef 0) #6
  tail call void @enqueue(ptr noundef %1, ptr noundef %6) #6
  %14 = tail call i32 @isQueueEmpty(ptr noundef %6) #6
  %.not2836 = icmp eq i32 %14, 0
  br i1 %.not2836, label %.lr.ph38, label %._crit_edge39

.loopexit:                                        ; preds = %26, %.lr.ph38
  %15 = tail call i32 @isQueueEmpty(ptr noundef %6) #6
  %.not28 = icmp eq i32 %15, 0
  br i1 %.not28, label %.lr.ph38, label %._crit_edge39, !llvm.loop !13

.lr.ph38:                                         ; preds = %._crit_edge, %.loopexit
  %16 = tail call ptr @dequeue(ptr noundef %6) #6
  %17 = tail call ptr @vertexGetEdges(ptr noundef %16) #6
  %18 = tail call ptr @getHead(ptr noundef %17) #6
  %.not2932 = icmp eq ptr %18, null
  br i1 %.not2932, label %.loopexit, label %.lr.ph35

.lr.ph35:                                         ; preds = %.lr.ph38, %26
  %.02633 = phi ptr [ %27, %26 ], [ %18, %.lr.ph38 ]
  %19 = tail call ptr @getData(ptr noundef nonnull %.02633) #6
  %20 = tail call ptr @edgeGetAdjacent(ptr noundef %19) #6
  %21 = tail call i32 @vertexGetGroup(ptr noundef %20) #6
  %22 = icmp eq i32 %21, 2147483647
  br i1 %22, label %23, label %26

23:                                               ; preds = %.lr.ph35
  %24 = tail call i32 @vertexGetGroup(ptr noundef %16) #6
  %25 = add nsw i32 %24, 1
  tail call void @vertexSetGroup(ptr noundef %20, i32 noundef %25) #6
  tail call void @vertexSetDad(ptr noundef %20, ptr noundef %16) #6
  tail call void @enqueue(ptr noundef %20, ptr noundef %6) #6
  br label %26

26:                                               ; preds = %23, %.lr.ph35
  %27 = tail call ptr @getNext(ptr noundef nonnull %.02633) #6
  %.not29 = icmp eq ptr %27, null
  br i1 %.not29, label %.loopexit, label %.lr.ph35, !llvm.loop !14

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

declare ptr @createQueue() local_unnamed_addr #2

declare void @vertexSetGroup(ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @vertexSetDad(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @enqueue(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @isQueueEmpty(ptr noundef) local_unnamed_addr #2

declare ptr @dequeue(ptr noundef) local_unnamed_addr #2

declare i32 @vertexGetGroup(ptr noundef) local_unnamed_addr #2

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 = { 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 #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 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 #4 = { cold }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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, !10, i64 8}
!6 = !{!"graphs", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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