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

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

@nil = external dso_local global double, align 8
@buf = external dso_local global [40 x i8], align 16
@.str.20 = external hidden unnamed_addr constant [2 x i8], align 1

; 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 willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local signext i8 @scan() #2

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

; Function Attrs: nounwind uwtable
define dso_local double @list() #2 {
  %1 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  %2 = call signext i8 @scan()
  %3 = sext i8 %2 to i32
  %4 = icmp eq i32 %3, 41
  br i1 %4, label %5, label %7

5:                                                ; preds = %0
  %6 = load double, ptr @nil, align 8, !tbaa !5
  br label %21

7:                                                ; preds = %0
  %8 = call i32 @strcmp(ptr noundef @buf, ptr noundef @.str.20) #4
  %9 = icmp ne i32 %8, 0
  br i1 %9, label %14, label %10

10:                                               ; preds = %7
  %11 = call double @Read()
  store double %11, ptr %1, align 8, !tbaa !5
  %12 = call signext i8 @scan()
  %13 = load double, ptr %1, align 8, !tbaa !5
  br label %19

14:                                               ; preds = %7
  %15 = call double @parse()
  store double %15, ptr %1, align 8, !tbaa !5
  %16 = load double, ptr %1, align 8, !tbaa !5
  %17 = call double @list()
  %18 = call double @cons(double noundef %16, double noundef %17)
  br label %19

19:                                               ; preds = %14, %10
  %20 = phi double [ %13, %10 ], [ %18, %14 ]
  br label %21

21:                                               ; preds = %19, %5
  %22 = phi double [ %6, %5 ], [ %20, %19 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret double %22
}

; Function Attrs: nounwind uwtable
declare dso_local double @parse() #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) "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 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 #3 = { nounwind }
attributes #4 = { nounwind willreturn memory(read) }

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


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

@nil = external dso_local local_unnamed_addr global double, align 8
@buf = external dso_local global [40 x i8], align 16
@.str.20 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #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 = tail call signext i8 @scan()
  %2 = icmp eq i8 %1, 41
  br i1 %2, label %3, label %5

3:                                                ; preds = %0
  %4 = load double, ptr @nil, align 8, !tbaa !5
  br label %common.ret2

5:                                                ; preds = %0
  %6 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @buf, ptr noundef nonnull dereferenceable(1) @.str.20) #2
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %10

7:                                                ; preds = %5
  %8 = tail call double @Read()
  %9 = tail call signext i8 @scan()
  br label %common.ret2

common.ret2:                                      ; preds = %7, %3, %10
  %common.ret2.op = phi double [ %13, %10 ], [ %4, %3 ], [ %8, %7 ]
  ret double %common.ret2.op

10:                                               ; preds = %5
  %11 = tail call double @parse()
  %12 = tail call double @list()
  %13 = tail call double @cons(double noundef %11, double noundef %12)
  br label %common.ret2
}

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

attributes #0 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 willreturn memory(read) }

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


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass