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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @getGridSize(ptr noundef %0) #1 {
  %2 = alloca %struct.GridSize, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #4
  store i8 0, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !10
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %63

9:                                                ; preds = %1
  store i32 0, ptr %5, align 4, !tbaa !10
  br label %10

10:                                               ; preds = %30, %9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i32 @fgetc(ptr noundef %11)
  %13 = trunc i32 %12 to i8
  store i8 %13, ptr %4, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %27

16:                                               ; preds = %10
  %17 = load i8, ptr %4, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp ne i32 %18, 10
  br i1 %19, label %20, label %25

20:                                               ; preds = %16
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call i32 @feof(ptr noundef %21) #4
  %23 = icmp ne i32 %22, 0
  %24 = xor i1 %23, true
  br label %25

25:                                               ; preds = %20, %16
  %26 = phi i1 [ false, %16 ], [ %24, %20 ]
  br label %27

27:                                               ; preds = %25, %10
  %28 = phi i1 [ false, %10 ], [ %26, %25 ]
  br i1 %28, label %29, label %33

29:                                               ; preds = %27
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %5, align 4, !tbaa !10
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %5, align 4, !tbaa !10
  br label %10, !llvm.loop !12

33:                                               ; preds = %27
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  call void @rewind(ptr noundef %34)
  br label %35

35:                                               ; preds = %55, %33
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = call i32 @fgetc(ptr noundef %36)
  %38 = trunc i32 %37 to i8
  store i8 %38, ptr %4, align 1, !tbaa !9
  %39 = sext i8 %38 to i32
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %46

41:                                               ; preds = %35
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = call i32 @feof(ptr noundef %42) #4
  %44 = icmp ne i32 %43, 0
  %45 = xor i1 %44, true
  br label %46

46:                                               ; preds = %41, %35
  %47 = phi i1 [ false, %35 ], [ %45, %41 ]
  br i1 %47, label %48, label %56

48:                                               ; preds = %46
  %49 = load i8, ptr %4, align 1, !tbaa !9
  %50 = sext i8 %49 to i32
  %51 = icmp eq i32 %50, 10
  br i1 %51, label %52, label %55

52:                                               ; preds = %48
  %53 = load i32, ptr %6, align 4, !tbaa !10
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %6, align 4, !tbaa !10
  br label %55

55:                                               ; preds = %52, %48
  br label %35, !llvm.loop !14

56:                                               ; preds = %46
  %57 = load i32, ptr %5, align 4, !tbaa !10
  %58 = icmp sgt i32 %57, 0
  br i1 %58, label %59, label %62

59:                                               ; preds = %56
  %60 = load i32, ptr %6, align 4, !tbaa !10
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %6, align 4, !tbaa !10
  br label %62

62:                                               ; preds = %59, %56
  br label %63

63:                                               ; preds = %62, %1
  %64 = load i32, ptr %5, align 4, !tbaa !10
  %65 = getelementptr inbounds %struct.GridSize, ptr %2, i32 0, i32 0
  store i32 %64, ptr %65, align 4, !tbaa !15
  %66 = load i32, ptr %6, align 4, !tbaa !10
  %67 = getelementptr inbounds %struct.GridSize, ptr %2, i32 0, i32 1
  store i32 %66, ptr %67, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  %68 = load i64, ptr %2, align 4
  ret i64 %68
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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


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

; Function Attrs: nofree nounwind uwtable
define dso_local i64 @getGridSize(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %18, label %.preheader

.preheader:                                       ; preds = %1, %5
  %.017 = phi i32 [ %6, %5 ], [ 0, %1 ]
  %2 = tail call i32 @fgetc(ptr noundef nonnull %0)
  %trunc = trunc i32 %2 to i8
  switch i8 %trunc, label %3 [
    i8 10, label %.critedge
    i8 0, label %.critedge
  ]

3:                                                ; preds = %.preheader
  %4 = tail call i32 @feof(ptr noundef nonnull %0) #2
  %.not21 = icmp eq i32 %4, 0
  br i1 %.not21, label %5, label %.critedge

5:                                                ; preds = %3
  %6 = add nuw nsw i32 %.017, 1
  br label %.preheader, !llvm.loop !5

.critedge:                                        ; preds = %.preheader, %.preheader, %3
  tail call void @rewind(ptr noundef nonnull %0)
  %7 = tail call i32 @fgetc(ptr noundef nonnull %0)
  %sext2227 = shl i32 %7, 24
  %.not2328 = icmp eq i32 %sext2227, 0
  br i1 %.not2328, label %.critedge2, label %.lr.ph

.lr.ph:                                           ; preds = %.critedge, %9
  %sext2230 = phi i32 [ %sext22, %9 ], [ %sext2227, %.critedge ]
  %.029 = phi i32 [ %spec.select, %9 ], [ 0, %.critedge ]
  %8 = tail call i32 @feof(ptr noundef nonnull %0) #2
  %.not24 = icmp eq i32 %8, 0
  br i1 %.not24, label %9, label %.critedge2

9:                                                ; preds = %.lr.ph
  %10 = icmp eq i32 %sext2230, 167772160
  %11 = zext i1 %10 to i32
  %spec.select = add nuw nsw i32 %.029, %11
  %12 = tail call i32 @fgetc(ptr noundef nonnull %0)
  %sext22 = shl i32 %12, 24
  %.not23 = icmp eq i32 %sext22, 0
  br i1 %.not23, label %.critedge2, label %.lr.ph, !llvm.loop !7

.critedge2:                                       ; preds = %.lr.ph, %9, %.critedge
  %.0.lcssa = phi i32 [ 0, %.critedge ], [ %spec.select, %9 ], [ %.029, %.lr.ph ]
  %.not25 = icmp ne i32 %.017, 0
  %13 = zext i1 %.not25 to i32
  %spec.select26 = add nuw nsw i32 %.0.lcssa, %13
  %14 = zext nneg i32 %spec.select26 to i64
  %15 = shl nuw nsw i64 %14, 32
  %16 = zext nneg i32 %.017 to i64
  %17 = or disjoint i64 %15, %16
  br label %18

18:                                               ; preds = %.critedge2, %1
  %.sroa.0.0.insert.insert = phi i64 [ 0, %1 ], [ %17, %.critedge2 ]
  ret i64 %.sroa.0.0.insert.insert
}

; 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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