; LLVM IR from DevonCrawford/A-Pathfinding-in-C-command-line :: backups (pathfinding_copy3)

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

@size = external dso_local global %struct.GridSize, align 4

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: nounwind uwtable
declare dso_local void @getNode(ptr dead_on_unwind noalias writable sret(%struct.Node) align 8, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @arrangeID(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @lowestFCost(ptr dead_on_unwind noalias writable sret(%struct.Node) align 8 %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca %struct.Node, align 8
  %10 = alloca %struct.Node, align 8
  %11 = alloca i32, align 4
  store ptr %1, ptr %4, align 8, !tbaa !5
  store i32 %2, ptr %5, align 4, !tbaa !9
  %12 = load i32, ptr @size, align 4, !tbaa !11
  %13 = zext i32 %12 to i64
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %18

16:                                               ; preds = %3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  call void @getNode(ptr dead_on_unwind writable sret(%struct.Node) align 8 %0, ptr noundef %17, i32 noundef 0)
  br label %64

18:                                               ; preds = %3
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = call ptr @llvm.stacksave.p0()
  store ptr %21, ptr %6, align 8
  %22 = alloca %struct.Node, i64 %20, align 16
  store i64 %20, ptr %7, align 8
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !9
  call void @arrangeID(ptr noundef %22, ptr noundef %23, i32 noundef %24)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 -1, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 40, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  br label %25

25:                                               ; preds = %60, %18
  %26 = load i32, ptr %8, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %61

28:                                               ; preds = %25
  store i32 0, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %57, %28
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = sub nsw i32 %31, 1
  %33 = icmp slt i32 %30, %32
  br i1 %33, label %34, label %60

34:                                               ; preds = %29
  %35 = load i32, ptr %11, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.Node, ptr %22, i64 %36
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %37, i64 40, i1 false), !tbaa.struct !13
  %38 = load i32, ptr %11, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds %struct.Node, ptr %22, i64 %40
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %41, i64 40, i1 false), !tbaa.struct !13
  %42 = getelementptr inbounds %struct.Node, ptr %9, i32 0, i32 6
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = getelementptr inbounds %struct.Node, ptr %10, i32 0, i32 6
  %45 = load i32, ptr %44, align 4, !tbaa !14
  %46 = icmp sgt i32 %43, %45
  br i1 %46, label %47, label %56

47:                                               ; preds = %34
  %48 = getelementptr inbounds %struct.Node, ptr %9, i32 0, i32 7
  %49 = load i32, ptr %48, align 8, !tbaa !16
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %struct.Node, ptr %22, i64 %50
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %51, ptr align 8 %10, i64 40, i1 false), !tbaa.struct !13
  %52 = getelementptr inbounds %struct.Node, ptr %10, i32 0, i32 7
  %53 = load i32, ptr %52, align 8, !tbaa !16
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds %struct.Node, ptr %22, i64 %54
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %55, ptr align 8 %9, i64 40, i1 false), !tbaa.struct !13
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %47, %34
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %11, align 4, !tbaa !9
  br label %29, !llvm.loop !17

60:                                               ; preds = %29
  br label %25, !llvm.loop !19

61:                                               ; preds = %25
  %62 = getelementptr inbounds %struct.Node, ptr %22, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 16 %62, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %63 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %63)
  br label %64

64:                                               ; preds = %61, %16
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn }
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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"GridSize", !10, i64 0, !10, i64 4}
!13 = !{i64 0, i64 8, !5, i64 8, i64 4, !9, i64 12, i64 4, !9, i64 16, i64 4, !9, i64 20, i64 4, !9, i64 24, i64 4, !9, i64 28, i64 4, !9, i64 32, i64 4, !9}
!14 = !{!15, !10, i64 28}
!15 = !{!"Node", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!16 = !{!15, !10, i64 32}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

%struct.Node = type { ptr, i32, i32, i32, i32, i32, i32, i32 }

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: nounwind uwtable
declare dso_local void @getNode(ptr dead_on_unwind noalias writable sret(%struct.Node) align 8, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare dso_local void @arrangeID(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local void @lowestFCost(ptr dead_on_unwind noalias writable sret(%struct.Node) align 8 %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #3 {
  %.sroa.010 = alloca [28 x i8], align 8
  %4 = icmp eq i32 %2, 1
  br i1 %4, label %5, label %6

5:                                                ; preds = %3
  tail call void @getNode(ptr dead_on_unwind writable sret(%struct.Node) align 8 %0, ptr noundef %1, i32 noundef 0)
  br label %25

6:                                                ; preds = %3
  %7 = zext i32 %2 to i64
  %8 = tail call ptr @llvm.stacksave.p0()
  %9 = alloca %struct.Node, i64 %7, align 16
  call void @arrangeID(ptr noundef nonnull %9, ptr noundef %1, i32 noundef %2)
  call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %.sroa.010)
  %10 = icmp sgt i32 %2, 1
  br i1 %10, label %.preheader.us.preheader, label %.split32.us

.preheader.us.preheader:                          ; preds = %6
  %11 = add nsw i32 %2, -1
  %wide.trip.count = zext i32 %11 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.backedge, %.preheader.us.preheader
  %indvars.iv = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.be, %.preheader.us.backedge ]
  %.129.us = phi i32 [ 0, %.preheader.us.preheader ], [ %.129.us.be, %.preheader.us.backedge ]
  %12 = getelementptr inbounds %struct.Node, ptr %9, i64 %indvars.iv
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(28) %.sroa.010, ptr noundef nonnull align 8 dereferenceable(28) %12, i64 28, i1 false), !tbaa.struct !5
  %.sroa.411.0..sroa_idx.us = getelementptr inbounds i8, ptr %12, i64 28
  %.sroa.411.0.copyload.us = load i32, ptr %.sroa.411.0..sroa_idx.us, align 4, !tbaa !10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = getelementptr inbounds %struct.Node, ptr %9, i64 %indvars.iv.next
  %.sroa.4.0..sroa_idx.us = getelementptr inbounds i8, ptr %13, i64 28
  %.sroa.4.0.copyload.us = load i32, ptr %.sroa.4.0..sroa_idx.us, align 4, !tbaa !10
  %14 = icmp sgt i32 %.sroa.411.0.copyload.us, %.sroa.4.0.copyload.us
  br i1 %14, label %15, label %24

15:                                               ; preds = %.preheader.us
  %.sroa.514.0..sroa_idx.us = getelementptr inbounds i8, ptr %12, i64 32
  %.sroa.5.0..sroa_idx.us = getelementptr inbounds i8, ptr %13, i64 32
  %16 = load <2 x i32>, ptr %.sroa.514.0..sroa_idx.us, align 8
  %17 = extractelement <2 x i32> %16, i64 0
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds %struct.Node, ptr %9, i64 %18
  %.sroa.4.0..sroa_idx4.us = getelementptr inbounds i8, ptr %19, i64 28
  %.sroa.5.0..sroa_idx6.us = getelementptr inbounds i8, ptr %19, i64 32
  %20 = load <2 x i32>, ptr %.sroa.5.0..sroa_idx.us, align 8
  %21 = extractelement <2 x i32> %20, i64 0
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %struct.Node, ptr %9, i64 %22
  %.sroa.411.0..sroa_idx12.us = getelementptr inbounds i8, ptr %23, i64 28
  %.sroa.514.0..sroa_idx15.us = getelementptr inbounds i8, ptr %23, i64 32
  call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(28) %19, ptr noundef nonnull align 8 dereferenceable(28) %13, i64 28, i1 false)
  store i32 %.sroa.4.0.copyload.us, ptr %.sroa.4.0..sroa_idx4.us, align 4, !tbaa !10
  store <2 x i32> %20, ptr %.sroa.5.0..sroa_idx6.us, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(28) %23, ptr noundef nonnull align 8 dereferenceable(28) %.sroa.010, i64 28, i1 false), !tbaa.struct !5
  store i32 %.sroa.411.0.copyload.us, ptr %.sroa.411.0..sroa_idx12.us, align 4, !tbaa !10
  store <2 x i32> %16, ptr %.sroa.514.0..sroa_idx15.us, align 8
  br label %24

24:                                               ; preds = %15, %.preheader.us
  %.2.us = phi i32 [ 1, %15 ], [ %.129.us, %.preheader.us ]
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %..loopexit_crit_edge.us, label %.preheader.us.backedge

.preheader.us.backedge:                           ; preds = %24, %..loopexit_crit_edge.us
  %indvars.iv.be = phi i64 [ %indvars.iv.next, %24 ], [ 0, %..loopexit_crit_edge.us ]
  %.129.us.be = phi i32 [ %.2.us, %24 ], [ 0, %..loopexit_crit_edge.us ]
  br label %.preheader.us, !llvm.loop !12

..loopexit_crit_edge.us:                          ; preds = %24
  %.not.us = icmp eq i32 %.2.us, 0
  br i1 %.not.us, label %.split32.us, label %.preheader.us.backedge

.split32.us:                                      ; preds = %..loopexit_crit_edge.us, %6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 16 dereferenceable(40) %9, i64 40, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %.sroa.010)
  call void @llvm.stackrestore.p0(ptr %8)
  br label %25

25:                                               ; preds = %.split32.us, %5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = !{i64 0, i64 8, !6, i64 8, i64 4, !10, i64 12, i64 4, !10, i64 16, i64 4, !10, i64 20, i64 4, !10, i64 24, i64 4, !10, i64 28, i64 4, !10, i64 32, i64 4, !10}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass