; 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 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 @initNodes(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load i32, ptr @size, align 4, !tbaa !9
  %6 = zext i32 %5 to i64
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %3, align 4, !tbaa !12
  br label %7

7:                                                ; preds = %49, %1
  %8 = load i32, ptr %3, align 4, !tbaa !12
  %9 = load i32, ptr getelementptr inbounds (%struct.GridSize, ptr @size, i32 0, i32 1), align 4, !tbaa !13
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %11, label %52

11:                                               ; preds = %7
  store i32 0, ptr %4, align 4, !tbaa !12
  br label %12

12:                                               ; preds = %45, %11
  %13 = load i32, ptr %4, align 4, !tbaa !12
  %14 = load i32, ptr @size, align 4, !tbaa !9
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %16, label %48

16:                                               ; preds = %12
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !12
  %19 = sext i32 %18 to i64
  %20 = mul nsw i64 %19, %6
  %21 = getelementptr inbounds %struct.Node, ptr %17, i64 %20
  %22 = load i32, ptr %4, align 4, !tbaa !12
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds %struct.Node, ptr %21, i64 %23
  call void @clearNode(ptr noundef %24)
  %25 = load i32, ptr %4, align 4, !tbaa !12
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !12
  %28 = sext i32 %27 to i64
  %29 = mul nsw i64 %28, %6
  %30 = getelementptr inbounds %struct.Node, ptr %26, i64 %29
  %31 = load i32, ptr %4, align 4, !tbaa !12
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct.Node, ptr %30, i64 %32
  %34 = getelementptr inbounds %struct.Node, ptr %33, i32 0, i32 2
  store i32 %25, ptr %34, align 4, !tbaa !14
  %35 = load i32, ptr %3, align 4, !tbaa !12
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = load i32, ptr %3, align 4, !tbaa !12
  %38 = sext i32 %37 to i64
  %39 = mul nsw i64 %38, %6
  %40 = getelementptr inbounds %struct.Node, ptr %36, i64 %39
  %41 = load i32, ptr %4, align 4, !tbaa !12
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.Node, ptr %40, i64 %42
  %44 = getelementptr inbounds %struct.Node, ptr %43, i32 0, i32 3
  store i32 %35, ptr %44, align 8, !tbaa !16
  br label %45

45:                                               ; preds = %16
  %46 = load i32, ptr %4, align 4, !tbaa !12
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %4, align 4, !tbaa !12
  br label %12, !llvm.loop !17

48:                                               ; preds = %12
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %3, align 4, !tbaa !12
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %3, align 4, !tbaa !12
  br label %7, !llvm.loop !19

52:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @clearNode(ptr noundef) #1

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"GridSize", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!15, !11, i64 12}
!15 = !{!"Node", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32}
!16 = !{!15, !11, i64 16}
!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.GridSize = type { i32, i32 }
%struct.Node = type { ptr, i32, i32, i32, i32, i32, i32, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local void @initNodes(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @size, align 4, !tbaa !5
  %3 = zext i32 %2 to i64
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @size, i64 4), align 4, !tbaa !10
  %5 = icmp sgt i32 %4, 0
  %6 = icmp sgt i32 %2, 0
  %or.cond = select i1 %5, i1 %6, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge17

.preheader:                                       ; preds = %1, %._crit_edge
  %7 = phi i32 [ %21, %._crit_edge ], [ %4, %1 ]
  %8 = phi i32 [ %22, %._crit_edge ], [ %2, %1 ]
  %indvars.iv20 = phi i64 [ %indvars.iv.next21, %._crit_edge ], [ 0, %1 ]
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %10 = mul nuw nsw i64 %indvars.iv20, %3
  %11 = getelementptr inbounds %struct.Node, ptr %0, i64 %10
  %12 = trunc nuw nsw i64 %indvars.iv20 to i32
  br label %13

13:                                               ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %14 = getelementptr inbounds %struct.Node, ptr %11, i64 %indvars.iv
  tail call void @clearNode(ptr noundef %14)
  %15 = getelementptr inbounds i8, ptr %14, i64 12
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %16, ptr %15, align 4, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %14, i64 16
  store i32 %12, ptr %17, align 8, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i32, ptr @size, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %13, label %._crit_edge.loopexit, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %13
  %.pre = load i32, ptr getelementptr inbounds (i8, ptr @size, i64 4), align 4, !tbaa !10
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %21 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %7, %.preheader ]
  %22 = phi i32 [ %18, %._crit_edge.loopexit ], [ %8, %.preheader ]
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %23 = sext i32 %21 to i64
  %24 = icmp slt i64 %indvars.iv.next21, %23
  br i1 %24, label %.preheader, label %._crit_edge17, !llvm.loop !17

._crit_edge17:                                    ; preds = %._crit_edge, %1
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local void @clearNode(ptr noundef) local_unnamed_addr #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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass