; LLVM IR from DevonCrawford/A-Pathfinding-in-C-command-line :: backups (pathfinding_copy2)

; 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 }

@size = external dso_local global %struct.GridSize, align 4
@.str.13 = external hidden unnamed_addr constant [48 x i8], align 1

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

13:                                               ; preds = %59, %2
  %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 %62

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

18:                                               ; preds = %55, %17
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = call i32 @fgetc(ptr noundef %19)
  %21 = trunc i32 %20 to i8
  store i8 %21, ptr %6, align 1, !tbaa !12
  %22 = sext i8 %21 to i32
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %33

24:                                               ; preds = %18
  %25 = load i32, ptr %8, align 4, !tbaa !13
  %26 = load i32, ptr @size, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %33

28:                                               ; preds = %24
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = call i32 @feof(ptr noundef %29) #4
  %31 = icmp ne i32 %30, 0
  %32 = xor i1 %31, true
  br label %33

33:                                               ; preds = %28, %24, %18
  %34 = phi i1 [ false, %24 ], [ false, %18 ], [ %32, %28 ]
  br i1 %34, label %35, label %58

35:                                               ; preds = %33
  %36 = load i8, ptr %6, align 1, !tbaa !12
  %37 = sext i8 %36 to i32
  %38 = icmp eq i32 %37, 10
  br i1 %38, label %39, label %45

39:                                               ; preds = %35
  %40 = load i32, ptr %8, align 4, !tbaa !13
  %41 = add nsw i32 %40, 1
  %42 = load i32, ptr %7, align 4, !tbaa !13
  %43 = add nsw i32 %42, 1
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.13, i32 noundef %41, i32 noundef %43)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %63

45:                                               ; preds = %35
  %46 = load i8, ptr %6, align 1, !tbaa !12
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !13
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %49, %11
  %51 = getelementptr inbounds i8, ptr %47, i64 %50
  %52 = load i32, ptr %8, align 4, !tbaa !13
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  store i8 %46, ptr %54, align 1, !tbaa !12
  br label %55

55:                                               ; preds = %45
  %56 = load i32, ptr %8, align 4, !tbaa !13
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %8, align 4, !tbaa !13
  br label %18, !llvm.loop !15

58:                                               ; preds = %33
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %7, align 4, !tbaa !13
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %7, align 4, !tbaa !13
  br label %13, !llvm.loop !17

62:                                               ; preds = %13
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %63

63:                                               ; preds = %62, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #4
  %64 = load i32, ptr %3, align 4
  ret i32 %64
}

declare i32 @printf(ptr noundef, ...) #2

declare void @rewind(ptr noundef) #2

declare i32 @fgetc(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @feof(ptr noundef) #3

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 = { "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 "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 #4 = { 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 = !{!7, !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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 }

@size = external dso_local local_unnamed_addr global %struct.GridSize, align 4
@.str.13 = external hidden unnamed_addr constant [48 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local range(i32 0, 2) i32 @readFile(ptr nocapture noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @size, align 4, !tbaa !5
  %4 = zext i32 %3 to i64
  tail call void @rewind(ptr noundef %0)
  %5 = load i32, ptr getelementptr inbounds (i8, ptr @size, i64 4), align 4, !tbaa !10
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %2, %.critedge
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %.critedge ], [ 0, %2 ]
  %7 = tail call i32 @fgetc(ptr noundef %0)
  %sext21 = shl i32 %7, 24
  %.not22 = icmp ne i32 %sext21, 0
  %8 = load i32, ptr @size, align 4
  %9 = icmp sgt i32 %8, 0
  %or.cond23 = select i1 %.not22, i1 %9, i1 false
  br i1 %or.cond23, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.preheader
  %10 = mul nuw nsw i64 %indvars.iv31, %4
  %11 = getelementptr inbounds i8, ptr %1, i64 %10
  br label %12

12:                                               ; preds = %.lr.ph, %23
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %23 ]
  %sext25 = phi i32 [ %sext21, %.lr.ph ], [ %sext, %23 ]
  %.in = phi i32 [ %7, %.lr.ph ], [ %25, %23 ]
  %13 = trunc i32 %.in to i8
  %14 = tail call i32 @feof(ptr noundef %0) #2
  %.not17 = icmp eq i32 %14, 0
  br i1 %.not17, label %15, label %.critedge

15:                                               ; preds = %12
  %16 = icmp eq i32 %sext25, 167772160
  br i1 %16, label %17, label %23

17:                                               ; preds = %15
  %18 = trunc nuw nsw i64 %indvars.iv31 to i32
  %19 = trunc nuw nsw i64 %indvars.iv to i32
  %20 = add nuw nsw i32 %19, 1
  %21 = add nuw nsw i32 %18, 1
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.13, i32 noundef %20, i32 noundef %21)
  br label %.loopexit

23:                                               ; preds = %15
  %24 = getelementptr inbounds i8, ptr %11, i64 %indvars.iv
  store i8 %13, ptr %24, align 1, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = tail call i32 @fgetc(ptr noundef %0)
  %sext = shl i32 %25, 24
  %.not = icmp ne i32 %sext, 0
  %26 = load i32, ptr @size, align 4
  %27 = sext i32 %26 to i64
  %28 = icmp slt i64 %indvars.iv.next, %27
  %or.cond = select i1 %.not, i1 %28, i1 false
  br i1 %or.cond, label %12, label %.critedge, !llvm.loop !12

.critedge:                                        ; preds = %23, %12, %.preheader
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @size, i64 4), align 4, !tbaa !10
  %30 = sext i32 %29 to i64
  %31 = icmp slt i64 %indvars.iv.next32, %30
  br i1 %31, label %.preheader, label %.loopexit, !llvm.loop !14

.loopexit:                                        ; preds = %.critedge, %2, %17
  %.015 = phi i32 [ 1, %17 ], [ 0, %2 ], [ 0, %.critedge ]
  ret i32 %.015
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare void @rewind(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fgetc(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @feof(ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { nofree 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 = { nofree 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 #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 = !{!6, !7, i64 4}
!11 = !{!8, !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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