; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: Numbers/Complex_numbers.ll (ZN7complex6divideES_S_)

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

%class.complex = type { float, float }

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7complex6divideES_S_(ptr noundef nonnull align 4 dereferenceable(8) %0, <2 x float> %1, <2 x float> %2) #1 align 2 {
  %4 = alloca %class.complex, align 4
  %5 = alloca %class.complex, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  store <2 x float> %1, ptr %4, align 4
  store <2 x float> %2, ptr %5, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %11 = getelementptr inbounds %class.complex, ptr %5, i32 0, i32 0
  %12 = load float, ptr %11, align 4, !tbaa !9
  %13 = getelementptr inbounds %class.complex, ptr %5, i32 0, i32 0
  %14 = load float, ptr %13, align 4, !tbaa !9
  %15 = getelementptr inbounds %class.complex, ptr %5, i32 0, i32 1
  %16 = load float, ptr %15, align 4, !tbaa !12
  %17 = getelementptr inbounds %class.complex, ptr %5, i32 0, i32 1
  %18 = load float, ptr %17, align 4, !tbaa !12
  %19 = fmul float %16, %18
  %20 = call float @llvm.fmuladd.f32(float %12, float %14, float %19)
  %21 = fptosi float %20 to i32
  store i32 %21, ptr %7, align 4, !tbaa !13
  %22 = getelementptr inbounds %class.complex, ptr %4, i32 0, i32 0
  %23 = load float, ptr %22, align 4, !tbaa !9
  %24 = getelementptr inbounds %class.complex, ptr %5, i32 0, i32 0
  %25 = load float, ptr %24, align 4, !tbaa !9
  %26 = getelementptr inbounds %class.complex, ptr %4, i32 0, i32 1
  %27 = load float, ptr %26, align 4, !tbaa !12
  %28 = getelementptr inbounds %class.complex, ptr %5, i32 0, i32 1
  %29 = load float, ptr %28, align 4, !tbaa !12
  %30 = fmul float %27, %29
  %31 = fmul float %30, -1.000000e+00
  %32 = fneg float %31
  %33 = call float @llvm.fmuladd.f32(float %23, float %25, float %32)
  %34 = getelementptr inbounds %class.complex, ptr %10, i32 0, i32 0
  store float %33, ptr %34, align 4, !tbaa !9
  %35 = getelementptr inbounds %class.complex, ptr %4, i32 0, i32 0
  %36 = load float, ptr %35, align 4, !tbaa !9
  %37 = getelementptr inbounds %class.complex, ptr %5, i32 0, i32 1
  %38 = load float, ptr %37, align 4, !tbaa !12
  %39 = fmul float %36, %38
  %40 = getelementptr inbounds %class.complex, ptr %4, i32 0, i32 1
  %41 = load float, ptr %40, align 4, !tbaa !12
  %42 = getelementptr inbounds %class.complex, ptr %5, i32 0, i32 0
  %43 = load float, ptr %42, align 4, !tbaa !9
  %44 = fmul float %41, %43
  %45 = call float @llvm.fmuladd.f32(float %39, float -1.000000e+00, float %44)
  %46 = getelementptr inbounds %class.complex, ptr %10, i32 0, i32 1
  store float %45, ptr %46, align 4, !tbaa !12
  %47 = getelementptr inbounds %class.complex, ptr %10, i32 0, i32 0
  %48 = load float, ptr %47, align 4, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !13
  %50 = sitofp i32 %49 to float
  %51 = fdiv float %48, %50
  %52 = getelementptr inbounds %class.complex, ptr %10, i32 0, i32 0
  store float %51, ptr %52, align 4, !tbaa !9
  %53 = getelementptr inbounds %class.complex, ptr %10, i32 0, i32 1
  %54 = load float, ptr %53, align 4, !tbaa !12
  %55 = load i32, ptr %7, align 4, !tbaa !13
  %56 = sitofp i32 %55 to float
  %57 = fdiv float %54, %56
  %58 = getelementptr inbounds %class.complex, ptr %10, i32 0, i32 1
  store float %57, ptr %58, align 4, !tbaa !12
  call void @_ZN7complex7displayEv(ptr noundef nonnull align 4 dereferenceable(8) %10)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7complex7displayEv(ptr noundef nonnull align 4 dereferenceable(8)) #2 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress uwtable "min-legal-vector-width"="64" "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"="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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS7complex", !11, i64 0, !11, i64 4}
!11 = !{!"float", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}


; 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 uwtable
define dso_local void @_ZN7complex6divideES_S_(ptr noundef nonnull align 4 dereferenceable(8) %0, <2 x float> %1, <2 x float> %2) local_unnamed_addr #0 align 2 {
  %4 = extractelement <2 x float> %2, i64 1
  %5 = extractelement <2 x float> %2, i64 0
  %6 = fmul float %4, %4
  %7 = tail call float @llvm.fmuladd.f32(float %5, float %5, float %6)
  %8 = fptosi float %7 to i32
  %.sroa.014.0.vec.extract = extractelement <2 x float> %1, i64 0
  %9 = fmul float %.sroa.014.0.vec.extract, %4
  %10 = sitofp i32 %8 to float
  %11 = shufflevector <2 x float> %1, <2 x float> poison, <2 x i32> <i32 1, i32 1>
  %12 = fmul <2 x float> %11, %2
  %13 = shufflevector <2 x float> %1, <2 x float> poison, <2 x i32> <i32 poison, i32 0>
  %14 = insertelement <2 x float> %13, float %9, i64 0
  %15 = shufflevector <2 x float> %2, <2 x float> <float -1.000000e+00, float poison>, <2 x i32> <i32 2, i32 0>
  %16 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %14, <2 x float> %15, <2 x float> %12)
  %17 = insertelement <2 x float> poison, float %10, i64 0
  %18 = shufflevector <2 x float> %17, <2 x float> poison, <2 x i32> zeroinitializer
  %19 = fdiv <2 x float> %16, %18
  %20 = shufflevector <2 x float> %19, <2 x float> poison, <2 x i32> <i32 1, i32 0>
  store <2 x float> %20, ptr %0, align 4, !tbaa !5
  tail call void @_ZN7complex7displayEv(ptr noundef nonnull align 4 dereferenceable(8) %0)
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7complex7displayEv(ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x float> @llvm.fmuladd.v2f32(<2 x float>, <2 x float>, <2 x float>) #3

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="64" "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 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass