; LLVM IR from MakeContributions/DSA :: algorithms/C/graphs (Prim's-algorithm)

; 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, i32, i32, ptr }

; 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 @change(i32 noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %10 = load ptr, ptr %6, align 8, !tbaa !9
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.node, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = icmp eq i32 %13, %14
  br i1 %15, label %16, label %25

16:                                               ; preds = %4
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.node, ptr %19, i32 0, i32 2
  store i32 %17, ptr %20, align 8, !tbaa !13
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.node, ptr %23, i32 0, i32 1
  store i32 %21, ptr %24, align 4, !tbaa !14
  br label %49

25:                                               ; preds = %4
  %26 = load ptr, ptr %6, align 8, !tbaa !9
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  store ptr %27, ptr %9, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %44, %25
  %29 = load ptr, ptr %9, align 8, !tbaa !9
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %48

31:                                               ; preds = %28
  %32 = load ptr, ptr %9, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = icmp eq i32 %34, %35
  br i1 %36, label %37, label %44

37:                                               ; preds = %31
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load ptr, ptr %9, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.node, ptr %39, i32 0, i32 2
  store i32 %38, ptr %40, align 8, !tbaa !13
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = load ptr, ptr %9, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.node, ptr %42, i32 0, i32 1
  store i32 %41, ptr %43, align 4, !tbaa !14
  br label %48

44:                                               ; preds = %31
  %45 = load ptr, ptr %9, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.node, ptr %45, i32 0, i32 3
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  store ptr %47, ptr %9, align 8, !tbaa !9
  br label %28, !llvm.loop !16

48:                                               ; preds = %37, %28
  br label %49

49:                                               ; preds = %48, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret void
}

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 = { 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, !6, i64 4, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 4}
!15 = !{!12, !10, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @change(i32 noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load ptr, ptr %1, align 8, !tbaa !5
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp eq i32 %6, %0
  br i1 %7, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %4, %10
  %.016 = phi ptr [ %12, %10 ], [ %5, %4 ]
  %8 = load i32, ptr %.016, align 8, !tbaa !9
  %9 = icmp eq i32 %8, %0
  br i1 %9, label %.loopexit.sink.split, label %10

10:                                               ; preds = %.preheader
  %11 = getelementptr inbounds i8, ptr %.016, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %.loopexit, label %.preheader, !llvm.loop !13

.loopexit.sink.split:                             ; preds = %.preheader, %4
  %.016.lcssa.sink19 = phi ptr [ %5, %4 ], [ %.016, %.preheader ]
  %13 = getelementptr inbounds i8, ptr %.016.lcssa.sink19, i64 8
  store i32 %2, ptr %13, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %.016.lcssa.sink19, i64 4
  store i32 %3, ptr %14, align 4, !tbaa !16
  br label %.loopexit

.loopexit:                                        ; preds = %10, %.loopexit.sink.split
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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" }

!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, !11, i64 0}
!10 = !{!"node", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !11, i64 4}


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