; LLVM IR from nubot-nudt/simatch :: src/auto_referee/src/Quaternion.ll (ZN6gazebo4math10Quaternion9NormalizeEv)

; 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.gazebo::math::Quaternion" = type { double, double, double, double }

; 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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6gazebo4math10Quaternion9NormalizeEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store double 0.000000e+00, ptr %3, align 8, !tbaa !9
  %7 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 0
  %8 = load double, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 0
  %10 = load double, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 1
  %12 = load double, ptr %11, align 8, !tbaa !13
  %13 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 1
  %14 = load double, ptr %13, align 8, !tbaa !13
  %15 = fmul double %12, %14
  %16 = call double @llvm.fmuladd.f64(double %8, double %10, double %15)
  %17 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 2
  %18 = load double, ptr %17, align 8, !tbaa !14
  %19 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 2
  %20 = load double, ptr %19, align 8, !tbaa !14
  %21 = call double @llvm.fmuladd.f64(double %18, double %20, double %16)
  %22 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 3
  %23 = load double, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 3
  %25 = load double, ptr %24, align 8, !tbaa !15
  %26 = call double @llvm.fmuladd.f64(double %23, double %25, double %21)
  %27 = call double @sqrt(double noundef %26) #5
  store double %27, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store double 0.000000e+00, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store double 0x3EB0C6F7A0B5ED8D, ptr %5, align 8, !tbaa !9
  %28 = call noundef zeroext i1 @_ZN6gazebo4math5equalIdEEbRKT_S4_S4_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %5)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  br i1 %28, label %29, label %34

29:                                               ; preds = %1
  %30 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 0
  store double 1.000000e+00, ptr %30, align 8, !tbaa !11
  %31 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 1
  store double 0.000000e+00, ptr %31, align 8, !tbaa !13
  %32 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 2
  store double 0.000000e+00, ptr %32, align 8, !tbaa !14
  %33 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 3
  store double 0.000000e+00, ptr %33, align 8, !tbaa !15
  br label %51

34:                                               ; preds = %1
  %35 = load double, ptr %3, align 8, !tbaa !9
  %36 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 0
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = fdiv double %37, %35
  store double %38, ptr %36, align 8, !tbaa !11
  %39 = load double, ptr %3, align 8, !tbaa !9
  %40 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 1
  %41 = load double, ptr %40, align 8, !tbaa !13
  %42 = fdiv double %41, %39
  store double %42, ptr %40, align 8, !tbaa !13
  %43 = load double, ptr %3, align 8, !tbaa !9
  %44 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 2
  %45 = load double, ptr %44, align 8, !tbaa !14
  %46 = fdiv double %45, %43
  store double %46, ptr %44, align 8, !tbaa !14
  %47 = load double, ptr %3, align 8, !tbaa !9
  %48 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %6, i32 0, i32 3
  %49 = load double, ptr %48, align 8, !tbaa !15
  %50 = fdiv double %49, %47
  store double %50, ptr %48, align 8, !tbaa !15
  br label %51

51:                                               ; preds = %34, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN6gazebo4math5equalIdEEbRKT_S4_S4_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #4

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { inlinehint 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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTSN6gazebo4math10QuaternionE", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !10, i64 16}
!15 = !{!12, !10, i64 24}


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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6gazebo4math10Quaternion9NormalizeEv(ptr nocapture noundef nonnull align 8 dereferenceable(32) %0) local_unnamed_addr #2 align 2 {
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %5 = load double, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load double, ptr %6, align 8, !tbaa !10
  %8 = fmul double %7, %7
  %9 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %8)
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load double, ptr %10, align 8, !tbaa !11
  %12 = tail call double @llvm.fmuladd.f64(double %11, double %11, double %9)
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load double, ptr %13, align 8, !tbaa !12
  %15 = tail call double @llvm.fmuladd.f64(double %14, double %14, double %12)
  %sqrt = tail call double @llvm.sqrt.f64(double %15)
  store double %sqrt, ptr %2, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  store double 0.000000e+00, ptr %3, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #5
  store double 0x3EB0C6F7A0B5ED8D, ptr %4, align 8, !tbaa !13
  %16 = call noundef zeroext i1 @_ZN6gazebo4math5equalIdEEbRKT_S4_S4_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  br i1 %16, label %25, label %17

17:                                               ; preds = %1
  %18 = load double, ptr %2, align 8, !tbaa !13
  %19 = load <2 x double>, ptr %0, align 8, !tbaa !13
  %20 = insertelement <2 x double> poison, double %18, i64 0
  %21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
  %22 = fdiv <2 x double> %19, %21
  %23 = load <2 x double>, ptr %10, align 8, !tbaa !13
  %24 = fdiv <2 x double> %23, %21
  br label %25

25:                                               ; preds = %1, %17
  %26 = phi <2 x double> [ %22, %17 ], [ <double 1.000000e+00, double 0.000000e+00>, %1 ]
  %27 = phi <2 x double> [ %24, %17 ], [ zeroinitializer, %1 ]
  store <2 x double> %26, ptr %0, align 8
  store <2 x double> %27, ptr %10, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN6gazebo4math5equalIdEEbRKT_S4_S4_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

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

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


; Effective O3 passes: AggressiveInstCombinePass,DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass