; LLVM IR from ponylang/ponyc :: src/libponyc/ast (source)

; 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.source_t = type { ptr, ptr, i64 }

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @source_open(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  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) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call noalias ptr @fopen(ptr noundef %11, ptr noundef @.str)
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %17

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr @.str.1, ptr %16, align 8, !tbaa !5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %76

17:                                               ; preds = %2
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = call i32 @fseek(ptr noundef %18, i64 noundef 0, i32 noundef 2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call i64 @ftell(ptr noundef %20)
  store i64 %21, ptr %8, align 8, !tbaa !9
  %22 = load i64, ptr %8, align 8, !tbaa !9
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %24, label %28

24:                                               ; preds = %17
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr @.str.2, ptr %25, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = call i32 @fclose(ptr noundef %26)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %75

28:                                               ; preds = %17
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = call i32 @fseek(ptr noundef %29, i64 noundef 0, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %31 = call noalias ptr @ponyint_pool_alloc(i64 noundef 0)
  store ptr %31, ptr %9, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = call ptr @stringtab(ptr noundef %32)
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.source_t, ptr %34, i32 0, i32 0
  store ptr %33, ptr %35, align 8, !tbaa !11
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = add nsw i64 %36, 1
  %38 = call noalias ptr @ponyint_pool_alloc_size(i64 noundef %37)
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.source_t, ptr %39, i32 0, i32 1
  store ptr %38, ptr %40, align 8, !tbaa !13
  %41 = load i64, ptr %8, align 8, !tbaa !9
  %42 = add nsw i64 %41, 1
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.source_t, ptr %43, i32 0, i32 2
  store i64 %42, ptr %44, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.source_t, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = call i64 @fread(ptr noundef %47, i64 noundef 1, i64 noundef %48, ptr noundef %49)
  store i64 %50, ptr %10, align 8, !tbaa !9
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.source_t, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = getelementptr inbounds i8, ptr %53, i64 %54
  store i8 0, ptr %55, align 1, !tbaa !15
  %56 = load i64, ptr %10, align 8, !tbaa !9
  %57 = load i64, ptr %8, align 8, !tbaa !9
  %58 = icmp slt i64 %56, %57
  br i1 %58, label %59, label %70

59:                                               ; preds = %28
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr @.str.3, ptr %60, align 8, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.source_t, ptr %61, i32 0, i32 2
  %63 = load i64, ptr %62, align 8, !tbaa !14
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.source_t, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !13
  call void @ponyint_pool_free_size(i64 noundef %63, ptr noundef %66)
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  call void @ponyint_pool_free(i64 noundef 0, ptr noundef %67)
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = call i32 @fclose(ptr noundef %68)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %74

70:                                               ; preds = %28
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = call i32 @fclose(ptr noundef %71)
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %73, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %74

74:                                               ; preds = %70, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %75

75:                                               ; preds = %74, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %76

76:                                               ; preds = %75, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %77 = load ptr, ptr %3, align 8
  ret ptr %77
}

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

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

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #2

declare i64 @ftell(ptr noundef) #2

declare i32 @fclose(ptr noundef) #2

declare noalias ptr @ponyint_pool_alloc(i64 noundef) #2

declare ptr @stringtab(ptr noundef) #2

declare noalias ptr @ponyint_pool_alloc_size(i64 noundef) #2

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

declare void @ponyint_pool_free_size(i64 noundef, ptr noundef) #2

declare void @ponyint_pool_free(i64 noundef, ptr noundef) #2

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

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

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"source_t", !6, i64 0, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !10, i64 16}
!15 = !{!7, !7, i64 0}


; 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 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @source_open(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str)
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %2
  store ptr @.str.1, ptr %1, align 8, !tbaa !5
  br label %27

6:                                                ; preds = %2
  %7 = tail call i32 @fseek(ptr noundef nonnull %3, i64 noundef 0, i32 noundef 2)
  %8 = tail call i64 @ftell(ptr noundef nonnull %3)
  %9 = icmp slt i64 %8, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %6
  store ptr @.str.2, ptr %1, align 8, !tbaa !5
  %11 = tail call i32 @fclose(ptr noundef nonnull %3)
  br label %27

12:                                               ; preds = %6
  %13 = tail call i32 @fseek(ptr noundef nonnull %3, i64 noundef 0, i32 noundef 0)
  %14 = tail call noalias ptr @ponyint_pool_alloc(i64 noundef 0) #3
  %15 = tail call ptr @stringtab(ptr noundef %0) #3
  store ptr %15, ptr %14, align 8, !tbaa !9
  %16 = add nuw nsw i64 %8, 1
  %17 = tail call noalias ptr @ponyint_pool_alloc_size(i64 noundef %16) #3
  %18 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr %17, ptr %18, align 8, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %14, i64 16
  store i64 %16, ptr %19, align 8, !tbaa !13
  %20 = tail call i64 @fread(ptr noundef %17, i64 noundef 1, i64 noundef %8, ptr noundef nonnull %3)
  %21 = getelementptr inbounds i8, ptr %17, i64 %8
  store i8 0, ptr %21, align 1, !tbaa !14
  %22 = icmp slt i64 %20, %8
  br i1 %22, label %23, label %25

23:                                               ; preds = %12
  store ptr @.str.3, ptr %1, align 8, !tbaa !5
  tail call void @ponyint_pool_free_size(i64 noundef %16, ptr noundef nonnull %17) #3
  tail call void @ponyint_pool_free(i64 noundef 0, ptr noundef nonnull %14) #3
  %24 = tail call i32 @fclose(ptr noundef nonnull %3)
  br label %27

25:                                               ; preds = %12
  %26 = tail call i32 @fclose(ptr noundef nonnull %3)
  br label %27

27:                                               ; preds = %10, %25, %23, %5
  %.2 = phi ptr [ null, %5 ], [ null, %10 ], [ null, %23 ], [ %14, %25 ]
  ret ptr %.2
}

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

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

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

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

declare noalias ptr @ponyint_pool_alloc(i64 noundef) local_unnamed_addr #2

declare ptr @stringtab(ptr noundef) local_unnamed_addr #2

declare noalias ptr @ponyint_pool_alloc_size(i64 noundef) local_unnamed_addr #2

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

declare void @ponyint_pool_free_size(i64 noundef, ptr noundef) local_unnamed_addr #2

declare void @ponyint_pool_free(i64 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 = { "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 }

!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, !6, i64 0}
!10 = !{!"source_t", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !11, i64 16}
!14 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass