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

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

@ATOM = external dso_local global i32, align 4
@CONS = external dso_local global i32, align 4
@cell = external dso_local global [10240 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 i32 @ord(double noundef) #1

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

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

; 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 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
  %6 = load double, ptr @nil, align 8, !tbaa !5
  %7 = call ptr @push(double noundef %6)
  store ptr %7, ptr %5, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %28, %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 %31

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 %5, align 8, !tbaa !9
  store double %20, ptr %21, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !9
  %23 = load double, ptr %22, align 8, !tbaa !5
  %24 = call i32 @ord(double noundef %23)
  %25 = add i32 %24, 1
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [10240 x double], ptr @cell, i64 0, i64 %26
  store ptr %27, ptr %5, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %14
  %29 = load double, ptr %3, align 8, !tbaa !5
  %30 = call double @cdr(double noundef %29)
  store double %30, ptr %3, align 8, !tbaa !5
  br label %8, !llvm.loop !15

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

37:                                               ; preds = %31
  %38 = load double, ptr %3, align 8, !tbaa !5
  %39 = load double, ptr %4, align 8, !tbaa !5
  %40 = call double @assoc(double noundef %38, double noundef %39)
  %41 = load ptr, ptr %5, align 8, !tbaa !9
  store double %40, ptr %41, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %37, %31
  %43 = call double @pop()
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret double %43
}

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

@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 [10240 x double], align 16
@nil = external dso_local local_unnamed_addr global double, align 8

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local double @evlis(double noundef %0, double noundef %1) local_unnamed_addr #0 {
  %3 = load double, ptr @nil, align 8, !tbaa !5
  %4 = tail call ptr @push(double noundef %3)
  %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
  %.012 = phi ptr [ %17, %.lr.ph ], [ %4, %2 ]
  %.0911 = phi double [ %18, %.lr.ph ], [ %0, %2 ]
  %10 = tail call double @car(double noundef %.0911)
  %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 %.012, align 8, !tbaa !5
  %14 = tail call i32 @ord(double noundef %13)
  %15 = add i32 %14, 1
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [10240 x double], ptr @cell, i64 0, i64 %16
  %18 = tail call double @cdr(double noundef %.0911)
  %19 = bitcast double %18 to i64
  %20 = lshr i64 %19, 48
  %21 = load i32, ptr @CONS, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = icmp eq i64 %20, %22
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.09.lcssa = phi double [ %0, %2 ], [ %18, %.lr.ph ]
  %.0.lcssa = phi ptr [ %4, %2 ], [ %17, %.lr.ph ]
  %.lcssa = phi i64 [ %6, %2 ], [ %20, %.lr.ph ]
  %24 = load i32, ptr @ATOM, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = icmp eq i64 %.lcssa, %25
  br i1 %26, label %27, label %29

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

29:                                               ; preds = %27, %._crit_edge
  %30 = tail call double @pop()
  ret double %30
}

; Function Attrs: nounwind uwtable
declare dso_local double @eval(double noundef, double noundef) 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" }

!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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass