; 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
declare dso_local void @clearNode(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @removeListNode(ptr noundef %0, ptr noundef %1, ptr noundef byval(%struct.Node) align 8 %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load i32, ptr @size, align 4, !tbaa !9
  %9 = zext i32 %8 to i64
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %10 = getelementptr inbounds %struct.Node, ptr %2, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %91

13:                                               ; preds = %3
  %14 = getelementptr inbounds %struct.Node, ptr %2, i32 0, i32 7
  %15 = load i32, ptr %14, align 8, !tbaa !14
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i32, ptr %16, align 4, !tbaa !15
  %18 = sub nsw i32 %17, 1
  %19 = icmp ne i32 %15, %18
  br i1 %19, label %20, label %65

20:                                               ; preds = %13
  store i32 0, ptr %6, align 4, !tbaa !15
  br label %21

21:                                               ; preds = %61, %20
  %22 = load i32, ptr %6, align 4, !tbaa !15
  %23 = load i32, ptr getelementptr inbounds (%struct.GridSize, ptr @size, i32 0, i32 1), align 4, !tbaa !16
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %64

25:                                               ; preds = %21
  store i32 0, ptr %7, align 4, !tbaa !15
  br label %26

26:                                               ; preds = %57, %25
  %27 = load i32, ptr %7, align 4, !tbaa !15
  %28 = load i32, ptr @size, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %60

30:                                               ; preds = %26
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i32, ptr %6, align 4, !tbaa !15
  %33 = sext i32 %32 to i64
  %34 = mul nsw i64 %33, %9
  %35 = getelementptr inbounds %struct.Node, ptr %31, i64 %34
  %36 = load i32, ptr %7, align 4, !tbaa !15
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds %struct.Node, ptr %35, i64 %37
  %39 = getelementptr inbounds %struct.Node, ptr %38, i32 0, i32 7
  %40 = load i32, ptr %39, align 8, !tbaa !14
  %41 = getelementptr inbounds %struct.Node, ptr %2, i32 0, i32 7
  %42 = load i32, ptr %41, align 8, !tbaa !14
  %43 = icmp sgt i32 %40, %42
  br i1 %43, label %44, label %56

44:                                               ; preds = %30
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %6, align 4, !tbaa !15
  %47 = sext i32 %46 to i64
  %48 = mul nsw i64 %47, %9
  %49 = getelementptr inbounds %struct.Node, ptr %45, i64 %48
  %50 = load i32, ptr %7, align 4, !tbaa !15
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds %struct.Node, ptr %49, i64 %51
  %53 = getelementptr inbounds %struct.Node, ptr %52, i32 0, i32 7
  %54 = load i32, ptr %53, align 8, !tbaa !14
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr %53, align 8, !tbaa !14
  br label %56

56:                                               ; preds = %44, %30
  br label %57

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

60:                                               ; preds = %26
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %6, align 4, !tbaa !15
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %6, align 4, !tbaa !15
  br label %21, !llvm.loop !19

64:                                               ; preds = %21
  br label %65

65:                                               ; preds = %64, %13
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.Node, ptr %2, i32 0, i32 3
  %68 = load i32, ptr %67, align 8, !tbaa !20
  %69 = sext i32 %68 to i64
  %70 = mul nsw i64 %69, %9
  %71 = getelementptr inbounds %struct.Node, ptr %66, i64 %70
  %72 = getelementptr inbounds %struct.Node, ptr %2, i32 0, i32 2
  %73 = load i32, ptr %72, align 4, !tbaa !21
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds %struct.Node, ptr %71, i64 %74
  call void @clearNode(ptr noundef %75)
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.Node, ptr %2, i32 0, i32 3
  %78 = load i32, ptr %77, align 8, !tbaa !20
  %79 = sext i32 %78 to i64
  %80 = mul nsw i64 %79, %9
  %81 = getelementptr inbounds %struct.Node, ptr %76, i64 %80
  %82 = getelementptr inbounds %struct.Node, ptr %2, i32 0, i32 2
  %83 = load i32, ptr %82, align 4, !tbaa !21
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds %struct.Node, ptr %81, i64 %84
  %86 = getelementptr inbounds %struct.Node, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !22
  call void @free(ptr noundef %87) #3
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = load i32, ptr %88, align 4, !tbaa !15
  %90 = add nsw i32 %89, -1
  store i32 %90, ptr %88, align 4, !tbaa !15
  br label %91

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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 "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 #3 = { 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 = !{!13, !11, i64 8}
!13 = !{!"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}
!14 = !{!13, !11, i64 32}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !11, i64 4}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{!13, !11, i64 16}
!21 = !{!13, !11, i64 12}
!22 = !{!13, !6, i64 0}


; 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
declare dso_local void @clearNode(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @removeListNode(ptr noundef %0, ptr nocapture noundef %1, ptr nocapture noundef readonly byval(%struct.Node) align 8 %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @size, align 4, !tbaa !5
  %5 = zext i32 %4 to i64
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !10
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %49

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %2, i64 32
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = load i32, ptr %1, align 4, !tbaa !14
  %13 = add nsw i32 %12, -1
  %.not = icmp eq i32 %11, %13
  br i1 %.not, label %.loopexit, label %.preheader15

.preheader15:                                     ; preds = %9
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @size, i64 4), align 4, !tbaa !15
  %15 = icmp sgt i32 %14, 0
  %16 = icmp sgt i32 %4, 0
  %or.cond = select i1 %15, i1 %16, i1 false
  br i1 %or.cond, label %.preheader.us.preheader, label %.loopexit

.preheader.us.preheader:                          ; preds = %.preheader15
  %wide.trip.count23 = zext nneg i32 %14 to i64
  %xtraiter = and i64 %5, 1
  %17 = icmp eq i32 %4, 1
  %unroll_iter = and i64 %5, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv20 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next21, %._crit_edge.us ]
  %18 = mul nuw nsw i64 %indvars.iv20, %5
  %19 = getelementptr inbounds %struct.Node, ptr %0, i64 %18
  br i1 %17, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %31
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %31 ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %31 ], [ 0, %.preheader.us ]
  %20 = getelementptr inbounds %struct.Node, ptr %19, i64 %indvars.iv, i32 7
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = icmp sgt i32 %21, %11
  br i1 %22, label %23, label %25

23:                                               ; preds = %.preheader.us.new
  %24 = add nsw i32 %21, -1
  store i32 %24, ptr %20, align 8, !tbaa !13
  br label %25

25:                                               ; preds = %23, %.preheader.us.new
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %26 = getelementptr inbounds %struct.Node, ptr %19, i64 %indvars.iv.next, i32 7
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = icmp sgt i32 %27, %11
  br i1 %28, label %29, label %31

29:                                               ; preds = %25
  %30 = add nsw i32 %27, -1
  store i32 %30, ptr %26, align 8, !tbaa !13
  br label %31

31:                                               ; preds = %29, %25
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !16

._crit_edge.us.unr-lcssa:                         ; preds = %31, %.preheader.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.1, %31 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa
  %32 = getelementptr inbounds %struct.Node, ptr %19, i64 %indvars.iv.unr, i32 7
  %33 = load i32, ptr %32, align 8, !tbaa !13
  %34 = icmp sgt i32 %33, %11
  br i1 %34, label %35, label %._crit_edge.us

35:                                               ; preds = %.epil.preheader
  %36 = add nsw i32 %33, -1
  store i32 %36, ptr %32, align 8, !tbaa !13
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %.epil.preheader, %35, %._crit_edge.us.unr-lcssa
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %exitcond24.not = icmp eq i64 %indvars.iv.next21, %wide.trip.count23
  br i1 %exitcond24.not, label %.loopexit, label %.preheader.us, !llvm.loop !18

.loopexit:                                        ; preds = %._crit_edge.us, %.preheader15, %9
  %37 = getelementptr inbounds i8, ptr %2, i64 16
  %38 = load i32, ptr %37, align 8, !tbaa !19
  %39 = sext i32 %38 to i64
  %40 = mul nsw i64 %39, %5
  %41 = getelementptr inbounds %struct.Node, ptr %0, i64 %40
  %42 = getelementptr inbounds i8, ptr %2, i64 12
  %43 = load i32, ptr %42, align 4, !tbaa !20
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.Node, ptr %41, i64 %44
  tail call void @clearNode(ptr noundef %45)
  %46 = load ptr, ptr %45, align 8, !tbaa !21
  tail call void @free(ptr noundef %46) #2
  %47 = load i32, ptr %1, align 4, !tbaa !14
  %48 = add nsw i32 %47, -1
  store i32 %48, ptr %1, align 4, !tbaa !14
  br label %49

49:                                               ; preds = %.loopexit, %3
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

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" }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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, !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 = !{!11, !7, i64 8}
!11 = !{!"Node", !12, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!11, !7, i64 32}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !7, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = !{!11, !7, i64 16}
!20 = !{!11, !7, i64 12}
!21 = !{!11, !12, i64 0}


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