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

; 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 i64, align 8
@hp = external dso_local global i64, align 8
@cell = external dso_local global ptr, align 8

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

4:                                                ; preds = %18, %1
  %5 = load i64, ptr %3, align 8, !tbaa !9
  %6 = load i64, ptr @hp, align 8, !tbaa !9
  %7 = icmp ult i64 %5, %6
  br i1 %7, label %8, label %16

8:                                                ; preds = %4
  %9 = load ptr, ptr @cell, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 4
  %11 = load i64, ptr %3, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %10, i64 %11
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call i32 @strcmp(ptr noundef %12, ptr noundef %13) #4
  %15 = icmp ne i32 %14, 0
  br label %16

16:                                               ; preds = %8, %4
  %17 = phi i1 [ false, %4 ], [ %15, %8 ]
  br i1 %17, label %18, label %27

18:                                               ; preds = %16
  %19 = load ptr, ptr @cell, align 8, !tbaa !5
  %20 = load i64, ptr %3, align 8, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %19, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = add i64 4, %23
  %25 = load i64, ptr %3, align 8, !tbaa !9
  %26 = add i64 %25, %24
  store i64 %26, ptr %3, align 8, !tbaa !9
  br label %4, !llvm.loop !13

27:                                               ; preds = %16
  %28 = load i64, ptr %3, align 8, !tbaa !9
  %29 = load i64, ptr @hp, align 8, !tbaa !9
  %30 = icmp ult i64 %28, %29
  br i1 %30, label %31, label %36

31:                                               ; preds = %27
  %32 = load i64, ptr @ATOM, align 8, !tbaa !9
  %33 = load i64, ptr %3, align 8, !tbaa !9
  %34 = add i64 4, %33
  %35 = call double @box(i64 noundef %32, i64 noundef %34)
  br label %40

36:                                               ; preds = %27
  %37 = load i64, ptr @ATOM, align 8, !tbaa !9
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = call double @dup(i64 noundef %37, ptr noundef %38)
  br label %40

40:                                               ; preds = %36, %31
  %41 = phi double [ %35, %31 ], [ %39, %36 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret double %41
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind willreturn memory(read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 i64, align 8
@hp = external dso_local local_unnamed_addr global i64, align 8
@cell = external dso_local local_unnamed_addr global ptr, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local double @atom(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i64, ptr @hp, align 8, !tbaa !5
  %.not9 = icmp eq i64 %2, 0
  br i1 %.not9, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %3 = load ptr, ptr @cell, align 8, !tbaa !9
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  br label %5

5:                                                ; preds = %.lr.ph, %8
  %.08 = phi i64 [ 0, %.lr.ph ], [ %13, %8 ]
  %6 = getelementptr inbounds i8, ptr %4, i64 %.08
  %7 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %6, ptr noundef nonnull dereferenceable(1) %0) #2
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %15, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %3, i64 %.08
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = sext i32 %10 to i64
  %12 = add i64 %.08, 4
  %13 = add i64 %12, %11
  %14 = icmp ult i64 %13, %2
  br i1 %14, label %5, label %.critedge, !llvm.loop !13

15:                                               ; preds = %5
  %16 = load i64, ptr @ATOM, align 8, !tbaa !5
  %17 = add i64 %.08, 4
  %18 = tail call double @box(i64 noundef %16, i64 noundef %17)
  br label %21

.critedge:                                        ; preds = %8, %1
  %19 = load i64, ptr @ATOM, align 8, !tbaa !5
  %20 = tail call double @dup(i64 noundef %19, ptr noundef %0)
  br label %21

21:                                               ; preds = %.critedge, %15
  %22 = phi double [ %18, %15 ], [ %20, %.critedge ]
  ret double %22
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #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 nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }

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


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