; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (r8lib)

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

; 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 void @r8vec_heap_d(i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @r8vec_sort_heap_a(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp sle i32 %8, 1
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store i32 1, ptr %7, align 4
  br label %60

11:                                               ; preds = %2
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !9
  call void @r8vec_heap_d(i32 noundef %12, ptr noundef %13)
  %14 = load ptr, ptr %4, align 8, !tbaa !9
  %15 = getelementptr inbounds double, ptr %14, i64 0
  %16 = load double, ptr %15, align 8, !tbaa !11
  store double %16, ptr %6, align 8, !tbaa !11
  %17 = load ptr, ptr %4, align 8, !tbaa !9
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sub nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %17, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds double, ptr %23, i64 0
  store double %22, ptr %24, align 8, !tbaa !11
  %25 = load double, ptr %6, align 8, !tbaa !11
  %26 = load ptr, ptr %4, align 8, !tbaa !9
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sub nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %26, i64 %29
  store double %25, ptr %30, align 8, !tbaa !11
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  store i32 %32, ptr %5, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %56, %11
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = icmp sle i32 2, %34
  br i1 %35, label %36, label %59

36:                                               ; preds = %33
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !9
  call void @r8vec_heap_d(i32 noundef %37, ptr noundef %38)
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  %40 = getelementptr inbounds double, ptr %39, i64 0
  %41 = load double, ptr %40, align 8, !tbaa !11
  store double %41, ptr %6, align 8, !tbaa !11
  %42 = load ptr, ptr %4, align 8, !tbaa !9
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sub nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %42, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !11
  %48 = load ptr, ptr %4, align 8, !tbaa !9
  %49 = getelementptr inbounds double, ptr %48, i64 0
  store double %47, ptr %49, align 8, !tbaa !11
  %50 = load double, ptr %6, align 8, !tbaa !11
  %51 = load ptr, ptr %4, align 8, !tbaa !9
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sub nsw i32 %52, 1
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %51, i64 %54
  store double %50, ptr %55, align 8, !tbaa !11
  br label %56

56:                                               ; preds = %36
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = add nsw i32 %57, -1
  store i32 %58, ptr %5, align 4, !tbaa !5
  br label %33, !llvm.loop !13

59:                                               ; preds = %33
  store i32 1, ptr %7, align 4
  br label %60

60:                                               ; preds = %59, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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 = !{!"int", !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 = !{!"double", !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"

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

; Function Attrs: nounwind uwtable
define dso_local void @r8vec_sort_heap_a(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp slt i32 %0, 2
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %2
  tail call void @r8vec_heap_d(i32 noundef %0, ptr noundef %1)
  %5 = load double, ptr %1, align 8, !tbaa !5
  %6 = add nsw i32 %0, -1
  %7 = zext nneg i32 %6 to i64
  %8 = getelementptr inbounds double, ptr %1, i64 %7
  %9 = load double, ptr %8, align 8, !tbaa !5
  store double %9, ptr %1, align 8, !tbaa !5
  store double %5, ptr %8, align 8, !tbaa !5
  %invariant.gep = getelementptr i8, ptr %1, i64 -8
  %.not = icmp eq i32 %0, 2
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %7, %4 ]
  %10 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @r8vec_heap_d(i32 noundef %10, ptr noundef nonnull %1)
  %11 = load double, ptr %1, align 8, !tbaa !5
  %gep = getelementptr double, ptr %invariant.gep, i64 %indvars.iv
  %12 = load double, ptr %gep, align 8, !tbaa !5
  store double %12, ptr %1, align 8, !tbaa !5
  store double %11, ptr %gep, align 8, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %13 = icmp ugt i64 %indvars.iv, 2
  br i1 %13, label %.lr.ph, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph, %4, %2
  ret void
}

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


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