; LLVM IR from b00dle/libpcc :: src/Measure.ll (ZN7Measure13colorErrorYuvERK3VecIfES3_)

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

%struct.Vec = type <{ ptr, float, float, float, [4 x i8] }>

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nounwind
declare double @sqrt(double noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN7Measure13colorErrorYuvERK3VecIfES3_(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef nonnull align 8 dereferenceable(20) %1) #2 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.Vec, align 8
  %6 = alloca %struct.Vec, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN7Encoder8rgbToYuvERK3VecIfE(ptr dead_on_unwind writable sret(%struct.Vec) align 8 %5, ptr noundef nonnull align 8 dereferenceable(20) %13)
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  invoke void @_ZN7Encoder8rgbToYuvERK3VecIfE(ptr dead_on_unwind writable sret(%struct.Vec) align 8 %6, ptr noundef nonnull align 8 dereferenceable(20) %14)
          to label %15 unwind label %58

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %16 = getelementptr inbounds %struct.Vec, ptr %5, i32 0, i32 1
  %17 = load float, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.Vec, ptr %6, i32 0, i32 1
  %19 = load float, ptr %18, align 8, !tbaa !9
  %20 = fsub float %17, %19
  %21 = getelementptr inbounds %struct.Vec, ptr %5, i32 0, i32 1
  %22 = load float, ptr %21, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.Vec, ptr %6, i32 0, i32 1
  %24 = load float, ptr %23, align 8, !tbaa !9
  %25 = fsub float %22, %24
  %26 = fmul float %20, %25
  store float %26, ptr %9, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %27 = getelementptr inbounds %struct.Vec, ptr %5, i32 0, i32 2
  %28 = load float, ptr %27, align 4, !tbaa !13
  %29 = getelementptr inbounds %struct.Vec, ptr %6, i32 0, i32 2
  %30 = load float, ptr %29, align 4, !tbaa !13
  %31 = fsub float %28, %30
  %32 = getelementptr inbounds %struct.Vec, ptr %5, i32 0, i32 2
  %33 = load float, ptr %32, align 4, !tbaa !13
  %34 = getelementptr inbounds %struct.Vec, ptr %6, i32 0, i32 2
  %35 = load float, ptr %34, align 4, !tbaa !13
  %36 = fsub float %33, %35
  %37 = fmul float %31, %36
  store float %37, ptr %10, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %38 = getelementptr inbounds %struct.Vec, ptr %5, i32 0, i32 3
  %39 = load float, ptr %38, align 8, !tbaa !14
  %40 = getelementptr inbounds %struct.Vec, ptr %6, i32 0, i32 3
  %41 = load float, ptr %40, align 8, !tbaa !14
  %42 = fsub float %39, %41
  %43 = getelementptr inbounds %struct.Vec, ptr %5, i32 0, i32 3
  %44 = load float, ptr %43, align 8, !tbaa !14
  %45 = getelementptr inbounds %struct.Vec, ptr %6, i32 0, i32 3
  %46 = load float, ptr %45, align 8, !tbaa !14
  %47 = fsub float %44, %46
  %48 = fmul float %42, %47
  store float %48, ptr %11, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %49 = load float, ptr %9, align 4, !tbaa !12
  %50 = load float, ptr %10, align 4, !tbaa !12
  %51 = fadd float %49, %50
  %52 = load float, ptr %11, align 4, !tbaa !12
  %53 = fadd float %51, %52
  %54 = fpext float %53 to double
  %55 = call double @sqrt(double noundef %54) #5
  %56 = fptrunc double %55 to float
  store float %56, ptr %12, align 4, !tbaa !12
  %57 = load float, ptr %12, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #5
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %5) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  ret float %57

58:                                               ; preds = %2
  %59 = landingpad { ptr, i32 }
          cleanup
  %60 = extractvalue { ptr, i32 } %59, 0
  store ptr %60, ptr %7, align 8
  %61 = extractvalue { ptr, i32 } %59, 1
  store i32 %61, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #5
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %5) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  br label %62

62:                                               ; preds = %58
  %63 = load ptr, ptr %7, align 8
  %64 = load i32, ptr %8, align 4
  %65 = insertvalue { ptr, i32 } poison, ptr %63, 0
  %66 = insertvalue { ptr, i32 } %65, i32 %64, 1
  resume { ptr, i32 } %66
}

declare void @_ZN7Encoder8rgbToYuvERK3VecIfE(ptr dead_on_unwind writable sret(%struct.Vec) align 8, ptr noundef nonnull align 8 dereferenceable(20)) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 = { 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 #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, !11, i64 8}
!10 = !{!"_ZTS3VecIfE", !11, i64 8, !11, i64 12, !11, i64 16}
!11 = !{!"float", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 12}
!14 = !{!10, !11, i64 16}


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

%struct.Vec = type <{ ptr, float, float, float, [4 x i8] }>

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

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN7Measure13colorErrorYuvERK3VecIfES3_(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef nonnull align 8 dereferenceable(20) %1) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %struct.Vec, align 8
  %4 = alloca %struct.Vec, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @_ZN7Encoder8rgbToYuvERK3VecIfE(ptr dead_on_unwind nonnull writable sret(%struct.Vec) align 8 %3, ptr noundef nonnull align 8 dereferenceable(20) %0)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #5
  invoke void @_ZN7Encoder8rgbToYuvERK3VecIfE(ptr dead_on_unwind nonnull writable sret(%struct.Vec) align 8 %4, ptr noundef nonnull align 8 dereferenceable(20) %1)
          to label %5 unwind label %30

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  %7 = load <4 x float>, ptr %6, align 8
  %8 = shufflevector <4 x float> %7, <4 x float> poison, <2 x i32> <i32 0, i32 poison>
  %9 = getelementptr inbounds i8, ptr %4, i64 8
  %10 = load <4 x float>, ptr %9, align 8
  %11 = shufflevector <4 x float> %10, <4 x float> poison, <2 x i32> <i32 0, i32 poison>
  %12 = getelementptr inbounds i8, ptr %3, i64 12
  %13 = load float, ptr %12, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %4, i64 12
  %15 = load float, ptr %14, align 4, !tbaa !5
  %16 = fsub float %13, %15
  %17 = fmul float %16, %16
  %18 = getelementptr inbounds i8, ptr %3, i64 16
  %19 = load float, ptr %18, align 8, !tbaa !10
  %20 = getelementptr inbounds i8, ptr %4, i64 16
  %21 = load float, ptr %20, align 8, !tbaa !10
  %22 = insertelement <2 x float> %8, float %19, i64 1
  %23 = insertelement <2 x float> %11, float %21, i64 1
  %24 = fsub <2 x float> %22, %23
  %25 = fmul <2 x float> %24, %24
  %26 = extractelement <2 x float> %25, i64 0
  %27 = fadd float %26, %17
  %28 = extractelement <2 x float> %25, i64 1
  %29 = fadd float %27, %28
  %sqrt = call float @llvm.sqrt.f32(float %29)
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %4) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %3) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  ret float %sqrt

30:                                               ; preds = %2
  %31 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #5
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %3) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  resume { ptr, i32 } %31
}

declare void @_ZN7Encoder8rgbToYuvERK3VecIfE(ptr dead_on_unwind writable sret(%struct.Vec) align 8, ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #3 align 2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 12}
!6 = !{!"_ZTS3VecIfE", !7, i64 8, !7, i64 12, !7, i64 16}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 16}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,VectorCombinePass