; LLVM IR from Robert-van-Engelen/lisp :: src (lisp-pr-single)

; 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
@MACR = external dso_local global i32, align 4
@sp = external dso_local global i32, align 4
@used = external dso_local global [128 x i32], align 16
@cell = external dso_local global [10240 x float], align 16
@env = external dso_local global float, align 4

; 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(float noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local float @err(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @mark(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @sweep() #1

; Function Attrs: nounwind uwtable
declare dso_local void @compact() #1

; Function Attrs: nounwind uwtable
define dso_local i32 @gc() #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.memset.p0.i64(ptr align 16 @used, i8 0, i64 512, i1 false)
  %2 = load i32, ptr @env, align 4, !tbaa !5
  %3 = lshr i32 %2, 20
  %4 = load i32, ptr @CONS, align 4, !tbaa !5
  %5 = icmp eq i32 %3, %4
  br i1 %5, label %6, label %9

6:                                                ; preds = %0
  %7 = load float, ptr @env, align 4, !tbaa !9
  %8 = call i32 @ord(float noundef %7)
  call void @mark(i32 noundef %8)
  br label %9

9:                                                ; preds = %6, %0
  %10 = load i32, ptr @sp, align 4, !tbaa !5
  store i32 %10, ptr %1, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %34, %9
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = icmp ult i32 %12, 10240
  br i1 %13, label %14, label %37

14:                                               ; preds = %11
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [10240 x float], ptr @cell, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = lshr i32 %18, 20
  %20 = load i32, ptr @CONS, align 4, !tbaa !5
  %21 = load i32, ptr @MACR, align 4, !tbaa !5
  %22 = xor i32 %20, %21
  %23 = xor i32 %22, -1
  %24 = and i32 %19, %23
  %25 = load i32, ptr @CONS, align 4, !tbaa !5
  %26 = icmp eq i32 %24, %25
  br i1 %26, label %27, label %33

27:                                               ; preds = %14
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds [10240 x float], ptr @cell, i64 0, i64 %29
  %31 = load float, ptr %30, align 4, !tbaa !9
  %32 = call i32 @ord(float noundef %31)
  call void @mark(i32 noundef %32)
  br label %33

33:                                               ; preds = %27, %14
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = add i32 %35, 1
  store i32 %36, ptr %1, align 4, !tbaa !5
  br label %11, !llvm.loop !11

37:                                               ; preds = %11
  %38 = call i32 @sweep()
  store i32 %38, ptr %1, align 4, !tbaa !5
  call void @compact()
  %39 = load i32, ptr %1, align 4, !tbaa !5
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %44

41:                                               ; preds = %37
  %42 = load i32, ptr %1, align 4, !tbaa !5
  %43 = uitofp i32 %42 to float
  br label %46

44:                                               ; preds = %37
  %45 = call float @err(i32 noundef 7)
  br label %46

46:                                               ; preds = %44, %41
  %47 = phi float [ %43, %41 ], [ %45, %44 ]
  %48 = fptoui float %47 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret i32 %48
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@CONS = external dso_local local_unnamed_addr global i32, align 4
@MACR = external dso_local local_unnamed_addr global i32, align 4
@sp = external dso_local local_unnamed_addr global i32, align 4
@used = external dso_local local_unnamed_addr global [128 x i32], align 16
@cell = external dso_local local_unnamed_addr global [10240 x float], align 16
@env = external dso_local local_unnamed_addr global float, align 4

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @sweep() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @compact() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @gc() local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(512) @used, i8 0, i64 512, i1 false)
  %1 = load i32, ptr @env, align 4
  %2 = lshr i32 %1, 20
  %3 = load i32, ptr @CONS, align 4, !tbaa !5
  %4 = icmp eq i32 %2, %3
  br i1 %4, label %5, label %8

5:                                                ; preds = %0
  %6 = bitcast i32 %1 to float
  %7 = tail call i32 @ord(float noundef %6)
  tail call void @mark(i32 noundef %7)
  br label %8

8:                                                ; preds = %5, %0
  %9 = load i32, ptr @sp, align 4, !tbaa !5
  %10 = icmp ult i32 %9, 10240
  br i1 %10, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %8
  %11 = zext nneg i32 %9 to i64
  %.pre9 = load i32, ptr @CONS, align 4, !tbaa !5
  %.pre11 = load i32, ptr @MACR, align 4, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %24
  %12 = phi i32 [ %.pre11, %.lr.ph.preheader ], [ %25, %24 ]
  %13 = phi i32 [ %.pre9, %.lr.ph.preheader ], [ %26, %24 ]
  %indvars.iv = phi i64 [ %11, %.lr.ph.preheader ], [ %indvars.iv.next, %24 ]
  %14 = getelementptr inbounds [10240 x float], ptr @cell, i64 0, i64 %indvars.iv
  %15 = load i32, ptr %14, align 4
  %16 = lshr i32 %15, 20
  %17 = xor i32 %13, %12
  %18 = xor i32 %17, -1
  %19 = and i32 %16, %18
  %20 = icmp eq i32 %19, %13
  br i1 %20, label %21, label %24

21:                                               ; preds = %.lr.ph
  %22 = bitcast i32 %15 to float
  %23 = tail call i32 @ord(float noundef %22)
  tail call void @mark(i32 noundef %23)
  %.pre = load i32, ptr @CONS, align 4, !tbaa !5
  %.pre10 = load i32, ptr @MACR, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %.lr.ph, %21
  %25 = phi i32 [ %12, %.lr.ph ], [ %.pre10, %21 ]
  %26 = phi i32 [ %13, %.lr.ph ], [ %.pre, %21 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = and i64 %indvars.iv.next, 4294967295
  %exitcond.not = icmp eq i64 %27, 10240
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %24, %8
  %28 = tail call i32 @sweep()
  tail call void @compact()
  %.not = icmp eq i32 %28, 0
  br i1 %.not, label %31, label %29

29:                                               ; preds = %._crit_edge
  %30 = uitofp i32 %28 to float
  br label %33

31:                                               ; preds = %._crit_edge
  %32 = tail call float @err(i32 noundef 7)
  br label %33

33:                                               ; preds = %31, %29
  %34 = phi float [ %30, %29 ], [ %32, %31 ]
  %35 = fptoui float %34 to i32
  ret i32 %35
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass