; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 @getNode(ptr dead_on_unwind noalias writable sret(%struct.Node) align 8, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @reverseID(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.Node, align 8
  %8 = alloca %struct.Node, align 8
  %9 = alloca %struct.Node, align 8
  %10 = alloca %struct.Node, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %11 = load i32, ptr @size, align 4, !tbaa !11
  %12 = zext i32 %11 to i64
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sub nsw i32 %13, 1
  store i32 %14, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 40, ptr %8) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %50, %2
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %53

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 40, ptr %9) #3
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !9
  call void @getNode(ptr dead_on_unwind writable sret(%struct.Node) align 8 %9, ptr noundef %20, i32 noundef %21)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %9, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 40, ptr %10) #3
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !9
  call void @getNode(ptr dead_on_unwind writable sret(%struct.Node) align 8 %10, ptr noundef %22, i32 noundef %23)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %10, i64 40, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 40, ptr %10) #3
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 3
  %27 = load i32, ptr %26, align 8, !tbaa !14
  %28 = sext i32 %27 to i64
  %29 = mul nsw i64 %28, %12
  %30 = getelementptr inbounds %struct.Node, ptr %25, i64 %29
  %31 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !16
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.Node, ptr %30, i64 %33
  %35 = getelementptr inbounds %struct.Node, ptr %34, i32 0, i32 7
  store i32 %24, ptr %35, align 8, !tbaa !17
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 3
  %39 = load i32, ptr %38, align 8, !tbaa !14
  %40 = sext i32 %39 to i64
  %41 = mul nsw i64 %40, %12
  %42 = getelementptr inbounds %struct.Node, ptr %37, i64 %41
  %43 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 2
  %44 = load i32, ptr %43, align 4, !tbaa !16
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds %struct.Node, ptr %42, i64 %45
  %47 = getelementptr inbounds %struct.Node, ptr %46, i32 0, i32 7
  store i32 %36, ptr %47, align 8, !tbaa !17
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr %6, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %19
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %5, align 4, !tbaa !9
  br label %15, !llvm.loop !18

53:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 40, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"GridSize", !10, i64 0, !10, i64 4}
!13 = !{i64 0, i64 8, !5, i64 8, i64 4, !9, i64 12, i64 4, !9, i64 16, i64 4, !9, i64 20, i64 4, !9, i64 24, i64 4, !9, i64 28, i64 4, !9, i64 32, i64 4, !9}
!14 = !{!15, !10, i64 16}
!15 = !{!"Node", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!16 = !{!15, !10, i64 12}
!17 = !{!15, !10, i64 32}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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 @getNode(ptr dead_on_unwind noalias writable sret(%struct.Node) align 8, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @reverseID(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.Node, align 8
  %4 = alloca %struct.Node, align 8
  %5 = load i32, ptr @size, align 4, !tbaa !5
  %6 = zext i32 %5 to i64
  %7 = icmp sgt i32 %1, 1
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %.01617 = add nsw i32 %1, -1
  %.sroa.32.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 12
  %.sroa.43.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 16
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %4, i64 12
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %4, i64 16
  br label %8

8:                                                ; preds = %.lr.ph, %8
  %.01619 = phi i32 [ %.01617, %.lr.ph ], [ %.016, %8 ]
  %.018 = phi i32 [ 0, %.lr.ph ], [ %19, %8 ]
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %3) #2
  call void @getNode(ptr dead_on_unwind nonnull writable sret(%struct.Node) align 8 %3, ptr noundef %0, i32 noundef %.018)
  %.sroa.32.0.copyload = load i32, ptr %.sroa.32.0..sroa_idx, align 4, !tbaa !10
  %.sroa.43.0.copyload = load i32, ptr %.sroa.43.0..sroa_idx, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %3) #2
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #2
  call void @getNode(ptr dead_on_unwind nonnull writable sret(%struct.Node) align 8 %4, ptr noundef %0, i32 noundef %.01619)
  %.sroa.3.0.copyload = load i32, ptr %.sroa.3.0..sroa_idx, align 4, !tbaa !10
  %.sroa.4.0.copyload = load i32, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #2
  %9 = sext i32 %.sroa.43.0.copyload to i64
  %10 = mul nsw i64 %9, %6
  %11 = getelementptr inbounds %struct.Node, ptr %0, i64 %10
  %12 = sext i32 %.sroa.32.0.copyload to i64
  %13 = getelementptr inbounds %struct.Node, ptr %11, i64 %12, i32 7
  store i32 %.01619, ptr %13, align 8, !tbaa !11
  %14 = sext i32 %.sroa.4.0.copyload to i64
  %15 = mul nsw i64 %14, %6
  %16 = getelementptr inbounds %struct.Node, ptr %0, i64 %15
  %17 = sext i32 %.sroa.3.0.copyload to i64
  %18 = getelementptr inbounds %struct.Node, ptr %16, i64 %17, i32 7
  store i32 %.018, ptr %18, align 8, !tbaa !11
  %19 = add nuw nsw i32 %.018, 1
  %.016 = add nsw i32 %.01619, -1
  %20 = icmp slt i32 %19, %.016
  br i1 %20, label %8, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %8, %2
  ret void
}

attributes #0 = { mustprogress 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, !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 = !{!7, !7, i64 0}
!11 = !{!12, !7, i64 32}
!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 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass