; LLVM IR from siavashserver/neonrvm :: example (sinc)

; 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: nounwind uwtable
define dso_local void @sinc(i64 noundef %0, double noundef %1, double noundef %2, double noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca i64, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca double, align 8
  %14 = alloca i64, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  store i64 %0, ptr %7, align 8, !tbaa !5
  store double %1, ptr %8, align 8, !tbaa !9
  store double %2, ptr %9, align 8, !tbaa !9
  store double %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !11
  store ptr %5, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store double 0x400921FB54442D18, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %67, %6
  %19 = load i64, ptr %14, align 8, !tbaa !5
  %20 = load i64, ptr %7, align 8, !tbaa !5
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %70

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %24 = load double, ptr %8, align 8, !tbaa !9
  %25 = fneg double %24
  %26 = load i64, ptr %14, align 8, !tbaa !5
  %27 = uitofp i64 %26 to double
  %28 = load double, ptr %8, align 8, !tbaa !9
  %29 = fmul double 2.000000e+00, %28
  %30 = load i64, ptr %7, align 8, !tbaa !5
  %31 = uitofp i64 %30 to double
  %32 = fdiv double %29, %31
  %33 = call double @llvm.fmuladd.f64(double %27, double %32, double %25)
  store double %33, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %34 = load double, ptr %15, align 8, !tbaa !9
  %35 = fcmp oeq double %34, 0.000000e+00
  br i1 %35, label %36, label %37

36:                                               ; preds = %23
  br label %46

37:                                               ; preds = %23
  %38 = load double, ptr %13, align 8, !tbaa !9
  %39 = load double, ptr %15, align 8, !tbaa !9
  %40 = fmul double %38, %39
  %41 = call double @sin(double noundef %40) #4
  %42 = load double, ptr %13, align 8, !tbaa !9
  %43 = load double, ptr %15, align 8, !tbaa !9
  %44 = fmul double %42, %43
  %45 = fdiv double %41, %44
  br label %46

46:                                               ; preds = %37, %36
  %47 = phi double [ 1.000000e+00, %36 ], [ %45, %37 ]
  store double %47, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %48 = load i64, ptr %14, align 8, !tbaa !5
  %49 = urem i64 %48, 2
  %50 = icmp eq i64 %49, 0
  %51 = zext i1 %50 to i64
  %52 = select i1 %50, double 1.000000e+00, double -1.000000e+00
  store double %52, ptr %17, align 8, !tbaa !9
  %53 = load double, ptr %9, align 8, !tbaa !9
  %54 = load double, ptr %16, align 8, !tbaa !9
  %55 = load double, ptr %10, align 8, !tbaa !9
  %56 = load double, ptr %17, align 8, !tbaa !9
  %57 = fmul double %55, %56
  %58 = call double @llvm.fmuladd.f64(double %53, double %54, double %57)
  store double %58, ptr %16, align 8, !tbaa !9
  %59 = load double, ptr %15, align 8, !tbaa !9
  %60 = load ptr, ptr %11, align 8, !tbaa !11
  %61 = load i64, ptr %14, align 8, !tbaa !5
  %62 = getelementptr inbounds double, ptr %60, i64 %61
  store double %59, ptr %62, align 8, !tbaa !9
  %63 = load double, ptr %16, align 8, !tbaa !9
  %64 = load ptr, ptr %12, align 8, !tbaa !11
  %65 = load i64, ptr %14, align 8, !tbaa !5
  %66 = getelementptr inbounds double, ptr %64, i64 %65
  store double %63, ptr %66, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %67

67:                                               ; preds = %46
  %68 = load i64, ptr %14, align 8, !tbaa !5
  %69 = add i64 %68, 1
  store i64 %69, ptr %14, align 8, !tbaa !5
  br label %18, !llvm.loop !13

70:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  ret void
}

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 }

!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 = !{!"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: nofree nounwind memory(write) uwtable
define dso_local void @sinc(i64 noundef %0, double noundef %1, double noundef %2, double noundef %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %7 = fneg double %1
  %8 = fmul double %1, 2.000000e+00
  %9 = uitofp i64 %0 to double
  %10 = fdiv double %8, %9
  %11 = fneg double %3
  br label %12

._crit_edge:                                      ; preds = %20, %6
  ret void

12:                                               ; preds = %.lr.ph, %20
  %.024 = phi i64 [ 0, %.lr.ph ], [ %28, %20 ]
  %13 = uitofp i64 %.024 to double
  %14 = tail call double @llvm.fmuladd.f64(double %13, double %10, double %7)
  %15 = fcmp oeq double %14, 0.000000e+00
  br i1 %15, label %20, label %16

16:                                               ; preds = %12
  %17 = fmul double %14, 0x400921FB54442D18
  %18 = tail call double @sin(double noundef %17) #3
  %19 = fdiv double %18, %17
  br label %20

20:                                               ; preds = %12, %16
  %21 = phi double [ %19, %16 ], [ 1.000000e+00, %12 ]
  %22 = and i64 %.024, 1
  %23 = icmp eq i64 %22, 0
  %24 = select i1 %23, double %3, double %11
  %25 = tail call double @llvm.fmuladd.f64(double %2, double %21, double %24)
  %26 = getelementptr inbounds double, ptr %4, i64 %.024
  store double %14, ptr %26, align 8, !tbaa !5
  %27 = getelementptr inbounds double, ptr %5, i64 %.024
  store double %25, ptr %27, align 8, !tbaa !5
  %28 = add nuw i64 %.024, 1
  %exitcond.not = icmp eq i64 %28, %0
  br i1 %exitcond.not, label %._crit_edge, label %12, !llvm.loop !9
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

attributes #0 = { nofree nounwind memory(write) 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 nosync nounwind speculatable willreturn memory(none) }
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 = { 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,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass