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

; 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 nounwind uwtable
declare dso_local void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN7Measure13colorErrorXyzERK3VecIfES3_(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef nonnull align 8 dereferenceable(20) %1) #3 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 %struct.Vec, align 8
  %10 = alloca %struct.Vec, align 8
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = 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
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN3VecIfEC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(20) %6, ptr noundef nonnull align 8 dereferenceable(20) %15)
  invoke void @_ZN7Encoder8rgbToXyzE3VecIfE(ptr dead_on_unwind writable sret(%struct.Vec) align 8 %5, ptr noundef %6)
          to label %16 unwind label %62

16:                                               ; preds = %2
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %6) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  invoke void @_ZN3VecIfEC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(20) %10, ptr noundef nonnull align 8 dereferenceable(20) %17)
          to label %18 unwind label %66

18:                                               ; preds = %16
  invoke void @_ZN7Encoder8rgbToXyzE3VecIfE(ptr dead_on_unwind writable sret(%struct.Vec) align 8 %9, ptr noundef %10)
          to label %19 unwind label %70

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

62:                                               ; preds = %2
  %63 = landingpad { ptr, i32 }
          cleanup
  %64 = extractvalue { ptr, i32 } %63, 0
  store ptr %64, ptr %7, align 8
  %65 = extractvalue { ptr, i32 } %63, 1
  store i32 %65, ptr %8, align 4
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %6) #5
  br label %75

66:                                               ; preds = %16
  %67 = landingpad { ptr, i32 }
          cleanup
  %68 = extractvalue { ptr, i32 } %67, 0
  store ptr %68, ptr %7, align 8
  %69 = extractvalue { ptr, i32 } %67, 1
  store i32 %69, ptr %8, align 4
  br label %74

70:                                               ; preds = %18
  %71 = landingpad { ptr, i32 }
          cleanup
  %72 = extractvalue { ptr, i32 } %71, 0
  store ptr %72, ptr %7, align 8
  %73 = extractvalue { ptr, i32 } %71, 1
  store i32 %73, ptr %8, align 4
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %10) #5
  br label %74

74:                                               ; preds = %70, %66
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #5
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %5) #5
  br label %75

75:                                               ; preds = %74, %62
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #5
  br label %76

76:                                               ; preds = %75
  %77 = load ptr, ptr %7, align 8
  %78 = load i32, ptr %8, align 4
  %79 = insertvalue { ptr, i32 } poison, ptr %77, 0
  %80 = insertvalue { ptr, i32 } %79, i32 %78, 1
  resume { ptr, i32 } %80
}

declare void @_ZN7Encoder8rgbToXyzE3VecIfE(ptr dead_on_unwind writable sret(%struct.Vec) align 8, ptr noundef) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3VecIfEC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #2 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 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 #3 = { 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 #4 = { "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 nounwind uwtable
declare dso_local void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #1 align 2

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

7:                                                ; preds = %2
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %4) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #5
  call void @_ZN3VecIfEC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(20) %6, ptr noundef nonnull align 8 dereferenceable(20) %1)
  invoke void @_ZN7Encoder8rgbToXyzE3VecIfE(ptr dead_on_unwind nonnull writable sret(%struct.Vec) align 8 %5, ptr noundef nonnull %6)
          to label %8 unwind label %35

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

33:                                               ; preds = %2
  %34 = landingpad { ptr, i32 }
          cleanup
  br label %37

35:                                               ; preds = %7
  %36 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #5
  br label %37

37:                                               ; preds = %35, %33
  %.sink = phi ptr [ %3, %35 ], [ %4, %33 ]
  %.pn = phi { ptr, i32 } [ %36, %35 ], [ %34, %33 ]
  call void @_ZN3VecIfED2Ev(ptr noundef nonnull align 8 dereferenceable(20) %.sink) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  resume { ptr, i32 } %.pn
}

declare void @_ZN7Encoder8rgbToXyzE3VecIfE(ptr dead_on_unwind writable sret(%struct.Vec) align 8, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3VecIfEC2ERKS0_(ptr noundef nonnull align 8 dereferenceable(20), ptr noundef nonnull align 8 dereferenceable(20)) unnamed_addr #1 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 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 = { 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 = { 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