; LLVM IR from buzz-lang/Buzz :: src/buzz (buzzdebug)

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

@.str.1 = external hidden unnamed_addr constant [3 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #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
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @buzzdebug_fromfile(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i16, align 2
  %12 = alloca i16, align 2
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call noalias ptr @fopen(ptr noundef %15, ptr noundef @.str.1)
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %97

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #6
  store i16 512, ptr %12, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %21 = load i16, ptr %12, align 2, !tbaa !9
  %22 = zext i16 %21 to i64
  %23 = call noalias ptr @malloc(i64 noundef %22) #7
  store ptr %23, ptr %13, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %86, %20
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = call i32 @feof(ptr noundef %25) #6
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %33, label %28

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

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

35:                                               ; preds = %33
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = call i64 @fread(ptr noundef %8, i64 noundef 4, i64 noundef 1, ptr noundef %36)
  %38 = icmp eq i64 %37, 1
  br i1 %38, label %39, label %86

39:                                               ; preds = %35
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = call i64 @fread(ptr noundef %9, i64 noundef 8, i64 noundef 1, ptr noundef %40)
  %42 = icmp eq i64 %41, 1
  br i1 %42, label %43, label %86

43:                                               ; preds = %39
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = call i64 @fread(ptr noundef %10, i64 noundef 8, i64 noundef 1, ptr noundef %44)
  %46 = icmp eq i64 %45, 1
  br i1 %46, label %47, label %86

47:                                               ; preds = %43
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = call i64 @fread(ptr noundef %11, i64 noundef 2, i64 noundef 1, ptr noundef %48)
  %50 = icmp eq i64 %49, 1
  br i1 %50, label %51, label %86

51:                                               ; preds = %47
  %52 = load i16, ptr %11, align 2, !tbaa !9
  %53 = zext i16 %52 to i32
  %54 = load i16, ptr %12, align 2, !tbaa !9
  %55 = zext i16 %54 to i32
  %56 = icmp sgt i32 %53, %55
  br i1 %56, label %57, label %66

57:                                               ; preds = %51
  %58 = load i16, ptr %11, align 2, !tbaa !9
  %59 = zext i16 %58 to i32
  %60 = add nsw i32 %59, 1
  %61 = trunc i32 %60 to i16
  store i16 %61, ptr %12, align 2, !tbaa !9
  %62 = load ptr, ptr %13, align 8, !tbaa !5
  %63 = load i16, ptr %12, align 2, !tbaa !9
  %64 = zext i16 %63 to i64
  %65 = call ptr @realloc(ptr noundef %62, i64 noundef %64) #8
  store ptr %65, ptr %13, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %57, %51
  %67 = load ptr, ptr %13, align 8, !tbaa !5
  %68 = load i16, ptr %11, align 2, !tbaa !9
  %69 = zext i16 %68 to i64
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = call i64 @fread(ptr noundef %67, i64 noundef 1, i64 noundef %69, ptr noundef %70)
  %72 = load i16, ptr %11, align 2, !tbaa !9
  %73 = zext i16 %72 to i64
  %74 = icmp eq i64 %71, %73
  br i1 %74, label %75, label %85

75:                                               ; preds = %66
  %76 = load ptr, ptr %13, align 8, !tbaa !5
  %77 = load i16, ptr %11, align 2, !tbaa !9
  %78 = zext i16 %77 to i64
  %79 = getelementptr inbounds i8, ptr %76, i64 %78
  store i8 0, ptr %79, align 1, !tbaa !11
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = load i32, ptr %8, align 4, !tbaa !12
  %82 = load i64, ptr %9, align 8, !tbaa !14
  %83 = load i64, ptr %10, align 8, !tbaa !14
  %84 = load ptr, ptr %13, align 8, !tbaa !5
  call void @buzzdebug_info_set(ptr noundef %80, i32 noundef %81, i64 noundef %82, i64 noundef %83, ptr noundef %84)
  br label %85

85:                                               ; preds = %75, %66
  br label %86

86:                                               ; preds = %85, %47, %43, %39, %35
  br label %24, !llvm.loop !16

87:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = call i32 @ferror(ptr noundef %88) #6
  store i32 %89, ptr %14, align 4, !tbaa !12
  %90 = load ptr, ptr %13, align 8, !tbaa !5
  call void @free(ptr noundef %90) #6
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = call i32 @fclose(ptr noundef %91)
  %93 = load i32, ptr %14, align 4, !tbaa !12
  %94 = icmp ne i32 %93, 0
  %95 = zext i1 %94 to i64
  %96 = select i1 %94, i32 0, i32 1
  store i32 %96, ptr %3, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %97

97:                                               ; preds = %87, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %98 = load i32, ptr %3, align 4
  ret i32 %98
}

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

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

; Function Attrs: nounwind
declare i32 @ferror(ptr noundef) #2

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #4

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local void @buzzdebug_info_set(ptr noundef, i32 noundef, i64 noundef, i64 noundef, ptr noundef) #3

declare i32 @fclose(ptr noundef) #4

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

!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 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [3 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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @buzzdebug_fromfile(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #3 {
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i16, align 2
  %7 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.1)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %45, label %8

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #7
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %6) #7
  %9 = tail call noalias dereferenceable_or_null(512) ptr @malloc(i64 noundef 512) #8
  %10 = tail call i32 @feof(ptr noundef nonnull %7) #7
  %.not2831 = icmp eq i32 %10, 0
  br i1 %.not2831, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %8, %40
  %.02133 = phi ptr [ %.2, %40 ], [ %9, %8 ]
  %.02232 = phi i16 [ %.224, %40 ], [ 512, %8 ]
  %11 = tail call i32 @ferror(ptr noundef nonnull %7) #7
  %.not29 = icmp eq i32 %11, 0
  br i1 %.not29, label %12, label %.critedge

12:                                               ; preds = %.lr.ph
  %13 = call i64 @fread(ptr noundef nonnull %3, i64 noundef 4, i64 noundef 1, ptr noundef nonnull %7)
  %14 = icmp eq i64 %13, 1
  br i1 %14, label %15, label %40

15:                                               ; preds = %12
  %16 = call i64 @fread(ptr noundef nonnull %4, i64 noundef 8, i64 noundef 1, ptr noundef nonnull %7)
  %17 = icmp eq i64 %16, 1
  br i1 %17, label %18, label %40

18:                                               ; preds = %15
  %19 = call i64 @fread(ptr noundef nonnull %5, i64 noundef 8, i64 noundef 1, ptr noundef nonnull %7)
  %20 = icmp eq i64 %19, 1
  br i1 %20, label %21, label %40

21:                                               ; preds = %18
  %22 = call i64 @fread(ptr noundef nonnull %6, i64 noundef 2, i64 noundef 1, ptr noundef nonnull %7)
  %23 = icmp eq i64 %22, 1
  br i1 %23, label %24, label %40

24:                                               ; preds = %21
  %25 = load i16, ptr %6, align 2, !tbaa !5
  %26 = icmp ugt i16 %25, %.02232
  br i1 %26, label %27, label %31

27:                                               ; preds = %24
  %28 = add i16 %25, 1
  %29 = zext i16 %28 to i64
  %30 = tail call ptr @realloc(ptr noundef %.02133, i64 noundef %29) #9
  br label %31

31:                                               ; preds = %27, %24
  %.123 = phi i16 [ %28, %27 ], [ %.02232, %24 ]
  %.1 = phi ptr [ %30, %27 ], [ %.02133, %24 ]
  %32 = zext i16 %25 to i64
  %33 = tail call i64 @fread(ptr noundef %.1, i64 noundef 1, i64 noundef %32, ptr noundef nonnull %7)
  %34 = icmp eq i64 %33, %32
  br i1 %34, label %35, label %40

35:                                               ; preds = %31
  %36 = getelementptr inbounds i8, ptr %.1, i64 %32
  store i8 0, ptr %36, align 1, !tbaa !9
  %37 = load i32, ptr %3, align 4, !tbaa !10
  %38 = load i64, ptr %4, align 8, !tbaa !12
  %39 = load i64, ptr %5, align 8, !tbaa !12
  tail call void @buzzdebug_info_set(ptr noundef %0, i32 noundef %37, i64 noundef %38, i64 noundef %39, ptr noundef %.1)
  br label %40

40:                                               ; preds = %31, %35, %21, %18, %15, %12
  %.224 = phi i16 [ %.123, %35 ], [ %.123, %31 ], [ %.02232, %21 ], [ %.02232, %18 ], [ %.02232, %15 ], [ %.02232, %12 ]
  %.2 = phi ptr [ %.1, %35 ], [ %.1, %31 ], [ %.02133, %21 ], [ %.02133, %18 ], [ %.02133, %15 ], [ %.02133, %12 ]
  %41 = tail call i32 @feof(ptr noundef nonnull %7) #7
  %.not28 = icmp eq i32 %41, 0
  br i1 %.not28, label %.lr.ph, label %.critedge, !llvm.loop !14

.critedge:                                        ; preds = %.lr.ph, %40, %8
  %.021.lcssa = phi ptr [ %9, %8 ], [ %.2, %40 ], [ %.02133, %.lr.ph ]
  %42 = tail call i32 @ferror(ptr noundef nonnull %7) #7
  tail call void @free(ptr noundef %.021.lcssa) #7
  %43 = tail call i32 @fclose(ptr noundef nonnull %7)
  %.not30 = icmp eq i32 %42, 0
  %44 = zext i1 %.not30 to i32
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #7
  br label %45

45:                                               ; preds = %2, %.critedge
  %.0 = phi i32 [ %44, %.critedge ], [ 0, %2 ]
  ret i32 %.0
}

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

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

; Function Attrs: nofree nounwind memory(read)
declare noundef i32 @ferror(ptr nocapture noundef) local_unnamed_addr #5

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #6

; Function Attrs: nounwind uwtable
declare dso_local void @buzzdebug_info_set(ptr noundef, i32 noundef, i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 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 #4 = { 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 #5 = { nofree nounwind 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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }
attributes #9 = { nounwind allocsize(1) }

!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 = !{!"short", !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 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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