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

13:                                               ; preds = %51, %3
  %14 = load i32, ptr %7, align 4, !tbaa !13
  %15 = load i32, ptr getelementptr inbounds (%struct.GridSize, ptr @size, i32 0, i32 1), align 4, !tbaa !14
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %54

17:                                               ; preds = %13
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %18

18:                                               ; preds = %47, %17
  %19 = load i32, ptr %8, align 4, !tbaa !13
  %20 = load i32, ptr @size, align 4, !tbaa !10
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %50

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

36:                                               ; preds = %22
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !13
  %39 = sext i32 %38 to i64
  %40 = mul nsw i64 %39, %12
  %41 = getelementptr inbounds %struct.Node, ptr %37, i64 %40
  %42 = load i32, ptr %8, align 4, !tbaa !13
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %struct.Node, ptr %41, i64 %43
  %45 = getelementptr inbounds %struct.Node, ptr %44, i32 0, i32 1
  store i32 1, ptr %45, align 8, !tbaa !15
  br label %46

46:                                               ; preds = %36, %22
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %8, align 4, !tbaa !13
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %8, align 4, !tbaa !13
  br label %18, !llvm.loop !17

50:                                               ; preds = %18
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %7, align 4, !tbaa !13
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !13
  br label %13, !llvm.loop !19

54:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #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 = !{!"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 = !{!11, !12, i64 4}
!15 = !{!16, !12, i64 8}
!16 = !{!"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}
!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: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @findNodes(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i8 noundef signext %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @size, align 4, !tbaa !5
  %5 = zext i32 %4 to i64
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @size, i64 4), align 4, !tbaa !10
  %7 = icmp sgt i32 %6, 0
  %8 = icmp sgt i32 %4, 0
  %or.cond = select i1 %7, i1 %8, i1 false
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge13

.preheader.us.preheader:                          ; preds = %3
  %wide.trip.count19 = zext nneg i32 %6 to i64
  %scevgep = getelementptr i8, ptr %1, i64 8
  %9 = mul nuw nsw i64 %wide.trip.count19, %5
  %10 = mul i64 %9, 40
  %11 = getelementptr i8, ptr %1, i64 %10
  %scevgep21 = getelementptr i8, ptr %11, i64 -28
  %12 = mul nuw nsw i64 %5, %wide.trip.count19
  %scevgep22 = getelementptr i8, ptr %0, i64 %12
  %min.iters.check = icmp ult i32 %4, 8
  %bound0 = icmp ult ptr %scevgep, %scevgep22
  %bound1 = icmp ugt ptr %scevgep21, %0
  %found.conflict = and i1 %bound0, %bound1
  %n.vec = and i64 %5, 2147483640
  %broadcast.splatinsert = insertelement <4 x i8> poison, i8 %2, i64 0
  %broadcast.splat = shufflevector <4 x i8> %broadcast.splatinsert, <4 x i8> poison, <4 x i32> zeroinitializer
  %cmp.n = icmp eq i64 %n.vec, %5
  %xtraiter = and i64 %5, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %13 = add nsw i64 %5, -1
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv16 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next17, %._crit_edge.us ]
  %14 = mul nuw nsw i64 %indvars.iv16, %5
  %15 = getelementptr inbounds i8, ptr %0, i64 %14
  %16 = getelementptr inbounds %struct.Node, ptr %1, i64 %14
  %brmerge = select i1 %min.iters.check, i1 true, i1 %found.conflict
  br i1 %brmerge, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us, %pred.store.continue37
  %index = phi i64 [ %index.next, %pred.store.continue37 ], [ 0, %.preheader.us ]
  %17 = or disjoint i64 %index, 4
  %18 = getelementptr inbounds i8, ptr %15, i64 %index
  %19 = getelementptr inbounds i8, ptr %18, i64 4
  %wide.load = load <4 x i8>, ptr %18, align 1, !tbaa !11, !alias.scope !12
  %wide.load23 = load <4 x i8>, ptr %19, align 1, !tbaa !11, !alias.scope !12
  %20 = icmp eq <4 x i8> %wide.load, %broadcast.splat
  %21 = icmp eq <4 x i8> %wide.load23, %broadcast.splat
  %22 = extractelement <4 x i1> %20, i64 0
  br i1 %22, label %pred.store.if, label %pred.store.continue

pred.store.if:                                    ; preds = %vector.body
  %23 = getelementptr inbounds %struct.Node, ptr %16, i64 %index, i32 1
  store i32 1, ptr %23, align 8, !tbaa !15, !alias.scope !18, !noalias !12
  br label %pred.store.continue

pred.store.continue:                              ; preds = %pred.store.if, %vector.body
  %24 = extractelement <4 x i1> %20, i64 1
  br i1 %24, label %pred.store.if24, label %pred.store.continue25

pred.store.if24:                                  ; preds = %pred.store.continue
  %25 = or disjoint i64 %index, 1
  %26 = getelementptr inbounds %struct.Node, ptr %16, i64 %25, i32 1
  store i32 1, ptr %26, align 8, !tbaa !15, !alias.scope !18, !noalias !12
  br label %pred.store.continue25

pred.store.continue25:                            ; preds = %pred.store.if24, %pred.store.continue
  %27 = extractelement <4 x i1> %20, i64 2
  br i1 %27, label %pred.store.if26, label %pred.store.continue27

pred.store.if26:                                  ; preds = %pred.store.continue25
  %28 = or disjoint i64 %index, 2
  %29 = getelementptr inbounds %struct.Node, ptr %16, i64 %28, i32 1
  store i32 1, ptr %29, align 8, !tbaa !15, !alias.scope !18, !noalias !12
  br label %pred.store.continue27

pred.store.continue27:                            ; preds = %pred.store.if26, %pred.store.continue25
  %30 = extractelement <4 x i1> %20, i64 3
  br i1 %30, label %pred.store.if28, label %pred.store.continue29

pred.store.if28:                                  ; preds = %pred.store.continue27
  %31 = or disjoint i64 %index, 3
  %32 = getelementptr inbounds %struct.Node, ptr %16, i64 %31, i32 1
  store i32 1, ptr %32, align 8, !tbaa !15, !alias.scope !18, !noalias !12
  br label %pred.store.continue29

pred.store.continue29:                            ; preds = %pred.store.if28, %pred.store.continue27
  %33 = extractelement <4 x i1> %21, i64 0
  br i1 %33, label %pred.store.if30, label %pred.store.continue31

pred.store.if30:                                  ; preds = %pred.store.continue29
  %34 = getelementptr inbounds %struct.Node, ptr %16, i64 %17, i32 1
  store i32 1, ptr %34, align 8, !tbaa !15, !alias.scope !18, !noalias !12
  br label %pred.store.continue31

pred.store.continue31:                            ; preds = %pred.store.if30, %pred.store.continue29
  %35 = extractelement <4 x i1> %21, i64 1
  br i1 %35, label %pred.store.if32, label %pred.store.continue33

pred.store.if32:                                  ; preds = %pred.store.continue31
  %36 = or disjoint i64 %index, 5
  %37 = getelementptr inbounds %struct.Node, ptr %16, i64 %36, i32 1
  store i32 1, ptr %37, align 8, !tbaa !15, !alias.scope !18, !noalias !12
  br label %pred.store.continue33

pred.store.continue33:                            ; preds = %pred.store.if32, %pred.store.continue31
  %38 = extractelement <4 x i1> %21, i64 2
  br i1 %38, label %pred.store.if34, label %pred.store.continue35

pred.store.if34:                                  ; preds = %pred.store.continue33
  %39 = or disjoint i64 %index, 6
  %40 = getelementptr inbounds %struct.Node, ptr %16, i64 %39, i32 1
  store i32 1, ptr %40, align 8, !tbaa !15, !alias.scope !18, !noalias !12
  br label %pred.store.continue35

pred.store.continue35:                            ; preds = %pred.store.if34, %pred.store.continue33
  %41 = extractelement <4 x i1> %21, i64 3
  br i1 %41, label %pred.store.if36, label %pred.store.continue37

pred.store.if36:                                  ; preds = %pred.store.continue35
  %42 = or disjoint i64 %index, 7
  %43 = getelementptr inbounds %struct.Node, ptr %16, i64 %42, i32 1
  store i32 1, ptr %43, align 8, !tbaa !15, !alias.scope !18, !noalias !12
  br label %pred.store.continue37

pred.store.continue37:                            ; preds = %pred.store.if36, %pred.store.continue35
  %index.next = add nuw i64 %index, 8
  %44 = icmp eq i64 %index.next, %n.vec
  br i1 %44, label %middle.block, label %vector.body, !llvm.loop !20

middle.block:                                     ; preds = %pred.store.continue37
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.preheader.us, %middle.block
  %indvars.iv.ph = phi i64 [ 0, %.preheader.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %45 = getelementptr inbounds i8, ptr %15, i64 %indvars.iv.ph
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = icmp eq i8 %46, %2
  br i1 %47, label %48, label %scalar.ph.prol.loopexit.unr-lcssa

48:                                               ; preds = %scalar.ph.prol
  %49 = getelementptr inbounds %struct.Node, ptr %16, i64 %indvars.iv.ph, i32 1
  store i32 1, ptr %49, align 8, !tbaa !15
  br label %scalar.ph.prol.loopexit.unr-lcssa

scalar.ph.prol.loopexit.unr-lcssa:                ; preds = %48, %scalar.ph.prol
  %indvars.iv.next.prol = or disjoint i64 %indvars.iv.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol.loopexit.unr-lcssa, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol.loopexit.unr-lcssa ]
  %50 = icmp eq i64 %indvars.iv.ph, %13
  br i1 %50, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %61
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %61 ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %51 = getelementptr inbounds i8, ptr %15, i64 %indvars.iv
  %52 = load i8, ptr %51, align 1, !tbaa !11
  %53 = icmp eq i8 %52, %2
  br i1 %53, label %54, label %scalar.ph.1

54:                                               ; preds = %scalar.ph
  %55 = getelementptr inbounds %struct.Node, ptr %16, i64 %indvars.iv, i32 1
  store i32 1, ptr %55, align 8, !tbaa !15
  br label %scalar.ph.1

scalar.ph.1:                                      ; preds = %54, %scalar.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %56 = getelementptr inbounds i8, ptr %15, i64 %indvars.iv.next
  %57 = load i8, ptr %56, align 1, !tbaa !11
  %58 = icmp eq i8 %57, %2
  br i1 %58, label %59, label %61

59:                                               ; preds = %scalar.ph.1
  %60 = getelementptr inbounds %struct.Node, ptr %16, i64 %indvars.iv.next, i32 1
  store i32 1, ptr %60, align 8, !tbaa !15
  br label %61

61:                                               ; preds = %59, %scalar.ph.1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %5
  br i1 %exitcond.not.1, label %._crit_edge.us, label %scalar.ph, !llvm.loop !24

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %61, %middle.block
  %indvars.iv.next17 = add nuw nsw i64 %indvars.iv16, 1
  %exitcond20.not = icmp eq i64 %indvars.iv.next17, %wide.trip.count19
  br i1 %exitcond20.not, label %._crit_edge13, label %.preheader.us, !llvm.loop !25

._crit_edge13:                                    ; preds = %._crit_edge.us, %3
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: 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, !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 = !{!8, !8, i64 0}
!12 = !{!13}
!13 = distinct !{!13, !14}
!14 = distinct !{!14, !"LVerDomain"}
!15 = !{!16, !7, i64 8}
!16 = !{!"Node", !17, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32}
!17 = !{!"any pointer", !8, i64 0}
!18 = !{!19}
!19 = distinct !{!19, !14}
!20 = distinct !{!20, !21, !22, !23}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = distinct !{!24, !21, !22}
!25 = distinct !{!25, !21}


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