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

@ATOM = external dso_local global i32, align 4
@CONS = external dso_local global i32, align 4
@cell = external dso_local global [10240 x double], align 16
@stderr = external global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [12 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 uwtable
declare dso_local i32 @ord(double noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local double @err(i32 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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

; Function Attrs: nounwind uwtable
define dso_local double @f_setq(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
  %7 = 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) #3
  %8 = load double, ptr %3, align 8, !tbaa !5
  %9 = call double @cdr(double noundef %8)
  %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)
  store double %13, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %14 = load double, ptr %3, align 8, !tbaa !5
  %15 = call double @car(double noundef %14)
  store double %15, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !9
  %17 = load double, ptr %16, align 8, !tbaa !5
  store double %17, ptr %7, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %34, %2
  %19 = load i64, ptr %7, align 8, !tbaa !11
  %20 = lshr i64 %19, 48
  %21 = load i32, ptr @CONS, align 4, !tbaa !13
  %22 = zext i32 %21 to i64
  %23 = icmp eq i64 %20, %22
  br i1 %23, label %24, label %32

24:                                               ; preds = %18
  %25 = load double, ptr %6, align 8, !tbaa !5
  %26 = load double, ptr %7, align 8, !tbaa !5
  %27 = call double @car(double noundef %26)
  %28 = call double @car(double noundef %27)
  %29 = call i32 @equ(double noundef %25, double noundef %28)
  %30 = icmp ne i32 %29, 0
  %31 = xor i1 %30, true
  br label %32

32:                                               ; preds = %24, %18
  %33 = phi i1 [ false, %18 ], [ %31, %24 ]
  br i1 %33, label %34, label %37

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

37:                                               ; preds = %32
  %38 = load i64, ptr %7, align 8, !tbaa !11
  %39 = lshr i64 %38, 48
  %40 = load i32, ptr @CONS, align 4, !tbaa !13
  %41 = zext i32 %40 to i64
  %42 = icmp eq i64 %39, %41
  br i1 %42, label %43, label %51

43:                                               ; preds = %37
  %44 = load double, ptr %5, align 8, !tbaa !5
  %45 = load double, ptr %7, align 8, !tbaa !5
  %46 = call double @car(double noundef %45)
  %47 = call i32 @ord(double noundef %46)
  %48 = add i32 %47, 1
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds [10240 x double], ptr @cell, i64 0, i64 %49
  store double %44, ptr %50, align 8, !tbaa !5
  br label %69

51:                                               ; preds = %37
  %52 = load i64, ptr %6, align 8, !tbaa !11
  %53 = lshr i64 %52, 48
  %54 = load i32, ptr @ATOM, align 4, !tbaa !13
  %55 = zext i32 %54 to i64
  %56 = icmp eq i64 %53, %55
  br i1 %56, label %57, label %65

57:                                               ; preds = %51
  %58 = load ptr, ptr @stderr, align 8, !tbaa !9
  %59 = load double, ptr %6, align 8, !tbaa !5
  %60 = call i32 @ord(double noundef %59)
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds i8, ptr @cell, i64 %61
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %58, ptr noundef @.str.9, ptr noundef %62) #3
  %64 = call double @err(i32 noundef 3)
  br label %67

65:                                               ; preds = %51
  %66 = call double @err(i32 noundef 3)
  br label %67

67:                                               ; preds = %65, %57
  %68 = phi double [ %64, %57 ], [ %66, %65 ]
  br label %69

69:                                               ; preds = %67, %43
  %70 = phi double [ %44, %43 ], [ %68, %67 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret double %70
}

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

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


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

@ATOM = external dso_local local_unnamed_addr global i32, align 4
@CONS = external dso_local local_unnamed_addr global i32, align 4
@cell = external dso_local global [10240 x double], align 16
@stderr = external local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [12 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @err(i32 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: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; 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_setq(double noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call double @cdr(double noundef %0)
  %4 = tail call double @car(double noundef %3)
  %5 = load double, ptr %1, align 8, !tbaa !5
  %6 = tail call double @eval(double noundef %4, double noundef %5)
  %7 = tail call double @car(double noundef %0)
  %8 = load double, ptr %1, align 8, !tbaa !5
  %9 = bitcast double %8 to i64
  %10 = lshr i64 %9, 48
  %11 = load i32, ptr @CONS, align 4, !tbaa !9
  %12 = zext i32 %11 to i64
  %13 = icmp eq i64 %10, %12
  br i1 %13, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %2
  %14 = tail call double @car(double noundef %8)
  %15 = tail call double @car(double noundef %14)
  %16 = tail call i32 @equ(double noundef %7, double noundef %15)
  %.not32 = icmp eq i32 %16, 0
  br i1 %.not32, label %.lr.ph34, label %.lr.ph..critedge.loopexit_crit_edge

.lr.ph:                                           ; preds = %.lr.ph34
  %17 = tail call double @car(double noundef %20)
  %18 = tail call double @car(double noundef %17)
  %19 = tail call i32 @equ(double noundef %7, double noundef %18)
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %.lr.ph34, label %.lr.ph..critedge.loopexit_crit_edge, !llvm.loop !11

.lr.ph..critedge.loopexit_crit_edge:              ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa27 = phi i64 [ %10, %.lr.ph.preheader ], [ %22, %.lr.ph ]
  %.012.lcssa = phi double [ %8, %.lr.ph.preheader ], [ %20, %.lr.ph ]
  %.pre.pre = load i32, ptr @CONS, align 4, !tbaa !9
  %.pre19 = zext i32 %.pre.pre to i64
  br label %.critedge

.lr.ph34:                                         ; preds = %.lr.ph.preheader, %.lr.ph
  %.01233 = phi double [ %20, %.lr.ph ], [ %8, %.lr.ph.preheader ]
  %20 = tail call double @cdr(double noundef %.01233)
  %21 = bitcast double %20 to i64
  %22 = lshr i64 %21, 48
  %23 = load i32, ptr @CONS, align 4, !tbaa !9
  %24 = zext i32 %23 to i64
  %25 = icmp eq i64 %22, %24
  br i1 %25, label %.lr.ph, label %.critedge, !llvm.loop !11

.critedge:                                        ; preds = %.lr.ph34, %.lr.ph..critedge.loopexit_crit_edge, %2
  %.pre-phi = phi i64 [ %12, %2 ], [ %.pre19, %.lr.ph..critedge.loopexit_crit_edge ], [ %24, %.lr.ph34 ]
  %.0.lcssa = phi double [ %8, %2 ], [ %.012.lcssa, %.lr.ph..critedge.loopexit_crit_edge ], [ %20, %.lr.ph34 ]
  %.lcssa = phi i64 [ %10, %2 ], [ %.lcssa27, %.lr.ph..critedge.loopexit_crit_edge ], [ %22, %.lr.ph34 ]
  %26 = icmp eq i64 %.lcssa, %.pre-phi
  br i1 %26, label %27, label %33

27:                                               ; preds = %.critedge
  %28 = tail call double @car(double noundef %.0.lcssa)
  %29 = tail call i32 @ord(double noundef %28)
  %30 = add i32 %29, 1
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds [10240 x double], ptr @cell, i64 0, i64 %31
  store double %6, ptr %32, align 8, !tbaa !5
  br label %48

33:                                               ; preds = %.critedge
  %34 = bitcast double %7 to i64
  %35 = lshr i64 %34, 48
  %36 = load i32, ptr @ATOM, align 4, !tbaa !9
  %37 = zext i32 %36 to i64
  %38 = icmp eq i64 %35, %37
  br i1 %38, label %39, label %46

39:                                               ; preds = %33
  %40 = load ptr, ptr @stderr, align 8, !tbaa !13
  %41 = tail call i32 @ord(double noundef %7)
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr @cell, i64 %42
  %44 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str.9, ptr noundef nonnull %43) #2
  %45 = tail call double @err(i32 noundef 3)
  br label %48

46:                                               ; preds = %33
  %47 = tail call double @err(i32 noundef 3)
  br label %48

48:                                               ; preds = %39, %46, %27
  %49 = phi double [ %6, %27 ], [ %45, %39 ], [ %47, %46 ]
  ret double %49
}

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 = { 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" }
attributes #2 = { cold 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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}


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