; LLVM IR from krig/LISP :: komplott (gc_alloc)

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

@stderr = external global ptr, align 8
@fromspace = external dso_local global ptr, align 8
@allocptr = external dso_local global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @gc_alloc(i32 noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  %7 = load ptr, ptr @allocptr, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.object_t, ptr %7, i64 1
  %9 = load ptr, ptr @fromspace, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.object_t, ptr %9, i64 16384
  %11 = icmp ugt ptr %8, %10
  br i1 %11, label %12, label %21

12:                                               ; preds = %3
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  call void (ptr, ...) @gc_protect(ptr noundef %5, ptr noundef %6, ptr noundef null)
  br label %16

16:                                               ; preds = %15, %12
  call void @gc_collect()
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  call void @gc_pop()
  br label %20

20:                                               ; preds = %19, %16
  br label %21

21:                                               ; preds = %20, %3
  %22 = load ptr, ptr @allocptr, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.object_t, ptr %22, i64 1
  %24 = load ptr, ptr @fromspace, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.object_t, ptr %24, i64 16384
  %26 = icmp ugt ptr %23, %25
  br i1 %26, label %27, label %30

27:                                               ; preds = %21
  %28 = load ptr, ptr @stderr, align 8, !tbaa !9
  %29 = call i32 @fputs(ptr noundef @.str.11, ptr noundef %28)
  call void @abort() #3
  unreachable

30:                                               ; preds = %21
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = load ptr, ptr @allocptr, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.object_t, ptr %32, i32 0, i32 2
  store i32 %31, ptr %33, align 8, !tbaa !11
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = load ptr, ptr @allocptr, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.object_t, ptr %35, i32 0, i32 0
  store ptr %34, ptr %36, align 8, !tbaa !13
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  %38 = load ptr, ptr @allocptr, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.object_t, ptr %38, i32 0, i32 1
  store ptr %37, ptr %39, align 8, !tbaa !14
  %40 = load ptr, ptr @allocptr, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.object_t, ptr %40, i32 1
  store ptr %41, ptr @allocptr, align 8, !tbaa !9
  ret ptr %40
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @gc_pop() #0

; Function Attrs: noreturn nounwind
declare void @abort() #1

declare i32 @fputs(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @gc_collect() #0

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 = { noreturn 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 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"object_t", !10, i64 0, !10, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 8}


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

@stderr = external local_unnamed_addr global ptr, align 8
@fromspace = external dso_local local_unnamed_addr global ptr, align 8
@allocptr = external dso_local local_unnamed_addr global ptr, align 8
@.str.11 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @gc_alloc(i32 noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  store ptr %2, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr @allocptr, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  %8 = load ptr, ptr @fromspace, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 393216
  %10 = icmp ugt ptr %7, %9
  br i1 %10, label %11, label %14

11:                                               ; preds = %3
  %12 = icmp eq i32 %0, 0
  br i1 %12, label %13, label %.critedge

13:                                               ; preds = %11
  call void (ptr, ...) @gc_protect(ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef null)
  call void @gc_collect()
  call void @gc_pop()
  br label %14

.critedge:                                        ; preds = %11
  tail call void @gc_collect()
  br label %14

14:                                               ; preds = %.critedge, %13, %3
  %15 = load ptr, ptr @allocptr, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 24
  %17 = load ptr, ptr @fromspace, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 393216
  %19 = icmp ugt ptr %16, %18
  br i1 %19, label %20, label %23

20:                                               ; preds = %14
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = call i32 @fputs(ptr noundef nonnull @.str.11, ptr noundef %21) #3
  call void @abort() #4
  unreachable

23:                                               ; preds = %14
  %24 = getelementptr inbounds i8, ptr %15, i64 16
  store i32 %0, ptr %24, align 8, !tbaa !9
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %25, ptr %15, align 8, !tbaa !12
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr @allocptr, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  store ptr %26, ptr %28, align 8, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %27, i64 24
  store ptr %29, ptr @allocptr, align 8, !tbaa !5
  ret ptr %27
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @gc_pop() local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fputs(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @gc_collect() local_unnamed_addr #0

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 = { noreturn 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 = { 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 #3 = { cold }
attributes #4 = { noreturn 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, !11, i64 16}
!10 = !{!"object_t", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 8}


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