; 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
@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 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 @not(double noundef) #1

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

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

8:                                                ; preds = %35, %2
  %9 = load double, ptr %3, align 8, !tbaa !5
  %10 = call double @car(double noundef %9)
  %11 = load ptr, ptr %4, align 8, !tbaa !9
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = call double @eval(double noundef %10, double noundef %12)
  %14 = call i32 @not(double noundef %13)
  %15 = icmp ne i32 %14, 0
  %16 = xor i1 %15, true
  br i1 %16, label %17, label %36

17:                                               ; preds = %8
  %18 = load double, ptr %3, align 8, !tbaa !5
  %19 = call double @cdr(double noundef %18)
  store double %19, ptr %5, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %32, %17
  %21 = load i64, ptr %5, align 8, !tbaa !11
  %22 = lshr i64 %21, 48
  %23 = load i32, ptr @NIL, align 4, !tbaa !13
  %24 = zext i32 %23 to i64
  %25 = icmp ne i64 %22, %24
  br i1 %25, label %26, label %35

26:                                               ; preds = %20
  %27 = load double, ptr %5, align 8, !tbaa !5
  %28 = call double @car(double noundef %27)
  %29 = load ptr, ptr %4, align 8, !tbaa !9
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = call double @eval(double noundef %28, double noundef %30)
  store double %31, ptr %6, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %26
  %33 = load double, ptr %5, align 8, !tbaa !5
  %34 = call double @cdr(double noundef %33)
  store double %34, ptr %5, align 8, !tbaa !5
  br label %20, !llvm.loop !15

35:                                               ; preds = %20
  br label %8, !llvm.loop !17

36:                                               ; preds = %8
  %37 = load double, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret double %37
}

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"}
!17 = distinct !{!17, !16}


; 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
@nil = external dso_local local_unnamed_addr global double, align 8

; 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 @not(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
define dso_local double @f_while(double noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load double, ptr @nil, align 8, !tbaa !5
  %4 = tail call double @car(double noundef %0)
  %5 = load double, ptr %1, align 8, !tbaa !5
  %6 = tail call double @eval(double noundef %4, double noundef %5)
  %7 = tail call i32 @not(double noundef %6)
  %.not11 = icmp eq i32 %7, 0
  br i1 %.not11, label %.lr.ph13, label %._crit_edge

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph13
  %.1.lcssa = phi double [ %.012, %.lr.ph13 ], [ %19, %.lr.ph ]
  %8 = tail call double @car(double noundef %0)
  %9 = load double, ptr %1, align 8, !tbaa !5
  %10 = tail call double @eval(double noundef %8, double noundef %9)
  %11 = tail call i32 @not(double noundef %10)
  %.not = icmp eq i32 %11, 0
  br i1 %.not, label %.lr.ph13, label %._crit_edge, !llvm.loop !9

.lr.ph13:                                         ; preds = %2, %.loopexit
  %.012 = phi double [ %.1.lcssa, %.loopexit ], [ %3, %2 ]
  %12 = tail call double @cdr(double noundef %0)
  %13 = bitcast double %12 to i64
  %14 = lshr i64 %13, 48
  %15 = load i32, ptr @NIL, align 4, !tbaa !11
  %16 = zext i32 %15 to i64
  %.not89 = icmp eq i64 %14, %16
  br i1 %.not89, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph13, %.lr.ph
  %.0710 = phi double [ %20, %.lr.ph ], [ %12, %.lr.ph13 ]
  %17 = tail call double @car(double noundef %.0710)
  %18 = load double, ptr %1, align 8, !tbaa !5
  %19 = tail call double @eval(double noundef %17, double noundef %18)
  %20 = tail call double @cdr(double noundef %.0710)
  %21 = bitcast double %20 to i64
  %22 = lshr i64 %21, 48
  %23 = load i32, ptr @NIL, align 4, !tbaa !11
  %24 = zext i32 %23 to i64
  %.not8 = icmp eq i64 %22, %24
  br i1 %.not8, label %.loopexit, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.loopexit, %2
  %.0.lcssa = phi double [ %3, %2 ], [ %.1.lcssa, %.loopexit ]
  ret double %.0.lcssa
}

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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !10}


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