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

; 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

declare void @_ZN7Encoder8rgbToYuvERK3VecIfE(ptr dead_on_unwind writable sret(%struct.Vec) align 8, ptr noundef nonnull align 8 dereferenceable(20)) #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: mustprogress uwtable
define dso_local noundef float @_ZN7Measure21colorErrorYuvWithoutYERK3VecIfES3_(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef nonnull align 8 dereferenceable(20) %1) #4 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
  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
  %12 = 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) %12)
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #5
  %13 = 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) %13)
          to label %14 unwind label %44

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %15 = getelementptr inbounds %struct.Vec, ptr %5, i32 0, i32 2
  %16 = load float, ptr %15, align 4, !tbaa !9
  %17 = getelementptr inbounds %struct.Vec, ptr %6, i32 0, i32 2
  %18 = load float, ptr %17, align 4, !tbaa !9
  %19 = fsub float %16, %18
  %20 = getelementptr inbounds %struct.Vec, ptr %5, i32 0, i32 2
  %21 = load float, ptr %20, align 4, !tbaa !9
  %22 = getelementptr inbounds %struct.Vec, ptr %6, i32 0, i32 2
  %23 = load float, ptr %22, align 4, !tbaa !9
  %24 = fsub float %21, %23
  %25 = fmul float %19, %24
  store float %25, ptr %9, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %26 = getelementptr inbounds %struct.Vec, ptr %5, i32 0, i32 3
  %27 = load float, ptr %26, align 8, !tbaa !13
  %28 = getelementptr inbounds %struct.Vec, ptr %6, i32 0, i32 3
  %29 = load float, ptr %28, align 8, !tbaa !13
  %30 = fsub float %27, %29
  %31 = getelementptr inbounds %struct.Vec, ptr %5, i32 0, i32 3
  %32 = load float, ptr %31, align 8, !tbaa !13
  %33 = getelementptr inbounds %struct.Vec, ptr %6, i32 0, i32 3
  %34 = load float, ptr %33, align 8, !tbaa !13
  %35 = fsub float %32, %34
  %36 = fmul float %30, %35
  store float %36, ptr %10, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %37 = load float, ptr %9, align 4, !tbaa !12
  %38 = load float, ptr %10, align 4, !tbaa !12
  %39 = fadd float %37, %38
  %40 = fpext float %39 to double
  %41 = call double @sqrt(double noundef %40) #5
  %42 = fptrunc double %41 to float
  store float %42, ptr %11, align 4, !tbaa !12
  %43 = load float, ptr %11, align 4, !tbaa !12
  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 %43

44:                                               ; preds = %2
  %45 = landingpad { ptr, i32 }
          cleanup
  %46 = extractvalue { ptr, i32 } %45, 0
  store ptr %46, ptr %7, align 8
  %47 = extractvalue { ptr, i32 } %45, 1
  store i32 %47, 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 %48

48:                                               ; preds = %44
  %49 = load ptr, ptr %7, align 8
  %50 = load i32, ptr %8, align 4
  %51 = insertvalue { ptr, i32 } poison, ptr %49, 0
  %52 = insertvalue { ptr, i32 } %51, i32 %50, 1
  resume { ptr, i32 } %52
}

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 = { "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 = { 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 #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 12}
!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 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(...)

declare void @_ZN7Encoder8rgbToYuvERK3VecIfE(ptr dead_on_unwind writable sret(%struct.Vec) align 8, ptr noundef nonnull align 8 dereferenceable(20)) local_unnamed_addr #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 @_ZN7Measure21colorErrorYuvWithoutYERK3VecIfES3_(ptr noundef nonnull align 8 dereferenceable(20) %0, ptr noundef nonnull align 8 dereferenceable(20) %1) local_unnamed_addr #3 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 %14

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %3, i64 12
  %7 = getelementptr inbounds i8, ptr %4, i64 12
  %8 = load <2 x float>, ptr %6, align 4, !tbaa !5
  %9 = load <2 x float>, ptr %7, align 4, !tbaa !5
  %10 = fsub <2 x float> %8, %9
  %11 = fmul <2 x float> %10, %10
  %shift = shufflevector <2 x float> %11, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %12 = fadd <2 x float> %11, %shift
  %13 = extractelement <2 x float> %12, i64 0
  %sqrt = call float @llvm.sqrt.f32(float %13)
  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

14:                                               ; preds = %2
  %15 = 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 } %15
}

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


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