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

@NIL = 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 double @pair(double noundef, 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 i32 @more(double noundef) #1

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

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

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

7:                                                ; preds = %20, %2
  %8 = load double, ptr %5, align 8, !tbaa !5
  %9 = call i32 @more(double noundef %8)
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %23

11:                                               ; preds = %7
  %12 = load double, ptr %5, align 8, !tbaa !5
  %13 = call double @car(double noundef %12)
  %14 = call double @car(double noundef %13)
  %15 = load double, ptr @nil, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !9
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = call double @pair(double noundef %14, double noundef %15, double noundef %17)
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  store double %18, ptr %19, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %11
  %21 = load double, ptr %5, align 8, !tbaa !5
  %22 = call double @cdr(double noundef %21)
  store double %22, ptr %5, align 8, !tbaa !5
  br label %7, !llvm.loop !11

23:                                               ; preds = %7
  %24 = load ptr, ptr %4, align 8, !tbaa !9
  %25 = load double, ptr %24, align 8, !tbaa !5
  store double %25, ptr %5, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %45, %23
  %27 = load double, ptr %3, align 8, !tbaa !5
  %28 = call i32 @more(double noundef %27)
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %50

30:                                               ; preds = %26
  %31 = load double, ptr %3, align 8, !tbaa !5
  %32 = call double @car(double noundef %31)
  %33 = call double @cdr(double noundef %32)
  %34 = load ptr, ptr %4, align 8, !tbaa !9
  %35 = call double @f_begin(double noundef %33, ptr noundef %34)
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = load double, ptr %36, align 8, !tbaa !5
  %38 = call double @eval(double noundef %35, double noundef %37)
  %39 = load double, ptr %5, align 8, !tbaa !5
  %40 = call double @car(double noundef %39)
  %41 = call i32 @ord(double noundef %40)
  %42 = add i32 %41, 1
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [10240 x double], ptr @cell, i64 0, i64 %43
  store double %38, ptr %44, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %30
  %46 = load double, ptr %5, align 8, !tbaa !5
  %47 = call double @cdr(double noundef %46)
  store double %47, ptr %5, align 8, !tbaa !5
  %48 = load double, ptr %3, align 8, !tbaa !5
  %49 = call double @cdr(double noundef %48)
  store double %49, ptr %3, align 8, !tbaa !5
  br label %26, !llvm.loop !13

50:                                               ; preds = %26
  %51 = load i64, ptr %3, align 8, !tbaa !14
  %52 = lshr i64 %51, 48
  %53 = load i32, ptr @NIL, align 4, !tbaa !16
  %54 = zext i32 %53 to i64
  %55 = icmp eq i64 %52, %54
  br i1 %55, label %56, label %58

56:                                               ; preds = %50
  %57 = load double, ptr @nil, align 8, !tbaa !5
  br label %61

58:                                               ; preds = %50
  %59 = load double, ptr %3, align 8, !tbaa !5
  %60 = call double @car(double noundef %59)
  br label %61

61:                                               ; preds = %58, %56
  %62 = phi double [ %57, %56 ], [ %60, %58 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret double %62
}

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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"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"

@NIL = 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 double @pair(double noundef, 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 i32 @more(double noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local double @f_letrec(double noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @more(double noundef %0)
  %.not17 = icmp eq i32 %3, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.018 = phi double [ %9, %.lr.ph ], [ %0, %2 ]
  %4 = tail call double @car(double noundef %.018)
  %5 = tail call double @car(double noundef %4)
  %6 = load double, ptr @nil, align 8, !tbaa !5
  %7 = load double, ptr %1, align 8, !tbaa !5
  %8 = tail call double @pair(double noundef %5, double noundef %6, double noundef %7)
  store double %8, ptr %1, align 8, !tbaa !5
  %9 = tail call double @cdr(double noundef %.018)
  %10 = tail call i32 @more(double noundef %9)
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %2
  %11 = load double, ptr %1, align 8, !tbaa !5
  %12 = tail call i32 @more(double noundef %0)
  %.not1619 = icmp eq i32 %12, 0
  br i1 %.not1619, label %._crit_edge24, label %.lr.ph23

.lr.ph23:                                         ; preds = %._crit_edge, %.lr.ph23
  %.121 = phi double [ %23, %.lr.ph23 ], [ %11, %._crit_edge ]
  %.01520 = phi double [ %24, %.lr.ph23 ], [ %0, %._crit_edge ]
  %13 = tail call double @car(double noundef %.01520)
  %14 = tail call double @cdr(double noundef %13)
  %15 = tail call double @f_begin(double noundef %14, ptr noundef nonnull %1)
  %16 = load double, ptr %1, align 8, !tbaa !5
  %17 = tail call double @eval(double noundef %15, double noundef %16)
  %18 = tail call double @car(double noundef %.121)
  %19 = tail call i32 @ord(double noundef %18)
  %20 = add i32 %19, 1
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds [10240 x double], ptr @cell, i64 0, i64 %21
  store double %17, ptr %22, align 8, !tbaa !5
  %23 = tail call double @cdr(double noundef %.121)
  %24 = tail call double @cdr(double noundef %.01520)
  %25 = tail call i32 @more(double noundef %24)
  %.not16 = icmp eq i32 %25, 0
  br i1 %.not16, label %._crit_edge24, label %.lr.ph23, !llvm.loop !11

._crit_edge24:                                    ; preds = %.lr.ph23, %._crit_edge
  %.015.lcssa = phi double [ %0, %._crit_edge ], [ %24, %.lr.ph23 ]
  %26 = bitcast double %.015.lcssa to i64
  %27 = lshr i64 %26, 48
  %28 = load i32, ptr @NIL, align 4, !tbaa !12
  %29 = zext i32 %28 to i64
  %30 = icmp eq i64 %27, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %._crit_edge24
  %32 = load double, ptr @nil, align 8, !tbaa !5
  br label %35

33:                                               ; preds = %._crit_edge24
  %34 = tail call double @car(double noundef %.015.lcssa)
  br label %35

35:                                               ; preds = %33, %31
  %36 = phi double [ %32, %31 ], [ %34, %33 ]
  ret double %36
}

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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}


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