; 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 @getNodeChar(ptr dead_on_unwind noalias writable sret(%struct.Node) align 8 %0, ptr noundef %1, i8 noundef signext %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %1, ptr %4, align 8, !tbaa !5
  store i8 %2, ptr %5, align 1, !tbaa !9
  %9 = load i32, ptr @size, align 4, !tbaa !10
  %10 = zext i32 %9 to i64
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @clearNode(ptr noundef %0)
  store i32 0, ptr %6, align 4, !tbaa !13
  br label %11

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

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

16:                                               ; preds = %41, %15
  %17 = load i32, ptr %7, align 4, !tbaa !13
  %18 = load i32, ptr @size, align 4, !tbaa !10
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %44

20:                                               ; preds = %16
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !13
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %23, %10
  %25 = getelementptr inbounds i8, ptr %21, i64 %24
  %26 = load i32, ptr %7, align 4, !tbaa !13
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !9
  %30 = sext i8 %29 to i32
  %31 = load i8, ptr %5, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = icmp eq i32 %30, %32
  br i1 %33, label %34, label %40

34:                                               ; preds = %20
  %35 = load i32, ptr %7, align 4, !tbaa !13
  %36 = getelementptr inbounds %struct.Node, ptr %0, i32 0, i32 2
  store i32 %35, ptr %36, align 4, !tbaa !14
  %37 = load i32, ptr %6, align 4, !tbaa !13
  %38 = getelementptr inbounds %struct.Node, ptr %0, i32 0, i32 3
  store i32 %37, ptr %38, align 8, !tbaa !16
  %39 = getelementptr inbounds %struct.Node, ptr %0, i32 0, i32 1
  store i32 1, ptr %39, align 8, !tbaa !17
  store i32 1, ptr %8, align 4
  br label %49

40:                                               ; preds = %20
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %7, align 4, !tbaa !13
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %7, align 4, !tbaa !13
  br label %16, !llvm.loop !18

44:                                               ; preds = %16
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %6, align 4, !tbaa !13
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %6, align 4, !tbaa !13
  br label %11, !llvm.loop !20

48:                                               ; preds = %11
  store i32 1, ptr %8, align 4
  br label %49

49:                                               ; preds = %48, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"GridSize", !12, i64 0, !12, i64 4}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !12, i64 12}
!15 = !{!"Node", !6, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32}
!16 = !{!15, !12, i64 16}
!17 = !{!15, !12, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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 @getNodeChar(ptr dead_on_unwind noalias writable sret(%struct.Node) align 8 %0, ptr nocapture noundef readonly %1, i8 noundef signext %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @size, align 4, !tbaa !5
  %5 = zext i32 %4 to i64
  tail call void @clearNode(ptr noundef %0)
  %6 = load i32, ptr @size, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.preheader.us.preheader, label %.loopexit

.preheader.us.preheader:                          ; preds = %3
  %wide.trip.count21 = zext nneg i32 %6 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv18 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next19, %._crit_edge.us ]
  %8 = mul nuw nsw i64 %indvars.iv18, %5
  %9 = getelementptr inbounds i8, ptr %1, i64 %8
  br label %10

10:                                               ; preds = %.preheader.us, %14
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %14 ]
  %11 = getelementptr inbounds i8, ptr %9, i64 %indvars.iv
  %12 = load i8, ptr %11, align 1, !tbaa !10
  %13 = icmp eq i8 %12, %2
  br i1 %13, label %.split.us, label %14

14:                                               ; preds = %10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count21
  br i1 %exitcond.not, label %._crit_edge.us, label %10, !llvm.loop !11

._crit_edge.us:                                   ; preds = %14
  %indvars.iv.next19 = add nuw nsw i64 %indvars.iv18, 1
  %exitcond22.not = icmp eq i64 %indvars.iv.next19, %wide.trip.count21
  br i1 %exitcond22.not, label %.loopexit, label %.preheader.us, !llvm.loop !13

.split.us:                                        ; preds = %10
  %15 = trunc nuw nsw i64 %indvars.iv18 to i32
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  %17 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %16, ptr %17, align 4, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %15, ptr %18, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 1, ptr %19, align 8, !tbaa !18
  br label %.loopexit

.loopexit:                                        ; preds = %._crit_edge.us, %3, %.split.us
  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 = !{!8, !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !7, i64 12}
!15 = !{!"Node", !16, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!15, !7, i64 16}
!18 = !{!15, !7, i64 8}


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