; LLVM IR from ihucos/plash :: tests/C (pl_parse_subid)

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

@pl_array = external dso_local global ptr, align 8
@pl_array_size = external dso_local global i64, align 8
@.str.48 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @pl_fatal(ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
define dso_local void @pl_array_add(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr @pl_array, align 8, !tbaa !5
  %4 = load i64, ptr @pl_array_size, align 8, !tbaa !9
  %5 = add i64 %4, 1
  %6 = mul i64 %5, 8
  %7 = call ptr @realloc(ptr noundef %3, i64 noundef %6) #2
  store ptr %7, ptr @pl_array, align 8, !tbaa !5
  %8 = load ptr, ptr @pl_array, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %1
  %11 = call i32 (ptr, ...) @pl_fatal(ptr noundef @.str.48)
  br label %12

12:                                               ; preds = %10, %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = load ptr, ptr @pl_array, align 8, !tbaa !5
  %15 = load i64, ptr @pl_array_size, align 8, !tbaa !9
  %16 = add i64 %15, 1
  store i64 %16, ptr @pl_array_size, align 8, !tbaa !9
  %17 = getelementptr inbounds ptr, ptr %14, i64 %15
  store ptr %13, ptr %17, align 8, !tbaa !5
  ret void
}

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #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 = { 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 #2 = { 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 = !{!"long", !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"

@pl_array = external dso_local local_unnamed_addr global ptr, align 8
@pl_array_size = external dso_local local_unnamed_addr global i64, align 8
@.str.48 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @pl_fatal(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @pl_array_add(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @pl_array, align 8, !tbaa !5
  %3 = load i64, ptr @pl_array_size, align 8, !tbaa !9
  %4 = shl i64 %3, 3
  %5 = add i64 %4, 8
  %6 = tail call ptr @realloc(ptr noundef %2, i64 noundef %5) #2
  store ptr %6, ptr @pl_array, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %10

8:                                                ; preds = %1
  %9 = tail call i32 (ptr, ...) @pl_fatal(ptr noundef nonnull @.str.48)
  %.pre = load ptr, ptr @pl_array, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %8, %1
  %11 = phi ptr [ %.pre, %8 ], [ %6, %1 ]
  %12 = load i64, ptr @pl_array_size, align 8, !tbaa !9
  %13 = add i64 %12, 1
  store i64 %13, ptr @pl_array_size, align 8, !tbaa !9
  %14 = getelementptr inbounds ptr, ptr %11, i64 %12
  store ptr %0, ptr %14, align 8, !tbaa !5
  ret void
}

; 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 #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 = { 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 #2 = { 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 = !{!"long", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass