; 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
@cell = external dso_local global [1024 x double], align 16
@nil = external dso_local global double, align 8
@buf = external dso_local global [40 x i8], align 16

; 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 signext i8 @scan() #1

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

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

6:                                                ; preds = %25, %0
  %7 = call signext i8 @scan()
  %8 = sext i8 %7 to i32
  %9 = icmp eq i32 %8, 41
  br i1 %9, label %10, label %12

10:                                               ; preds = %6
  %11 = load double, ptr %2, align 8, !tbaa !5
  store double %11, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %33

12:                                               ; preds = %6
  %13 = load i8, ptr @buf, align 16, !tbaa !11
  %14 = sext i8 %13 to i32
  %15 = icmp eq i32 %14, 46
  br i1 %15, label %16, label %24

16:                                               ; preds = %12
  %17 = load i8, ptr getelementptr inbounds ([40 x i8], ptr @buf, i64 0, i64 1), align 1, !tbaa !11
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %24, label %19

19:                                               ; preds = %16
  %20 = call double @Read()
  %21 = load ptr, ptr %3, align 8, !tbaa !9
  store double %20, ptr %21, align 8, !tbaa !5
  %22 = call signext i8 @scan()
  %23 = load double, ptr %2, align 8, !tbaa !5
  store double %23, ptr %1, align 8
  store i32 1, ptr %4, align 4
  br label %33

24:                                               ; preds = %16, %12
  br label %25

25:                                               ; preds = %24
  %26 = call double @parse()
  %27 = load double, ptr @nil, align 8, !tbaa !5
  %28 = call double @cons(double noundef %26, double noundef %27)
  %29 = load ptr, ptr %3, align 8, !tbaa !9
  store double %28, ptr %29, align 8, !tbaa !5
  %30 = load i32, ptr @sp, align 4, !tbaa !12
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr @cell, i64 %31
  store ptr %32, ptr %3, align 8, !tbaa !9
  br label %6

33:                                               ; preds = %19, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  %34 = load double, ptr %1, align 8
  ret double %34
}

; Function Attrs: nounwind uwtable
declare dso_local double @parse() #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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"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"

@sp = 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
@buf = external dso_local local_unnamed_addr global [40 x i8], align 16

; 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 signext i8 @scan() local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local double @list() local_unnamed_addr #1 {
  %1 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1)
  %2 = load double, ptr @nil, align 8, !tbaa !5
  store double %2, ptr %1, align 8, !tbaa !5
  %3 = tail call signext i8 @scan()
  %4 = icmp eq i8 %3, 41
  br i1 %4, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %0, %12
  %.07 = phi ptr [ %18, %12 ], [ %1, %0 ]
  %5 = load i8, ptr @buf, align 16, !tbaa !9
  %6 = icmp ne i8 %5, 46
  %7 = load i8, ptr getelementptr inbounds (i8, ptr @buf, i64 1), align 1
  %8 = icmp ne i8 %7, 0
  %or.cond = select i1 %6, i1 true, i1 %8
  br i1 %or.cond, label %12, label %9

9:                                                ; preds = %.lr.ph
  %10 = tail call double @Read()
  store double %10, ptr %.07, align 8, !tbaa !5
  %11 = tail call signext i8 @scan()
  br label %.loopexit

12:                                               ; preds = %.lr.ph
  %13 = tail call double @parse()
  %14 = load double, ptr @nil, align 8, !tbaa !5
  %15 = tail call double @cons(double noundef %13, double noundef %14)
  store double %15, ptr %.07, align 8, !tbaa !5
  %16 = load i32, ptr @sp, align 4, !tbaa !10
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds double, ptr @cell, i64 %17
  %19 = tail call signext i8 @scan()
  %20 = icmp eq i8 %19, 41
  br i1 %20, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %12, %0, %9
  %.0..0..0..04 = load double, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1)
  ret double %.0..0..0..04
}

; Function Attrs: nounwind uwtable
declare dso_local double @parse() 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}


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