; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind
declare double @cos(double noundef) #3

; Function Attrs: nounwind uwtable
define dso_local ptr @r8vec_cheby_extreme_new(i32 noundef %0, double noundef %1, double noundef %2) #4 {
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store double 0x400921FB54442D18, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = mul i64 %13, 8
  %15 = call noalias ptr @malloc(i64 noundef %14) #6
  store ptr %15, ptr %11, align 8, !tbaa !11
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp eq i32 %16, 1
  br i1 %17, label %18, label %25

18:                                               ; preds = %3
  %19 = load double, ptr %5, align 8, !tbaa !9
  %20 = load double, ptr %6, align 8, !tbaa !9
  %21 = fadd double %19, %20
  %22 = fdiv double %21, 2.000000e+00
  %23 = load ptr, ptr %11, align 8, !tbaa !11
  %24 = getelementptr inbounds double, ptr %23, i64 0
  store double %22, ptr %24, align 8, !tbaa !9
  br label %72

25:                                               ; preds = %3
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %68, %25
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %30, label %71

30:                                               ; preds = %26
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = sub nsw i32 %31, %32
  %34 = sub nsw i32 %33, 1
  %35 = sitofp i32 %34 to double
  %36 = fmul double %35, 0x400921FB54442D18
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sub nsw i32 %37, 1
  %39 = sitofp i32 %38 to double
  %40 = fdiv double %36, %39
  store double %40, ptr %10, align 8, !tbaa !9
  %41 = load double, ptr %10, align 8, !tbaa !9
  %42 = call double @cos(double noundef %41) #5
  store double %42, ptr %7, align 8, !tbaa !9
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = srem i32 %43, 2
  %45 = icmp eq i32 %44, 1
  br i1 %45, label %46, label %54

46:                                               ; preds = %30
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = mul nsw i32 2, %47
  %49 = add nsw i32 %48, 1
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = icmp eq i32 %49, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %46
  store double 0.000000e+00, ptr %7, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %52, %46
  br label %54

54:                                               ; preds = %53, %30
  %55 = load double, ptr %7, align 8, !tbaa !9
  %56 = fsub double 1.000000e+00, %55
  %57 = load double, ptr %5, align 8, !tbaa !9
  %58 = load double, ptr %7, align 8, !tbaa !9
  %59 = fadd double 1.000000e+00, %58
  %60 = load double, ptr %6, align 8, !tbaa !9
  %61 = fmul double %59, %60
  %62 = call double @llvm.fmuladd.f64(double %56, double %57, double %61)
  %63 = fdiv double %62, 2.000000e+00
  %64 = load ptr, ptr %11, align 8, !tbaa !11
  %65 = load i32, ptr %8, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds double, ptr %64, i64 %66
  store double %63, ptr %67, align 8, !tbaa !9
  br label %68

68:                                               ; preds = %54
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %8, align 4, !tbaa !5
  br label %26, !llvm.loop !13

71:                                               ; preds = %26
  br label %72

72:                                               ; preds = %71, %18
  %73 = load ptr, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret ptr %73
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nounwind allocsize(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 #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind memory(write, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @r8vec_cheby_extreme_new(i32 noundef %0, double noundef %1, double noundef %2) local_unnamed_addr #3 {
  %4 = sext i32 %0 to i64
  %5 = shl nsw i64 %4, 3
  %6 = tail call noalias ptr @malloc(i64 noundef %5) #4
  %7 = icmp eq i32 %0, 1
  br i1 %7, label %28, label %.preheader

.preheader:                                       ; preds = %3
  %8 = icmp sgt i32 %0, 0
  br i1 %8, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %9 = add nsw i32 %0, -1
  %10 = uitofp nneg i32 %9 to double
  %11 = and i32 %0, 1
  %.not = icmp eq i32 %11, 0
  %wide.trip.count29 = zext nneg i32 %0 to i64
  br i1 %.not, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph, %.lr.ph.split.us
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph.split.us ], [ 0, %.lr.ph ]
  %12 = trunc nuw nsw i64 %indvars.iv to i32
  %13 = xor i32 %12, -1
  %14 = add nsw i32 %13, %0
  %15 = sitofp i32 %14 to double
  %16 = fmul double %15, 0x400921FB54442D18
  %17 = fdiv double %16, %10
  %18 = tail call double @cos(double noundef %17) #5
  %19 = shl nuw nsw i64 %indvars.iv, 1
  %20 = or disjoint i64 %19, 1
  %21 = icmp eq i64 %20, %wide.trip.count29
  %.0.us = select i1 %21, double 0.000000e+00, double %18
  %22 = fsub double 1.000000e+00, %.0.us
  %23 = fadd double %.0.us, 1.000000e+00
  %24 = fmul double %23, %2
  %25 = tail call double @llvm.fmuladd.f64(double %22, double %1, double %24)
  %26 = fmul double %25, 5.000000e-01
  %27 = getelementptr inbounds double, ptr %6, i64 %indvars.iv
  store double %26, ptr %27, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count29
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph.split.us, !llvm.loop !9

28:                                               ; preds = %3
  %29 = fadd double %1, %2
  %30 = fmul double %29, 5.000000e-01
  store double %30, ptr %6, align 8, !tbaa !5
  br label %.loopexit

.lr.ph.split:                                     ; preds = %.lr.ph, %.lr.ph.split
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %.lr.ph.split ], [ 0, %.lr.ph ]
  %31 = trunc nuw nsw i64 %indvars.iv26 to i32
  %32 = xor i32 %31, -1
  %33 = add nsw i32 %32, %0
  %34 = sitofp i32 %33 to double
  %35 = fmul double %34, 0x400921FB54442D18
  %36 = fdiv double %35, %10
  %37 = tail call double @cos(double noundef %36) #5
  %38 = fsub double 1.000000e+00, %37
  %39 = fadd double %37, 1.000000e+00
  %40 = fmul double %39, %2
  %41 = tail call double @llvm.fmuladd.f64(double %38, double %1, double %40)
  %42 = fmul double %41, 5.000000e-01
  %43 = getelementptr inbounds double, ptr %6, i64 %indvars.iv26
  store double %42, ptr %43, align 8, !tbaa !5
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %exitcond30.not = icmp eq i64 %indvars.iv.next27, %wide.trip.count29
  br i1 %exitcond30.not, label %.loopexit, label %.lr.ph.split, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph.split.us, %.lr.ph.split, %.preheader, %28
  ret ptr %6
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn memory(write) "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 = { nofree nounwind memory(write, inaccessiblemem: readwrite) 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 #4 = { nounwind allocsize(0) }
attributes #5 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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