; LLVM IR from AlgoGenesis/C :: Graph Algorithms/Kruskal's Algorithm (Program)

; 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.Graph = type { i32, i32, ptr }
%struct.Edge = type { i32, i32, i32 }

; Function Attrs: nounwind uwtable
declare dso_local ptr @createGraph(i32 noundef, i32 noundef) #0

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

; 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 dso_local void @KruskalMST(ptr noundef) #0

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 4, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 5, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = call ptr @createGraph(i32 noundef %5, i32 noundef %6)
  store ptr %7, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.Graph, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.Edge, ptr %10, i64 0
  %12 = getelementptr inbounds %struct.Edge, ptr %11, i32 0, i32 0
  store i32 0, ptr %12, align 4, !tbaa !13
  %13 = load ptr, ptr %4, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.Graph, ptr %13, i32 0, i32 2
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds %struct.Edge, ptr %15, i64 0
  %17 = getelementptr inbounds %struct.Edge, ptr %16, i32 0, i32 1
  store i32 1, ptr %17, align 4, !tbaa !15
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.Graph, ptr %18, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.Edge, ptr %20, i64 0
  %22 = getelementptr inbounds %struct.Edge, ptr %21, i32 0, i32 2
  store i32 10, ptr %22, align 4, !tbaa !16
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.Graph, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = getelementptr inbounds %struct.Edge, ptr %25, i64 1
  %27 = getelementptr inbounds %struct.Edge, ptr %26, i32 0, i32 0
  store i32 0, ptr %27, align 4, !tbaa !13
  %28 = load ptr, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.Graph, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = getelementptr inbounds %struct.Edge, ptr %30, i64 1
  %32 = getelementptr inbounds %struct.Edge, ptr %31, i32 0, i32 1
  store i32 2, ptr %32, align 4, !tbaa !15
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.Graph, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds %struct.Edge, ptr %35, i64 1
  %37 = getelementptr inbounds %struct.Edge, ptr %36, i32 0, i32 2
  store i32 6, ptr %37, align 4, !tbaa !16
  %38 = load ptr, ptr %4, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.Graph, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = getelementptr inbounds %struct.Edge, ptr %40, i64 2
  %42 = getelementptr inbounds %struct.Edge, ptr %41, i32 0, i32 0
  store i32 0, ptr %42, align 4, !tbaa !13
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.Graph, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.Edge, ptr %45, i64 2
  %47 = getelementptr inbounds %struct.Edge, ptr %46, i32 0, i32 1
  store i32 3, ptr %47, align 4, !tbaa !15
  %48 = load ptr, ptr %4, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.Graph, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.Edge, ptr %50, i64 2
  %52 = getelementptr inbounds %struct.Edge, ptr %51, i32 0, i32 2
  store i32 5, ptr %52, align 4, !tbaa !16
  %53 = load ptr, ptr %4, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.Graph, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.Edge, ptr %55, i64 3
  %57 = getelementptr inbounds %struct.Edge, ptr %56, i32 0, i32 0
  store i32 1, ptr %57, align 4, !tbaa !13
  %58 = load ptr, ptr %4, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.Graph, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !11
  %61 = getelementptr inbounds %struct.Edge, ptr %60, i64 3
  %62 = getelementptr inbounds %struct.Edge, ptr %61, i32 0, i32 1
  store i32 3, ptr %62, align 4, !tbaa !15
  %63 = load ptr, ptr %4, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.Graph, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !11
  %66 = getelementptr inbounds %struct.Edge, ptr %65, i64 3
  %67 = getelementptr inbounds %struct.Edge, ptr %66, i32 0, i32 2
  store i32 15, ptr %67, align 4, !tbaa !16
  %68 = load ptr, ptr %4, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.Graph, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !11
  %71 = getelementptr inbounds %struct.Edge, ptr %70, i64 4
  %72 = getelementptr inbounds %struct.Edge, ptr %71, i32 0, i32 0
  store i32 2, ptr %72, align 4, !tbaa !13
  %73 = load ptr, ptr %4, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.Graph, ptr %73, i32 0, i32 2
  %75 = load ptr, ptr %74, align 8, !tbaa !11
  %76 = getelementptr inbounds %struct.Edge, ptr %75, i64 4
  %77 = getelementptr inbounds %struct.Edge, ptr %76, i32 0, i32 1
  store i32 3, ptr %77, align 4, !tbaa !15
  %78 = load ptr, ptr %4, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.Graph, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !11
  %81 = getelementptr inbounds %struct.Edge, ptr %80, i64 4
  %82 = getelementptr inbounds %struct.Edge, ptr %81, i32 0, i32 2
  store i32 4, ptr %82, align 4, !tbaa !16
  %83 = load ptr, ptr %4, align 8, !tbaa !9
  call void @KruskalMST(ptr noundef %83)
  %84 = load ptr, ptr %4, align 8, !tbaa !9
  %85 = getelementptr inbounds %struct.Graph, ptr %84, i32 0, i32 2
  %86 = load ptr, ptr %85, align 8, !tbaa !11
  call void @free(ptr noundef %86) #3
  %87 = load ptr, ptr %4, align 8, !tbaa !9
  call void @free(ptr noundef %87) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 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 "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, !10, i64 8}
!12 = !{!"Graph", !6, i64 0, !6, i64 4, !10, i64 8}
!13 = !{!14, !6, i64 0}
!14 = !{!"Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!15 = !{!14, !6, i64 4}
!16 = !{!14, !6, i64 8}


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

; Function Attrs: nounwind uwtable
declare dso_local ptr @createGraph(i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call ptr @createGraph(i32 noundef 4, i32 noundef 5)
  %2 = getelementptr inbounds i8, ptr %1, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  store <4 x i32> <i32 0, i32 1, i32 10, i32 0>, ptr %3, align 4, !tbaa !11
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  store <4 x i32> <i32 2, i32 6, i32 0, i32 3>, ptr %4, align 4, !tbaa !11
  %5 = getelementptr inbounds i8, ptr %3, i64 32
  store <4 x i32> <i32 5, i32 1, i32 3, i32 15>, ptr %5, align 4, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %3, i64 48
  store i32 2, ptr %6, align 4, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %3, i64 52
  store i32 3, ptr %7, align 4, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %3, i64 56
  store i32 4, ptr %8, align 4, !tbaa !15
  tail call void @KruskalMST(ptr noundef %1)
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @free(ptr noundef %9) #2
  tail call void @free(ptr noundef %1) #2
  ret i32 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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, !10, i64 8}
!6 = !{!"Graph", !7, i64 0, !7, i64 4, !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 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"Edge", !7, i64 0, !7, i64 4, !7, i64 8}
!14 = !{!13, !7, i64 4}
!15 = !{!13, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass