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

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

@sp = external dso_local global i32, align 4
@ATOM = 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
@nil = external dso_local global double, align 8

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @cons(double noundef, double noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local double @car(double noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local double @cdr(double noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local double @assoc(double noundef, double noundef) #1

; Function Attrs: nounwind uwtable
define dso_local double @evlis(double noundef %0, double noundef %1) #1 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %7 = load double, ptr @nil, align 8, !tbaa !5
  store double %7, ptr %5, align 8, !tbaa !5
  store ptr %5, ptr %6, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %22, %2
  %9 = load i64, ptr %3, align 8, !tbaa !11
  %10 = lshr i64 %9, 48
  %11 = load i32, ptr @CONS, align 4, !tbaa !13
  %12 = zext i32 %11 to i64
  %13 = icmp eq i64 %10, %12
  br i1 %13, label %14, label %28

14:                                               ; preds = %8
  %15 = load double, ptr %3, align 8, !tbaa !5
  %16 = call double @car(double noundef %15)
  %17 = load double, ptr %4, align 8, !tbaa !5
  %18 = call double @eval(double noundef %16, double noundef %17)
  %19 = load double, ptr @nil, align 8, !tbaa !5
  %20 = call double @cons(double noundef %18, double noundef %19)
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  store double %20, ptr %21, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %14
  %23 = load i32, ptr @sp, align 4, !tbaa !13
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr @cell, i64 %24
  store ptr %25, ptr %6, align 8, !tbaa !9
  %26 = load double, ptr %3, align 8, !tbaa !5
  %27 = call double @cdr(double noundef %26)
  store double %27, ptr %3, align 8, !tbaa !5
  br label %8, !llvm.loop !15

28:                                               ; preds = %8
  %29 = load i64, ptr %3, align 8, !tbaa !11
  %30 = lshr i64 %29, 48
  %31 = load i32, ptr @ATOM, align 4, !tbaa !13
  %32 = zext i32 %31 to i64
  %33 = icmp eq i64 %30, %32
  br i1 %33, label %34, label %39

34:                                               ; preds = %28
  %35 = load double, ptr %3, align 8, !tbaa !5
  %36 = load double, ptr %4, align 8, !tbaa !5
  %37 = call double @assoc(double noundef %35, double noundef %36)
  %38 = load ptr, ptr %6, align 8, !tbaa !9
  store double %37, ptr %38, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %34, %28
  %40 = load double, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret double %40
}

; Function Attrs: nounwind uwtable
declare dso_local double @eval(double noundef, double noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@sp = external dso_local local_unnamed_addr global i32, align 4
@ATOM = 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
@nil = external dso_local local_unnamed_addr global double, align 8

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @cons(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local double @car(double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local double @cdr(double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local double @assoc(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local double @evlis(double noundef %0, double noundef %1) local_unnamed_addr #1 {
  %3 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3)
  %4 = load double, ptr @nil, align 8, !tbaa !5
  store double %4, ptr %3, align 8, !tbaa !5
  %5 = bitcast double %0 to i64
  %6 = lshr i64 %5, 48
  %7 = load i32, ptr @CONS, align 4, !tbaa !9
  %8 = zext i32 %7 to i64
  %9 = icmp eq i64 %6, %8
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.011 = phi ptr [ %16, %.lr.ph ], [ %3, %2 ]
  %.0810 = phi double [ %17, %.lr.ph ], [ %0, %2 ]
  %10 = tail call double @car(double noundef %.0810)
  %11 = tail call double @eval(double noundef %10, double noundef %1)
  %12 = load double, ptr @nil, align 8, !tbaa !5
  %13 = tail call double @cons(double noundef %11, double noundef %12)
  store double %13, ptr %.011, align 8, !tbaa !5
  %14 = load i32, ptr @sp, align 4, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds double, ptr @cell, i64 %15
  %17 = tail call double @cdr(double noundef %.0810)
  %18 = bitcast double %17 to i64
  %19 = lshr i64 %18, 48
  %20 = load i32, ptr @CONS, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = icmp eq i64 %19, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.08.lcssa = phi double [ %0, %2 ], [ %17, %.lr.ph ]
  %.0.lcssa = phi ptr [ %3, %2 ], [ %16, %.lr.ph ]
  %.lcssa = phi i64 [ %6, %2 ], [ %19, %.lr.ph ]
  %23 = load i32, ptr @ATOM, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = icmp eq i64 %.lcssa, %24
  br i1 %25, label %26, label %28

26:                                               ; preds = %._crit_edge
  %27 = tail call double @assoc(double noundef %.08.lcssa, double noundef %1)
  store double %27, ptr %.0.lcssa, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %26, %._crit_edge
  %.0..0..0..0. = load double, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3)
  ret double %.0..0..0..0.
}

; Function Attrs: nounwind uwtable
declare dso_local double @eval(double noundef, double noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = !{!"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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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