; 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.13 = external hidden unnamed_addr constant [35 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

declare ptr @createLinkedList() #1

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

declare ptr @createNode(ptr noundef) #1

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

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

declare ptr @createStack() #1

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

declare i32 @isStackEmpty(ptr noundef) #1

declare ptr @pop(ptr noundef) #1

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

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

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %19 = call ptr @createStack()
  store ptr %19, 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
  %20 = call ptr @createLinkedList()
  store ptr %20, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %21 = call ptr @createLinkedList()
  store ptr %21, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store ptr null, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store ptr null, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.graphs, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = call ptr @getHead(ptr noundef %24)
  store ptr %25, ptr %11, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %29, %18
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %36

29:                                               ; preds = %26
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = call ptr @getData(ptr noundef %30)
  store ptr %31, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  call void @vertexSetGroup(ptr noundef %32, i32 noundef 0)
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  call void @vertexSetDad(ptr noundef %33, ptr noundef null)
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = call ptr @getNext(ptr noundef %34)
  store ptr %35, ptr %11, align 8, !tbaa !5
  br label %26, !llvm.loop !12

36:                                               ; preds = %26
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %37, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call ptr @createEdge(ptr noundef %38, ptr noundef %39, ptr noundef null)
  store ptr %40, ptr %10, align 8, !tbaa !5
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  call void @push(ptr noundef %41, ptr noundef %42)
  br label %43

43:                                               ; preds = %104, %36
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call i32 @isStackEmpty(ptr noundef %44)
  %46 = icmp ne i32 %45, 0
  %47 = xor i1 %46, true
  br i1 %47, label %48, label %105

48:                                               ; preds = %43
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = call ptr @pop(ptr noundef %49)
  store ptr %50, ptr %9, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = call ptr @edgeGetAdjacent(ptr noundef %51)
  store ptr %52, ptr %6, align 8, !tbaa !5
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = call i32 @vertexGetGroup(ptr noundef %53)
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %87, label %56

56:                                               ; preds = %48
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  call void @vertexSetGroup(ptr noundef %57, i32 noundef 1)
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = call ptr @createNode(ptr noundef %58)
  store ptr %59, ptr %11, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  call void @addTail(ptr noundef %60, ptr noundef %61)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = call ptr @vertexGetEdges(ptr noundef %62)
  store ptr %63, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = call ptr @getHead(ptr noundef %64)
  store ptr %65, ptr %13, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %81, %56
  %67 = load ptr, ptr %13, align 8, !tbaa !5
  %68 = icmp ne ptr %67, null
  br i1 %68, label %69, label %86

69:                                               ; preds = %66
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = call ptr @getData(ptr noundef %70)
  store ptr %71, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = call ptr @edgeGetAdjacent(ptr noundef %72)
  store ptr %73, ptr %14, align 8, !tbaa !5
  %74 = load ptr, ptr %14, align 8, !tbaa !5
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = call ptr @vertexGetDad(ptr noundef %75)
  %77 = icmp ne ptr %74, %76
  br i1 %77, label %78, label %81

78:                                               ; preds = %69
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  call void @push(ptr noundef %79, ptr noundef %80)
  br label %81

81:                                               ; preds = %78, %69
  %82 = load ptr, ptr %14, align 8, !tbaa !5
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  call void @vertexSetDad(ptr noundef %82, ptr noundef %83)
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  %85 = call ptr @getNext(ptr noundef %84)
  store ptr %85, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %66, !llvm.loop !14

86:                                               ; preds = %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %104

87:                                               ; preds = %48
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  %89 = call i32 @isEdgeUsed(ptr noundef %88)
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %103, label %91

91:                                               ; preds = %87
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = call ptr @counterEdge(ptr noundef %92)
  %94 = call i32 @isEdgeUsed(ptr noundef %93)
  %95 = icmp ne i32 %94, 0
  br i1 %95, label %103, label %96

96:                                               ; preds = %91
  %97 = load ptr, ptr %8, align 8, !tbaa !5
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = load ptr, ptr %9, align 8, !tbaa !5
  call void @createLoop(ptr noundef %97, ptr noundef %98, ptr noundef %99)
  %100 = load ptr, ptr %9, align 8, !tbaa !5
  call void @setUsedEdge(ptr noundef %100, i32 noundef 1)
  %101 = load ptr, ptr %9, align 8, !tbaa !5
  %102 = call ptr @counterEdge(ptr noundef %101)
  call void @setUsedEdge(ptr noundef %102, i32 noundef 1)
  br label %103

103:                                              ; preds = %96, %91, %87
  br label %104

104:                                              ; preds = %103, %86
  br label %43, !llvm.loop !15

105:                                              ; preds = %43
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  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 ptr %106
}

declare ptr @createEdge(ptr noundef, ptr noundef, ptr noundef) #1

declare ptr @vertexGetDad(ptr noundef) #1

declare i32 @isEdgeUsed(ptr noundef) #1

declare ptr @counterEdge(ptr noundef) #1

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

declare void @setUsedEdge(ptr noundef, i32 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.13 = external hidden unnamed_addr constant [35 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 @createLinkedList() local_unnamed_addr #2

declare ptr @createNode(ptr noundef) local_unnamed_addr #2

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

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

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

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

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

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

._crit_edge:                                      ; preds = %.lr.ph, %5
  %14 = tail call ptr @createEdge(ptr noundef %1, ptr noundef %1, ptr noundef null) #6
  tail call void @push(ptr noundef %14, ptr noundef %6) #6
  %15 = tail call i32 @isStackEmpty(ptr noundef %6) #6
  %.not4254 = icmp eq i32 %15, 0
  br i1 %.not4254, label %.lr.ph56, label %._crit_edge57

.lr.ph56:                                         ; preds = %._crit_edge, %.loopexit
  %16 = tail call ptr @pop(ptr noundef %6) #6
  %17 = tail call ptr @edgeGetAdjacent(ptr noundef %16) #6
  %18 = tail call i32 @vertexGetGroup(ptr noundef %17) #6
  %.not43 = icmp eq i32 %18, 0
  br i1 %.not43, label %19, label %29

19:                                               ; preds = %.lr.ph56
  tail call void @vertexSetGroup(ptr noundef %17, i32 noundef 1) #6
  %20 = tail call ptr @createNode(ptr noundef %16) #6
  tail call void @addTail(ptr noundef %7, ptr noundef %20) #6
  %21 = tail call ptr @vertexGetEdges(ptr noundef %17) #6
  %22 = tail call ptr @getHead(ptr noundef %21) #6
  %.not4450 = icmp eq ptr %22, null
  br i1 %.not4450, label %.loopexit, label %.lr.ph53

.lr.ph53:                                         ; preds = %19, %27
  %.051 = phi ptr [ %28, %27 ], [ %22, %19 ]
  %23 = tail call ptr @getData(ptr noundef nonnull %.051) #6
  %24 = tail call ptr @edgeGetAdjacent(ptr noundef %23) #6
  %25 = tail call ptr @vertexGetDad(ptr noundef %17) #6
  %.not45 = icmp eq ptr %24, %25
  br i1 %.not45, label %27, label %26

26:                                               ; preds = %.lr.ph53
  tail call void @push(ptr noundef %23, ptr noundef %6) #6
  br label %27

27:                                               ; preds = %26, %.lr.ph53
  tail call void @vertexSetDad(ptr noundef %24, ptr noundef %17) #6
  %28 = tail call ptr @getNext(ptr noundef nonnull %.051) #6
  %.not44 = icmp eq ptr %28, null
  br i1 %.not44, label %.loopexit, label %.lr.ph53, !llvm.loop !13

29:                                               ; preds = %.lr.ph56
  %30 = tail call i32 @isEdgeUsed(ptr noundef %16) #6
  %.not46 = icmp eq i32 %30, 0
  br i1 %.not46, label %31, label %.loopexit

31:                                               ; preds = %29
  %32 = tail call ptr @counterEdge(ptr noundef %16) #6
  %33 = tail call i32 @isEdgeUsed(ptr noundef %32) #6
  %.not47 = icmp eq i32 %33, 0
  br i1 %.not47, label %34, label %.loopexit

34:                                               ; preds = %31
  tail call void @createLoop(ptr noundef %8, ptr noundef %7, ptr noundef %16) #6
  tail call void @setUsedEdge(ptr noundef %16, i32 noundef 1) #6
  %35 = tail call ptr @counterEdge(ptr noundef %16) #6
  tail call void @setUsedEdge(ptr noundef %35, i32 noundef 1) #6
  br label %.loopexit

.loopexit:                                        ; preds = %27, %19, %29, %31, %34
  %36 = tail call i32 @isStackEmpty(ptr noundef %6) #6
  %.not42 = icmp eq i32 %36, 0
  br i1 %.not42, label %.lr.ph56, label %._crit_edge57, !llvm.loop !14

._crit_edge57:                                    ; preds = %.loopexit, %._crit_edge
  ret ptr %8
}

declare ptr @createEdge(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare ptr @vertexGetDad(ptr noundef) local_unnamed_addr #2

declare i32 @isEdgeUsed(ptr noundef) local_unnamed_addr #2

declare ptr @counterEdge(ptr noundef) local_unnamed_addr #2

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

declare void @setUsedEdge(ptr noundef, i32 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