; LLVM IR from Robert-van-Engelen/tinylisp :: src (tinylisp-commented)

; 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 i32, align 4
@sp = external dso_local global i32, align 4
@CONS = external dso_local global i32, align 4
@cell = external dso_local global [1024 x double], align 16

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

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

; Function Attrs: nounwind uwtable
define dso_local double @cons(double noundef %0, double noundef %1) #0 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !5
  %5 = load double, ptr %3, align 8, !tbaa !5
  %6 = load i32, ptr @sp, align 4, !tbaa !9
  %7 = add i32 %6, -1
  store i32 %7, ptr @sp, align 4, !tbaa !9
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds [1024 x double], ptr @cell, i64 0, i64 %8
  store double %5, ptr %9, align 8, !tbaa !5
  %10 = load double, ptr %4, align 8, !tbaa !5
  %11 = load i32, ptr @sp, align 4, !tbaa !9
  %12 = add i32 %11, -1
  store i32 %12, ptr @sp, align 4, !tbaa !9
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds [1024 x double], ptr @cell, i64 0, i64 %13
  store double %10, ptr %14, align 8, !tbaa !5
  %15 = load i32, ptr @hp, align 4, !tbaa !9
  %16 = load i32, ptr @sp, align 4, !tbaa !9
  %17 = shl i32 %16, 3
  %18 = icmp ugt i32 %15, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  call void @abort() #2
  unreachable

20:                                               ; preds = %2
  %21 = load i32, ptr @CONS, align 4, !tbaa !9
  %22 = load i32, ptr @sp, align 4, !tbaa !9
  %23 = call double @box(i32 noundef %21, i32 noundef %22)
  ret double %23
}

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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@hp = external dso_local local_unnamed_addr global i32, align 4
@sp = external dso_local local_unnamed_addr global i32, align 4
@CONS = external dso_local local_unnamed_addr global i32, align 4
@cell = external dso_local local_unnamed_addr global [1024 x double], align 16

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

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

; Function Attrs: nounwind uwtable
define dso_local double @cons(double noundef %0, double noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @sp, align 4, !tbaa !5
  %4 = add i32 %3, -1
  %5 = zext i32 %4 to i64
  %6 = getelementptr inbounds [1024 x double], ptr @cell, i64 0, i64 %5
  store double %0, ptr %6, align 8, !tbaa !9
  %7 = add i32 %3, -2
  store i32 %7, ptr @sp, align 4, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds [1024 x double], ptr @cell, i64 0, i64 %8
  store double %1, ptr %9, align 8, !tbaa !9
  %10 = load i32, ptr @hp, align 4, !tbaa !5
  %11 = shl i32 %7, 3
  %12 = icmp ugt i32 %10, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  tail call void @abort() #2
  unreachable

14:                                               ; preds = %2
  %15 = load i32, ptr @CONS, align 4, !tbaa !5
  %16 = tail call double @box(i32 noundef %15, i32 noundef %7)
  ret double %16
}

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 = { 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 = !{!"double", !7, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass