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

; 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 @arrangeID(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @lowestF(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 = zext i32 %14 to i64
  %16 = call ptr @llvm.stacksave.p0()
  store ptr %16, ptr %6, align 8
  %17 = alloca %struct.Node, i64 %15, align 16
  store i64 %15, ptr %7, align 8
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !9
  call void @arrangeID(ptr noundef %17, ptr noundef %18, i32 noundef %19)
  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 %20

20:                                               ; preds = %54, %3
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %55

23:                                               ; preds = %20
  store i32 0, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %51, %23
  %25 = load i32, ptr %11, align 4, !tbaa !9
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = sub nsw i32 %26, 1
  %28 = icmp slt i32 %25, %27
  br i1 %28, label %29, label %54

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

42:                                               ; preds = %29
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.Node, ptr %17, i64 %44
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %45, ptr align 8 %10, i64 40, i1 false), !tbaa.struct !13
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds %struct.Node, ptr %17, i64 %48
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %49, ptr align 8 %9, i64 40, i1 false), !tbaa.struct !13
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %42, %29
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %11, align 4, !tbaa !9
  br label %24, !llvm.loop !16

54:                                               ; preds = %24
  br label %20, !llvm.loop !18

55:                                               ; preds = %20
  %56 = getelementptr inbounds %struct.Node, ptr %17, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 16 %56, 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
  %57 = load ptr, ptr %6, align 8
  call void @llvm.stackrestore.p0(ptr %57)
  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 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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: nounwind uwtable
declare dso_local void @arrangeID(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @lowestF(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.Node) align 8 %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %.sroa.010 = alloca [28 x i8], align 8
  %4 = zext i32 %2 to i64
  %5 = alloca %struct.Node, i64 %4, align 16
  call void @arrangeID(ptr noundef nonnull %5, ptr noundef %1, i32 noundef %2)
  call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %.sroa.010)
  %6 = icmp sgt i32 %2, 1
  br i1 %6, label %.preheader.us.preheader, label %.split26.us

.preheader.us.preheader:                          ; preds = %3
  %7 = add nsw i32 %2, -1
  %wide.trip.count = zext i32 %7 to i64
  %.sroa.411.0..sroa_idx.us.phi.trans.insert = getelementptr inbounds i8, ptr %5, i64 28
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %..loopexit_crit_edge.us
  %.sroa.411.0.copyload.us.pre = load i32, ptr %.sroa.411.0..sroa_idx.us.phi.trans.insert, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %.preheader.us, %13
  %.sroa.411.0.copyload.us = phi i32 [ %.sroa.411.0.copyload.us.pre, %.preheader.us ], [ %.sroa.411.0.copyload.us28, %13 ]
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %13 ]
  %.123.us = phi i32 [ 0, %.preheader.us ], [ %.2.us, %13 ]
  %9 = getelementptr inbounds %struct.Node, ptr %5, 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) %9, i64 28, i1 false), !tbaa.struct !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds %struct.Node, ptr %5, i64 %indvars.iv.next
  %.sroa.4.0..sroa_idx.us = getelementptr inbounds i8, ptr %10, i64 28
  %.sroa.4.0.copyload.us = load i32, ptr %.sroa.4.0..sroa_idx.us, align 4, !tbaa !5
  %11 = icmp sgt i32 %.sroa.411.0.copyload.us, %.sroa.4.0.copyload.us
  br i1 %11, label %12, label %13

12:                                               ; preds = %8
  %.sroa.514.0..sroa_idx.us = getelementptr inbounds i8, ptr %9, i64 32
  %.sroa.514.0.copyload.us = load i64, ptr %.sroa.514.0..sroa_idx.us, align 8
  %.sroa.411.0..sroa_idx.us = getelementptr inbounds i8, ptr %9, i64 28
  %.sroa.5.0..sroa_idx.us = getelementptr inbounds i8, ptr %10, i64 32
  %.sroa.5.0.copyload.us = load i64, ptr %.sroa.5.0..sroa_idx.us, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(28) %9, ptr noundef nonnull align 8 dereferenceable(28) %10, i64 28, i1 false)
  store i32 %.sroa.4.0.copyload.us, ptr %.sroa.411.0..sroa_idx.us, align 4, !tbaa !5
  store i64 %.sroa.5.0.copyload.us, ptr %.sroa.514.0..sroa_idx.us, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(28) %10, ptr noundef nonnull align 8 dereferenceable(28) %.sroa.010, i64 28, i1 false), !tbaa.struct !9
  store i32 %.sroa.411.0.copyload.us, ptr %.sroa.4.0..sroa_idx.us, align 4, !tbaa !5
  store i64 %.sroa.514.0.copyload.us, ptr %.sroa.5.0..sroa_idx.us, align 8
  br label %13

13:                                               ; preds = %12, %8
  %.sroa.411.0.copyload.us28 = phi i32 [ %.sroa.411.0.copyload.us, %12 ], [ %.sroa.4.0.copyload.us, %8 ]
  %.2.us = phi i32 [ 1, %12 ], [ %.123.us, %8 ]
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %..loopexit_crit_edge.us, label %8, !llvm.loop !12

..loopexit_crit_edge.us:                          ; preds = %13
  %.not.us = icmp eq i32 %.2.us, 0
  br i1 %.not.us, label %.split26.us, label %.preheader.us, !llvm.loop !14

.split26.us:                                      ; preds = %..loopexit_crit_edge.us, %3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 16 dereferenceable(40) %5, i64 40, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %.sroa.010)
  ret void
}

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

!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 = !{i64 0, i64 8, !10, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 4, !5, i64 20, i64 4, !5, i64 24, i64 4, !5, i64 28, i64 4, !5, i64 32, i64 4, !5}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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