; LLVM IR from Robert-van-Engelen/lisp-cheney :: src (lisp-cheney)

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

@hp = external dso_local global i64, align 8
@sp = external dso_local global i64, align 8
@heap = external dso_local global [2 x [8192 x double]], align 16
@cell = external dso_local global ptr, align 8
@from = external dso_local global ptr, align 8
@vars = external dso_local global double, align 8

; Function Attrs: nounwind uwtable
declare dso_local i64 @equ(double noundef, double noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local double @err(i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local double @move(double noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local double @gc(double noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca i64, align 8
  store double %0, ptr %2, align 8, !tbaa !5
  %4 = load i64, ptr @hp, align 8, !tbaa !9
  %5 = load i64, ptr @sp, align 8, !tbaa !9
  %6 = sub i64 %5, 2
  %7 = shl i64 %6, 3
  %8 = icmp ugt i64 %4, %7
  br i1 %8, label %13, label %9

9:                                                ; preds = %1
  %10 = load double, ptr %2, align 8, !tbaa !5
  %11 = call i64 @equ(double noundef %10, double noundef 1.000000e+00)
  %12 = icmp ne i64 %11, 0
  br i1 %12, label %13, label %48

13:                                               ; preds = %9, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 8192, ptr %3, align 8, !tbaa !9
  store i64 0, ptr @hp, align 8, !tbaa !9
  store i64 8192, ptr @sp, align 8, !tbaa !9
  %14 = load ptr, ptr @cell, align 8, !tbaa !11
  store ptr %14, ptr @from, align 8, !tbaa !11
  %15 = load ptr, ptr @cell, align 8, !tbaa !11
  %16 = icmp eq ptr %15, @heap
  %17 = zext i1 %16 to i32
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [2 x [8192 x double]], ptr @heap, i64 0, i64 %18
  %20 = getelementptr inbounds [8192 x double], ptr %19, i64 0, i64 0
  store ptr %20, ptr @cell, align 8, !tbaa !11
  %21 = load double, ptr @vars, align 8, !tbaa !5
  %22 = call double @move(double noundef %21)
  store double %22, ptr @vars, align 8, !tbaa !5
  %23 = load double, ptr %2, align 8, !tbaa !5
  %24 = call double @move(double noundef %23)
  store double %24, ptr %2, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %30, %13
  %26 = load i64, ptr %3, align 8, !tbaa !9
  %27 = add i64 %26, -1
  store i64 %27, ptr %3, align 8, !tbaa !9
  %28 = load i64, ptr @sp, align 8, !tbaa !9
  %29 = icmp uge i64 %27, %28
  br i1 %29, label %30, label %39

30:                                               ; preds = %25
  %31 = load ptr, ptr @cell, align 8, !tbaa !11
  %32 = load i64, ptr %3, align 8, !tbaa !9
  %33 = getelementptr inbounds double, ptr %31, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = call double @move(double noundef %34)
  %36 = load ptr, ptr @cell, align 8, !tbaa !11
  %37 = load i64, ptr %3, align 8, !tbaa !9
  %38 = getelementptr inbounds double, ptr %36, i64 %37
  store double %35, ptr %38, align 8, !tbaa !5
  br label %25, !llvm.loop !13

39:                                               ; preds = %25
  %40 = load i64, ptr @hp, align 8, !tbaa !9
  %41 = load i64, ptr @sp, align 8, !tbaa !9
  %42 = sub i64 %41, 2
  %43 = shl i64 %42, 3
  %44 = icmp ugt i64 %40, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %39
  %46 = call double @err(i32 noundef 7)
  br label %47

47:                                               ; preds = %45, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %48

48:                                               ; preds = %47, %9
  %49 = load double, ptr %2, align 8, !tbaa !5
  ret double %49
}

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 = { 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 = !{!"double", !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, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@hp = external dso_local local_unnamed_addr global i64, align 8
@sp = external dso_local local_unnamed_addr global i64, align 8
@heap = external dso_local global [2 x [8192 x double]], align 16
@cell = external dso_local local_unnamed_addr global ptr, align 8
@from = external dso_local local_unnamed_addr global ptr, align 8
@vars = external dso_local local_unnamed_addr global double, align 8

; Function Attrs: nounwind uwtable
declare dso_local i64 @equ(double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local double @err(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local double @move(double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local double @gc(double noundef %0) local_unnamed_addr #0 {
  %2 = load i64, ptr @hp, align 8, !tbaa !5
  %3 = load i64, ptr @sp, align 8, !tbaa !5
  %4 = shl i64 %3, 3
  %5 = add i64 %4, -16
  %6 = icmp ugt i64 %2, %5
  br i1 %6, label %9, label %7

7:                                                ; preds = %1
  %8 = tail call i64 @equ(double noundef %0, double noundef 1.000000e+00)
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %33, label %9

9:                                                ; preds = %7, %1
  store i64 0, ptr @hp, align 8, !tbaa !5
  store i64 8192, ptr @sp, align 8, !tbaa !5
  %10 = load ptr, ptr @cell, align 8, !tbaa !9
  store ptr %10, ptr @from, align 8, !tbaa !9
  %11 = icmp eq ptr %10, @heap
  %12 = zext i1 %11 to i64
  %13 = getelementptr inbounds [2 x [8192 x double]], ptr @heap, i64 0, i64 %12
  store ptr %13, ptr @cell, align 8, !tbaa !9
  %14 = load double, ptr @vars, align 8, !tbaa !11
  %15 = tail call double @move(double noundef %14)
  store double %15, ptr @vars, align 8, !tbaa !11
  %16 = tail call double @move(double noundef %0)
  %17 = load i64, ptr @sp, align 8, !tbaa !5
  %.not89 = icmp ugt i64 %17, 8191
  br i1 %.not89, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %9
  %.pre = load ptr, ptr @cell, align 8, !tbaa !9
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %18 = phi ptr [ %23, %.lr.ph ], [ %.pre, %.lr.ph.preheader ]
  %19 = phi i64 [ %25, %.lr.ph ], [ 8191, %.lr.ph.preheader ]
  %20 = getelementptr inbounds double, ptr %18, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !11
  %22 = tail call double @move(double noundef %21)
  %23 = load ptr, ptr @cell, align 8, !tbaa !9
  %24 = getelementptr inbounds double, ptr %23, i64 %19
  store double %22, ptr %24, align 8, !tbaa !11
  %25 = add i64 %19, -1
  %26 = load i64, ptr @sp, align 8, !tbaa !5
  %.not8 = icmp ult i64 %25, %26
  br i1 %.not8, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %9
  %.lcssa = phi i64 [ %17, %9 ], [ %26, %.lr.ph ]
  %27 = load i64, ptr @hp, align 8, !tbaa !5
  %28 = shl i64 %.lcssa, 3
  %29 = add i64 %28, -16
  %30 = icmp ugt i64 %27, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %._crit_edge
  %32 = tail call double @err(i32 noundef 7)
  br label %33

33:                                               ; preds = %._crit_edge, %31, %7
  %.05 = phi double [ %0, %7 ], [ %16, %31 ], [ %16, %._crit_edge ]
  ret double %.05
}

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

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


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