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

@PRIM = external dso_local global i32, align 4
@MACR = external dso_local global i32, align 4
@NIL = external dso_local global i32, 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 double @car(double noundef) #1

; Function Attrs: nounwind uwtable
define dso_local double @f_type(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
  %7 = call double @car(double noundef %6)
  store double %7, ptr %5, align 8, !tbaa !5
  %8 = load i64, ptr %5, align 8, !tbaa !11
  %9 = lshr i64 %8, 48
  %10 = load i32, ptr @NIL, align 4, !tbaa !13
  %11 = zext i32 %10 to i64
  %12 = icmp eq i64 %9, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  br label %37

14:                                               ; preds = %2
  %15 = load i64, ptr %5, align 8, !tbaa !11
  %16 = lshr i64 %15, 48
  %17 = load i32, ptr @PRIM, align 4, !tbaa !13
  %18 = zext i32 %17 to i64
  %19 = icmp uge i64 %16, %18
  br i1 %19, label %20, label %34

20:                                               ; preds = %14
  %21 = load i64, ptr %5, align 8, !tbaa !11
  %22 = lshr i64 %21, 48
  %23 = load i32, ptr @MACR, align 4, !tbaa !13
  %24 = zext i32 %23 to i64
  %25 = icmp ule i64 %22, %24
  br i1 %25, label %26, label %34

26:                                               ; preds = %20
  %27 = load i64, ptr %5, align 8, !tbaa !11
  %28 = lshr i64 %27, 48
  %29 = load i32, ptr @PRIM, align 4, !tbaa !13
  %30 = zext i32 %29 to i64
  %31 = sub i64 %28, %30
  %32 = add i64 %31, 1
  %33 = uitofp i64 %32 to double
  br label %35

34:                                               ; preds = %20, %14
  br label %35

35:                                               ; preds = %34, %26
  %36 = phi double [ %33, %26 ], [ 0.000000e+00, %34 ]
  br label %37

37:                                               ; preds = %35, %13
  %38 = phi double [ -1.000000e+00, %13 ], [ %36, %35 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret double %38
}

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}


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

@PRIM = external dso_local local_unnamed_addr global i32, align 4
@MACR = external dso_local local_unnamed_addr global i32, align 4
@NIL = external dso_local local_unnamed_addr global i32, align 4

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

; Function Attrs: nounwind uwtable
define dso_local double @f_type(double noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = tail call double @car(double noundef %0)
  %4 = bitcast double %3 to i64
  %5 = lshr i64 %4, 48
  %6 = load i32, ptr @NIL, align 4, !tbaa !5
  %7 = zext i32 %6 to i64
  %8 = icmp eq i64 %5, %7
  br i1 %8, label %18, label %9

9:                                                ; preds = %2
  %10 = load i32, ptr @PRIM, align 4, !tbaa !5
  %11 = zext i32 %10 to i64
  %.not = icmp ult i64 %5, %11
  %12 = load i32, ptr @MACR, align 4
  %13 = zext i32 %12 to i64
  %.not5 = icmp ugt i64 %5, %13
  %or.cond = select i1 %.not, i1 true, i1 %.not5
  br i1 %or.cond, label %18, label %14

14:                                               ; preds = %9
  %15 = add nuw nsw i64 %5, 1
  %16 = sub nsw i64 %15, %11
  %17 = uitofp i64 %16 to double
  br label %18

18:                                               ; preds = %14, %9, %2
  %19 = phi double [ -1.000000e+00, %2 ], [ %17, %14 ], [ 0.000000e+00, %9 ]
  ret double %19
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass