; LLVM IR from kobalicek/simdtests :: trigo/trigo_sse2.ll (Z19trigo_vsin_vml_sse2PdPKdm)

; 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: alwaysinline mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN9SimdUtilsL9isAlignedIPdEEbT_j(ptr noundef, i32 noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <2 x double> @_ZL11_mm_load_sdPKd(ptr noundef) #2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden void @_ZL12_mm_store_sdPdDv2_d(ptr noundef, <2 x double> noundef) #2

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

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <2 x double> @_ZL12_mm_loadu_pdPKd(ptr noundef) #2

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden void @_ZL12_mm_store_pdPdDv2_d(ptr noundef, <2 x double> noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z19trigo_vsin_vml_sse2PdPKdm(ptr noundef %0, ptr noundef %1, i64 noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca <2 x double>, align 16
  %9 = alloca i32, align 4
  %10 = alloca <2 x double>, align 16
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %11 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %11, ptr %7, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %55, %3
  %13 = load i64, ptr %7, align 8, !tbaa !9
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %15, label %56

15:                                               ; preds = %12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call noundef zeroext i1 @_ZN9SimdUtilsL9isAlignedIPdEEbT_j(ptr noundef %16, i32 noundef 16)
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = load i64, ptr %7, align 8, !tbaa !9
  %20 = icmp eq i64 %19, 1
  br i1 %20, label %21, label %39

21:                                               ; preds = %18, %15
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call noundef <2 x double> @_ZL11_mm_load_sdPKd(ptr noundef %22)
  store <2 x double> %23, ptr %8, align 16, !tbaa !11
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load <2 x double>, ptr %8, align 16, !tbaa !11
  %26 = call noundef <2 x double> @_ZL10sin_vml_pdDv2_d(<2 x double> noundef %25)
  call void @_ZL12_mm_store_sdPdDv2_d(ptr noundef %24, <2 x double> noundef %26)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds double, ptr %27, i32 1
  store ptr %28, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %29, i32 1
  store ptr %30, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = add i64 %31, -1
  store i64 %32, ptr %7, align 8, !tbaa !9
  %33 = icmp eq i64 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %21
  store i32 3, ptr %9, align 4
  br label %36

35:                                               ; preds = %21
  store i32 0, ptr %9, align 4
  br label %36

36:                                               ; preds = %35, %34
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #5
  %37 = load i32, ptr %9, align 4
  switch i32 %37, label %57 [
    i32 0, label %38
    i32 3, label %56
  ]

38:                                               ; preds = %36
  br label %39

39:                                               ; preds = %38, %18
  br label %40

40:                                               ; preds = %43, %39
  %41 = load i64, ptr %7, align 8, !tbaa !9
  %42 = icmp uge i64 %41, 2
  br i1 %42, label %43, label %55

43:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #5
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = call noundef <2 x double> @_ZL12_mm_loadu_pdPKd(ptr noundef %44)
  store <2 x double> %45, ptr %10, align 16, !tbaa !11
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load <2 x double>, ptr %10, align 16, !tbaa !11
  %48 = call noundef <2 x double> @_ZL10sin_vml_pdDv2_d(<2 x double> noundef %47)
  call void @_ZL12_mm_store_pdPdDv2_d(ptr noundef %46, <2 x double> noundef %48)
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds double, ptr %49, i64 2
  store ptr %50, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds double, ptr %51, i64 2
  store ptr %52, ptr %5, align 8, !tbaa !5
  %53 = load i64, ptr %7, align 8, !tbaa !9
  %54 = sub i64 %53, 2
  store i64 %54, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #5
  br label %40, !llvm.loop !12

55:                                               ; preds = %40
  br label %12, !llvm.loop !14

56:                                               ; preds = %36, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret void

57:                                               ; preds = %36
  unreachable
}

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden noundef <2 x double> @_ZL10sin_vml_pdDv2_d(<2 x double> noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline mustprogress 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 = { alwaysinline mustprogress nounwind uwtable "min-legal-vector-width"="128" "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 = { mustprogress uwtable "min-legal-vector-width"="128" "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 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="128" "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 }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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: alwaysinline mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN9SimdUtilsL9isAlignedIPdEEbT_j(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <2 x double> @_ZL11_mm_load_sdPKd(ptr noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden void @_ZL12_mm_store_sdPdDv2_d(ptr noundef, <2 x double> noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef <2 x double> @_ZL12_mm_loadu_pdPKd(ptr noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden void @_ZL12_mm_store_pdPdDv2_d(ptr noundef, <2 x double> noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z19trigo_vsin_vml_sse2PdPKdm(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #2 {
  %.not2532 = icmp eq i64 %2, 0
  br i1 %.not2532, label %._crit_edge, label %.lr.ph36

.loopexit:                                        ; preds = %.lr.ph, %11
  %.224.lcssa = phi i64 [ 1, %11 ], [ %18, %.lr.ph ]
  %.221.lcssa = phi ptr [ %12, %11 ], [ %17, %.lr.ph ]
  %.2.lcssa = phi ptr [ %13, %11 ], [ %16, %.lr.ph ]
  %.not25 = icmp eq i64 %.224.lcssa, 0
  br i1 %.not25, label %._crit_edge, label %.lr.ph36, !llvm.loop !5

.lr.ph36:                                         ; preds = %3, %.loopexit
  %.035 = phi ptr [ %.2.lcssa, %.loopexit ], [ %0, %3 ]
  %.01934 = phi ptr [ %.221.lcssa, %.loopexit ], [ %1, %3 ]
  %.02233 = phi i64 [ 1, %.loopexit ], [ %2, %3 ]
  %4 = tail call noundef zeroext i1 @_ZN9SimdUtilsL9isAlignedIPdEEbT_j(ptr noundef %.035, i32 noundef 16)
  %5 = icmp ne i64 %.02233, 1
  %or.cond.not = and i1 %5, %4
  br i1 %or.cond.not, label %.lr.ph.preheader, label %6

6:                                                ; preds = %.lr.ph36
  %7 = tail call noundef <2 x double> @_ZL11_mm_load_sdPKd(ptr noundef %.01934)
  %8 = tail call noundef <2 x double> @_ZL10sin_vml_pdDv2_d(<2 x double> noundef %7)
  tail call void @_ZL12_mm_store_sdPdDv2_d(ptr noundef %.035, <2 x double> noundef %8)
  %9 = add i64 %.02233, -1
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %._crit_edge, label %11

11:                                               ; preds = %6
  %12 = getelementptr inbounds i8, ptr %.01934, i64 8
  %13 = getelementptr inbounds i8, ptr %.035, i64 8
  %.not = icmp eq i64 %9, 1
  br i1 %.not, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph36, %11
  %.229.ph = phi ptr [ %.035, %.lr.ph36 ], [ %13, %11 ]
  %.22128.ph = phi ptr [ %.01934, %.lr.ph36 ], [ %12, %11 ]
  %.22427.ph = phi i64 [ %.02233, %.lr.ph36 ], [ %9, %11 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.229 = phi ptr [ %16, %.lr.ph ], [ %.229.ph, %.lr.ph.preheader ]
  %.22128 = phi ptr [ %17, %.lr.ph ], [ %.22128.ph, %.lr.ph.preheader ]
  %.22427 = phi i64 [ %18, %.lr.ph ], [ %.22427.ph, %.lr.ph.preheader ]
  %14 = tail call noundef <2 x double> @_ZL12_mm_loadu_pdPKd(ptr noundef %.22128)
  %15 = tail call noundef <2 x double> @_ZL10sin_vml_pdDv2_d(<2 x double> noundef %14)
  tail call void @_ZL12_mm_store_pdPdDv2_d(ptr noundef %.229, <2 x double> noundef %15)
  %16 = getelementptr inbounds i8, ptr %.229, i64 16
  %17 = getelementptr inbounds i8, ptr %.22128, i64 16
  %18 = add i64 %.22427, -2
  %19 = icmp ugt i64 %18, 1
  br i1 %19, label %.lr.ph, label %.loopexit, !llvm.loop !7

._crit_edge:                                      ; preds = %.loopexit, %6, %3
  ret void
}

; Function Attrs: alwaysinline mustprogress uwtable
declare hidden noundef <2 x double> @_ZL10sin_vml_pdDv2_d(<2 x double> noundef) local_unnamed_addr #3

attributes #0 = { alwaysinline mustprogress 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 = { alwaysinline mustprogress nounwind uwtable "min-legal-vector-width"="128" "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 uwtable "min-legal-vector-width"="128" "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 = { alwaysinline mustprogress uwtable "min-legal-vector-width"="128" "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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