; 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.12 = 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

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

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

declare i32 @vertexGetGroup(ptr noundef) #1

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

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

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %15 = call ptr @createStack()
  store ptr %15, 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
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.graphs, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = call ptr @getHead(ptr noundef %18)
  store ptr %19, ptr %7, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %23, %14
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %30

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

30:                                               ; preds = %20
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %31, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  call void @push(ptr noundef %32, ptr noundef %33)
  br label %34

34:                                               ; preds = %65, %30
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = call i32 @isStackEmpty(ptr noundef %35)
  %37 = icmp ne i32 %36, 0
  %38 = xor i1 %37, true
  br i1 %38, label %39, label %66

39:                                               ; preds = %34
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call ptr @pop(ptr noundef %40)
  store ptr %41, ptr %6, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call i32 @vertexGetGroup(ptr noundef %42)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %65, label %45

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

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

54:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = call ptr @getData(ptr noundef %55)
  %57 = call ptr @edgeGetAdjacent(ptr noundef %56)
  store ptr %57, ptr %10, align 8, !tbaa !5
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  call void @push(ptr noundef %58, ptr noundef %59)
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  call void @vertexSetDad(ptr noundef %60, ptr noundef %61)
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = call ptr @getNext(ptr noundef %62)
  store ptr %63, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %51, !llvm.loop !14

64:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %65

65:                                               ; preds = %64, %39
  br label %34, !llvm.loop !15

66:                                               ; preds = %34
  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 @createStack() #1

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

declare i32 @isStackEmpty(ptr noundef) #1

declare ptr @pop(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 = distinct !{!14, !13}
!15 = distinct !{!15, !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.12 = 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

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

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

declare i32 @vertexGetGroup(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @dfs(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.12) #4
  tail call void @exit(i32 noundef 1) #5
  unreachable

5:                                                ; preds = %2
  %6 = tail call ptr @createStack() #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
  %.not28 = icmp eq ptr %9, null
  br i1 %.not28, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.02329 = phi ptr [ %11, %.lr.ph ], [ %9, %5 ]
  %10 = tail call ptr @getData(ptr noundef nonnull %.02329) #6
  tail call void @vertexSetGroup(ptr noundef %10, i32 noundef 0) #6
  tail call void @vertexSetDad(ptr noundef %10, ptr noundef null) #6
  %11 = tail call ptr @getNext(ptr noundef nonnull %.02329) #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
  tail call void @push(ptr noundef %1, ptr noundef %6) #6
  %12 = tail call i32 @isStackEmpty(ptr noundef %6) #6
  %.not2534 = icmp eq i32 %12, 0
  br i1 %.not2534, label %.lr.ph36, label %._crit_edge37

.lr.ph36:                                         ; preds = %._crit_edge, %.loopexit
  %13 = tail call ptr @pop(ptr noundef %6) #6
  %14 = tail call i32 @vertexGetGroup(ptr noundef %13) #6
  %.not26 = icmp eq i32 %14, 0
  br i1 %.not26, label %15, label %.loopexit

15:                                               ; preds = %.lr.ph36
  tail call void @vertexSetGroup(ptr noundef %13, i32 noundef 1) #6
  %16 = tail call ptr @vertexGetEdges(ptr noundef %13) #6
  %17 = tail call ptr @getHead(ptr noundef %16) #6
  %.not2730 = icmp eq ptr %17, null
  br i1 %.not2730, label %.loopexit, label %.lr.ph33

.lr.ph33:                                         ; preds = %15, %.lr.ph33
  %.031 = phi ptr [ %20, %.lr.ph33 ], [ %17, %15 ]
  %18 = tail call ptr @getData(ptr noundef nonnull %.031) #6
  %19 = tail call ptr @edgeGetAdjacent(ptr noundef %18) #6
  tail call void @push(ptr noundef %19, ptr noundef %6) #6
  tail call void @vertexSetDad(ptr noundef %19, ptr noundef %13) #6
  %20 = tail call ptr @getNext(ptr noundef nonnull %.031) #6
  %.not27 = icmp eq ptr %20, null
  br i1 %.not27, label %.loopexit, label %.lr.ph33, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph33, %15, %.lr.ph36
  %21 = tail call i32 @isStackEmpty(ptr noundef %6) #6
  %.not25 = icmp eq i32 %21, 0
  br i1 %.not25, label %.lr.ph36, label %._crit_edge37, !llvm.loop !14

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

declare ptr @createStack() local_unnamed_addr #2

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

declare i32 @isStackEmpty(ptr noundef) local_unnamed_addr #2

declare ptr @pop(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: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass