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

@size = external dso_local global %struct.GridSize, align 4
@.str.7 = 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 = %75, %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 %78

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

18:                                               ; preds = %71, %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 %74

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 %55, label %39

39:                                               ; preds = %35
  %40 = load i8, ptr %6, align 1, !tbaa !12
  %41 = sext i8 %40 to i32
  %42 = icmp ne i32 %41, 35
  br i1 %42, label %43, label %61

43:                                               ; preds = %39
  %44 = load i8, ptr %6, align 1, !tbaa !12
  %45 = sext i8 %44 to i32
  %46 = icmp ne i32 %45, 79
  br i1 %46, label %47, label %61

47:                                               ; preds = %43
  %48 = load i8, ptr %6, align 1, !tbaa !12
  %49 = sext i8 %48 to i32
  %50 = icmp ne i32 %49, 83
  br i1 %50, label %51, label %61

51:                                               ; preds = %47
  %52 = load i8, ptr %6, align 1, !tbaa !12
  %53 = sext i8 %52 to i32
  %54 = icmp ne i32 %53, 71
  br i1 %54, label %55, label %61

55:                                               ; preds = %51, %35
  %56 = load i32, ptr %8, align 4, !tbaa !13
  %57 = add nsw i32 %56, 1
  %58 = load i32, ptr %7, align 4, !tbaa !13
  %59 = add nsw i32 %58, 1
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i32 noundef %57, i32 noundef %59)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %79

61:                                               ; preds = %51, %47, %43, %39
  %62 = load i8, ptr %6, align 1, !tbaa !12
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !13
  %65 = sext i32 %64 to i64
  %66 = mul nsw i64 %65, %11
  %67 = getelementptr inbounds i8, ptr %63, i64 %66
  %68 = load i32, ptr %8, align 4, !tbaa !13
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds i8, ptr %67, i64 %69
  store i8 %62, ptr %70, align 1, !tbaa !12
  br label %71

71:                                               ; preds = %61
  %72 = load i32, ptr %8, align 4, !tbaa !13
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %8, align 4, !tbaa !13
  br label %18, !llvm.loop !15

74:                                               ; preds = %33
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %7, align 4, !tbaa !13
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %7, align 4, !tbaa !13
  br label %13, !llvm.loop !17

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

79:                                               ; preds = %78, %55
  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
  %80 = load i32, ptr %3, align 4
  ret i32 %80
}

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

declare i32 @fgetc(ptr noundef) #2

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

declare void @rewind(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 = { "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.7 = 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.iv44 = phi i64 [ %indvars.iv.next45, %.critedge ], [ 0, %2 ]
  %7 = tail call i32 @fgetc(ptr noundef %0)
  %sext34 = shl i32 %7, 24
  %.not35 = icmp ne i32 %sext34, 0
  %8 = load i32, ptr @size, align 4
  %9 = icmp sgt i32 %8, 0
  %or.cond3136 = select i1 %.not35, i1 %9, i1 false
  br i1 %or.cond3136, label %.lr.ph, label %.critedge

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

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

15:                                               ; preds = %12
  switch i32 %sext38, label %16 [
    i32 587202560, label %22
    i32 1392508928, label %22
    i32 1325400064, label %22
    i32 1191182336, label %22
  ]

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

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

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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

; Function Attrs: nofree nounwind
declare void @rewind(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