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

11:                                               ; preds = %46, %2
  %12 = load i32, ptr %5, align 4, !tbaa !12
  %13 = load i32, ptr getelementptr inbounds (%struct.GridSize, ptr @size, i32 0, i32 1), align 4, !tbaa !13
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %49

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

16:                                               ; preds = %42, %15
  %17 = load i32, ptr %6, align 4, !tbaa !12
  %18 = load i32, ptr @size, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %45

20:                                               ; preds = %16
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !12
  %23 = sext i32 %22 to i64
  %24 = mul nsw i64 %23, %10
  %25 = getelementptr inbounds %struct.Node, ptr %21, i64 %24
  %26 = load i32, ptr %6, align 4, !tbaa !12
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.Node, ptr %25, i64 %27
  %29 = getelementptr inbounds %struct.Node, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 8, !tbaa !14
  %31 = icmp eq i32 %30, 1
  br i1 %31, label %32, label %41

32:                                               ; preds = %20
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !12
  %35 = sext i32 %34 to i64
  %36 = mul nsw i64 %35, %8
  %37 = getelementptr inbounds i8, ptr %33, i64 %36
  %38 = load i32, ptr %6, align 4, !tbaa !12
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  store i8 32, ptr %40, align 1, !tbaa !16
  br label %41

41:                                               ; preds = %32, %20
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %6, align 4, !tbaa !12
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %6, align 4, !tbaa !12
  br label %16, !llvm.loop !17

45:                                               ; preds = %16
  br label %46

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

49:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #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 = !{!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 8}
!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 = !{!7, !7, i64 0}
!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 @insertPath(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @size, align 4, !tbaa !5
  %4 = zext i32 %3 to i64
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @size, i64 4), align 4, !tbaa !10
  %6 = icmp sgt i32 %5, 0
  %7 = icmp sgt i32 %3, 0
  %or.cond = select i1 %6, i1 %7, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge12

.preheader:                                       ; preds = %2, %._crit_edge
  %8 = phi i32 [ %26, %._crit_edge ], [ %5, %2 ]
  %9 = phi i32 [ %27, %._crit_edge ], [ %3, %2 ]
  %10 = phi i32 [ %28, %._crit_edge ], [ %3, %2 ]
  %indvars.iv15 = phi i64 [ %indvars.iv.next16, %._crit_edge ], [ 0, %2 ]
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %12 = mul nuw nsw i64 %indvars.iv15, %4
  %13 = getelementptr inbounds %struct.Node, ptr %1, i64 %12
  %14 = getelementptr inbounds i8, ptr %0, i64 %12
  br label %15

15:                                               ; preds = %.lr.ph, %22
  %16 = phi i32 [ %9, %.lr.ph ], [ %23, %22 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %17 = getelementptr inbounds %struct.Node, ptr %13, i64 %indvars.iv, i32 1
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %22

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %14, i64 %indvars.iv
  store i8 32, ptr %21, align 1, !tbaa !14
  %.pre = load i32, ptr @size, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %15, %20
  %23 = phi i32 [ %16, %15 ], [ %.pre, %20 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next, %24
  br i1 %25, label %15, label %._crit_edge.loopexit, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %22
  %.pre18 = 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
  %26 = phi i32 [ %.pre18, %._crit_edge.loopexit ], [ %8, %.preheader ]
  %27 = phi i32 [ %23, %._crit_edge.loopexit ], [ %9, %.preheader ]
  %28 = phi i32 [ %23, %._crit_edge.loopexit ], [ %10, %.preheader ]
  %indvars.iv.next16 = add nuw nsw i64 %indvars.iv15, 1
  %29 = sext i32 %26 to i64
  %30 = icmp slt i64 %indvars.iv.next16, %29
  br i1 %30, label %.preheader, label %._crit_edge12, !llvm.loop !17

._crit_edge12:                                    ; preds = %._crit_edge, %2
  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 = !{!12, !7, i64 8}
!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 = !{!8, !8, i64 0}
!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,PostOrderFunctionAttrsPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass