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

@CONS = external dso_local global i32, align 4
@NIL = external dso_local global i32, align 4
@.str.22 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @printlist(double noundef %0) #0 {
  %2 = alloca double, align 8
  store double %0, ptr %2, align 8, !tbaa !5
  %3 = call i32 @putchar(i32 noundef 40)
  br label %4

4:                                                ; preds = %25, %1
  %5 = load double, ptr %2, align 8, !tbaa !5
  %6 = call double @car(double noundef %5)
  call void @print(double noundef %6)
  %7 = load double, ptr %2, align 8, !tbaa !5
  %8 = call double @cdr(double noundef %7)
  store double %8, ptr %2, align 8, !tbaa !5
  %9 = load i64, ptr %2, align 8, !tbaa !9
  %10 = lshr i64 %9, 48
  %11 = load i32, ptr @NIL, align 4, !tbaa !11
  %12 = zext i32 %11 to i64
  %13 = icmp eq i64 %10, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %4
  br label %27

15:                                               ; preds = %4
  %16 = load i64, ptr %2, align 8, !tbaa !9
  %17 = lshr i64 %16, 48
  %18 = load i32, ptr @CONS, align 4, !tbaa !11
  %19 = zext i32 %18 to i64
  %20 = icmp ne i64 %17, %19
  br i1 %20, label %21, label %24

21:                                               ; preds = %15
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.22)
  %23 = load double, ptr %2, align 8, !tbaa !5
  call void @print(double noundef %23)
  br label %27

24:                                               ; preds = %15
  br label %25

25:                                               ; preds = %24
  %26 = call i32 @putchar(i32 noundef 32)
  br label %4

27:                                               ; preds = %21, %14
  %28 = call i32 @putchar(i32 noundef 41)
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare i32 @putchar(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @print(double noundef) #0

declare i32 @printf(ptr noundef, ...) #2

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 = { inlinehint 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 = { "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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"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"

@CONS = external dso_local local_unnamed_addr global i32, align 4
@NIL = external dso_local local_unnamed_addr global i32, align 4
@.str.22 = external hidden unnamed_addr constant [4 x i8], align 1

; 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
define dso_local void @printlist(double noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @putchar(i32 noundef 40)
  %3 = tail call double @car(double noundef %0)
  tail call void @print(double noundef %3)
  %4 = tail call double @cdr(double noundef %0)
  %5 = bitcast double %4 to i64
  %6 = lshr i64 %5, 48
  %7 = load i32, ptr @NIL, align 4, !tbaa !5
  %8 = zext i32 %7 to i64
  %9 = icmp eq i64 %6, %8
  br i1 %9, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %1, %16
  %10 = phi i64 [ %21, %16 ], [ %6, %1 ]
  %11 = phi double [ %19, %16 ], [ %4, %1 ]
  %12 = load i32, ptr @CONS, align 4, !tbaa !5
  %13 = zext i32 %12 to i64
  %.not = icmp eq i64 %10, %13
  br i1 %.not, label %16, label %14

14:                                               ; preds = %.lr.ph
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22)
  tail call void @print(double noundef %11)
  br label %.loopexit

16:                                               ; preds = %.lr.ph
  %17 = tail call i32 @putchar(i32 noundef 32)
  %18 = tail call double @car(double noundef %11)
  tail call void @print(double noundef %18)
  %19 = tail call double @cdr(double noundef %11)
  %20 = bitcast double %19 to i64
  %21 = lshr i64 %20, 48
  %22 = load i32, ptr @NIL, align 4, !tbaa !5
  %23 = zext i32 %22 to i64
  %24 = icmp eq i64 %21, %23
  br i1 %24, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %16, %1, %14
  %25 = tail call i32 @putchar(i32 noundef 41)
  ret void
}

; Function Attrs: inlinehint nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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 = { inlinehint nofree 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 = { nofree 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" }

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


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