; 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
@__const.writeFile.insert = external hidden unnamed_addr constant [9 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [2 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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

; 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) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nounwind uwtable
define dso_local void @writeFile(ptr noundef %0, ptr noundef %1) #4 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca [9 x i8], align 1
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load i32, ptr @size, align 4, !tbaa !9
  %12 = zext i32 %11 to i64
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 9, ptr %8) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %8, ptr align 1 @__const.writeFile.insert, i64 9, i1 false)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #7
  %15 = getelementptr inbounds [9 x i8], ptr %8, i64 0, i64 0
  %16 = call i64 @strlen(ptr noundef %15) #7
  %17 = add i64 %14, %16
  %18 = call ptr @llvm.stacksave.p0()
  store ptr %18, ptr %9, align 8
  %19 = alloca i8, i64 %17, align 16
  store i64 %17, ptr %10, align 8
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds [9 x i8], ptr %8, i64 0, i64 0
  call void @appendName(ptr noundef %20, ptr noundef %21, ptr noundef %19)
  %22 = call noalias ptr @fopen(ptr noundef %19, ptr noundef @.str.8)
  store ptr %22, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %23

23:                                               ; preds = %51, %2
  %24 = load i32, ptr %5, align 4, !tbaa !12
  %25 = load i32, ptr getelementptr inbounds (%struct.GridSize, ptr @size, i32 0, i32 1), align 4, !tbaa !13
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %54

27:                                               ; preds = %23
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %28

28:                                               ; preds = %45, %27
  %29 = load i32, ptr %6, align 4, !tbaa !12
  %30 = load i32, ptr @size, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %48

32:                                               ; preds = %28
  %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, %12
  %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
  %41 = load i8, ptr %40, align 1, !tbaa !14
  %42 = sext i8 %41 to i32
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = call i32 @fputc(i32 noundef %42, ptr noundef %43)
  br label %45

45:                                               ; preds = %32
  %46 = load i32, ptr %6, align 4, !tbaa !12
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %6, align 4, !tbaa !12
  br label %28, !llvm.loop !15

48:                                               ; preds = %28
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = call i32 @fputc(i32 noundef 10, ptr noundef %49)
  br label %51

51:                                               ; preds = %48
  %52 = load i32, ptr %5, align 4, !tbaa !12
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %5, align 4, !tbaa !12
  br label %23, !llvm.loop !17

54:                                               ; preds = %23
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = call i32 @fclose(ptr noundef %55)
  %57 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %57)
  call void @llvm.lifetime.end.p0(i64 9, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local void @appendName(ptr noundef, ptr noundef, ptr noundef) #4

declare i32 @fputc(i32 noundef, ptr noundef) #1

declare i32 @fclose(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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 #5 = { nounwind willreturn memory(read) "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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 = !{!7, !7, i64 0}
!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
@__const.writeFile.insert = external hidden unnamed_addr constant [9 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [2 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: mustprogress 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) #2

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nounwind uwtable
define dso_local void @writeFile(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #4 {
  %3 = alloca [9 x i8], align 1
  %4 = load i32, ptr @size, align 4, !tbaa !5
  %5 = zext i32 %4 to i64
  call void @llvm.lifetime.start.p0(i64 9, ptr nonnull %3) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(9) %3, ptr noundef nonnull align 1 dereferenceable(9) @__const.writeFile.insert, i64 9, i1 false)
  %6 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #7
  %7 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #7
  %8 = add i64 %7, %6
  %9 = tail call ptr @llvm.stacksave.p0()
  %10 = alloca i8, i64 %8, align 16
  call void @appendName(ptr noundef %1, ptr noundef nonnull %3, ptr noundef nonnull %10)
  %11 = call noalias ptr @fopen(ptr noundef nonnull %10, ptr noundef nonnull @.str.8)
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @size, i64 4), align 4, !tbaa !10
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.preheader, label %._crit_edge15

.preheader:                                       ; preds = %2, %._crit_edge
  %indvars.iv17 = phi i64 [ %indvars.iv.next18, %._crit_edge ], [ 0, %2 ]
  %14 = load i32, ptr @size, align 4, !tbaa !5
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %16 = mul nuw nsw i64 %indvars.iv17, %5
  %17 = getelementptr inbounds i8, ptr %0, i64 %16
  br label %18

18:                                               ; preds = %.lr.ph, %18
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %18 ]
  %19 = getelementptr inbounds i8, ptr %17, i64 %indvars.iv
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = sext i8 %20 to i32
  %22 = call i32 @fputc(i32 noundef %21, ptr noundef %11)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %23 = load i32, ptr @size, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next, %24
  br i1 %25, label %18, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %18, %.preheader
  %26 = call i32 @fputc(i32 noundef 10, ptr noundef %11)
  %indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 1
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @size, i64 4), align 4, !tbaa !10
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %indvars.iv.next18, %28
  br i1 %29, label %.preheader, label %._crit_edge15, !llvm.loop !14

._crit_edge15:                                    ; preds = %._crit_edge, %2
  %30 = call i32 @fclose(ptr noundef %11)
  call void @llvm.stackrestore.p0(ptr %9)
  call void @llvm.lifetime.end.p0(i64 9, ptr nonnull %3) #6
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare dso_local void @appendName(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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 #5 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

!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,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass