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

; 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: mustprogress uwtable
define dso_local void @_ZNK6gazebo4math10Quaternion6GetLogEv(ptr dead_on_unwind noalias writable sret(%"class.gazebo::math::Quaternion") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i1, align 1
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  store i1 false, ptr %5, align 1
  call void @_ZN6gazebo4math10QuaternionC1Ev(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %11 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 0
  store double 0.000000e+00, ptr %11, align 8, !tbaa !9
  %12 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %10, i32 0, i32 0
  %13 = load double, ptr %12, align 8, !tbaa !9
  %14 = call double @llvm.fabs.f64(double %13)
  %15 = fcmp olt double %14, 1.000000e+00
  br i1 %15, label %16, label %48

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %17 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %10, i32 0, i32 0
  %18 = load double, ptr %17, align 8, !tbaa !9
  %19 = call double @acos(double noundef %18) #4
  store double %19, ptr %6, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %20 = load double, ptr %6, align 8, !tbaa !12
  %21 = call double @sin(double noundef %20) #4
  store double %21, ptr %7, align 8, !tbaa !12
  %22 = load double, ptr %7, align 8, !tbaa !12
  %23 = call double @llvm.fabs.f64(double %22)
  %24 = fcmp oge double %23, 1.000000e-03
  br i1 %24, label %25, label %44

25:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %26 = load double, ptr %6, align 8, !tbaa !12
  %27 = load double, ptr %7, align 8, !tbaa !12
  %28 = fdiv double %26, %27
  store double %28, ptr %8, align 8, !tbaa !12
  %29 = load double, ptr %8, align 8, !tbaa !12
  %30 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %10, i32 0, i32 1
  %31 = load double, ptr %30, align 8, !tbaa !13
  %32 = fmul double %29, %31
  %33 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 1
  store double %32, ptr %33, align 8, !tbaa !13
  %34 = load double, ptr %8, align 8, !tbaa !12
  %35 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %10, i32 0, i32 2
  %36 = load double, ptr %35, align 8, !tbaa !14
  %37 = fmul double %34, %36
  %38 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 2
  store double %37, ptr %38, align 8, !tbaa !14
  %39 = load double, ptr %8, align 8, !tbaa !12
  %40 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %10, i32 0, i32 3
  %41 = load double, ptr %40, align 8, !tbaa !15
  %42 = fmul double %39, %41
  %43 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 3
  store double %42, ptr %43, align 8, !tbaa !15
  store i1 true, ptr %5, align 1
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %45

44:                                               ; preds = %16
  store i32 0, ptr %9, align 4
  br label %45

45:                                               ; preds = %44, %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %46 = load i32, ptr %9, align 4
  switch i32 %46, label %58 [
    i32 0, label %47
  ]

47:                                               ; preds = %45
  br label %48

48:                                               ; preds = %47, %2
  %49 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %10, i32 0, i32 1
  %50 = load double, ptr %49, align 8, !tbaa !13
  %51 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 1
  store double %50, ptr %51, align 8, !tbaa !13
  %52 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %10, i32 0, i32 2
  %53 = load double, ptr %52, align 8, !tbaa !14
  %54 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 2
  store double %53, ptr %54, align 8, !tbaa !14
  %55 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %10, i32 0, i32 3
  %56 = load double, ptr %55, align 8, !tbaa !15
  %57 = getelementptr inbounds %"class.gazebo::math::Quaternion", ptr %0, i32 0, i32 3
  store double %56, ptr %57, align 8, !tbaa !15
  store i1 true, ptr %5, align 1
  store i32 1, ptr %9, align 4
  br label %58

58:                                               ; preds = %48, %45
  %59 = load i1, ptr %5, align 1
  br i1 %59, label %61, label %60

60:                                               ; preds = %58
  call void @_ZN6gazebo4math10QuaternionD1Ev(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  br label %61

61:                                               ; preds = %60, %58
  ret void
}

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

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

; Function Attrs: nounwind
declare double @acos(double noundef) #3

; Function Attrs: nounwind
declare double @sin(double noundef) #3

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

declare void @_ZN6gazebo4math10QuaternionC1Ev(ptr)

declare void @_ZN6gazebo4math10QuaternionD1Ev(ptr)

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

%"class.gazebo::math::Quaternion" = type { double, double, double, double }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6gazebo4math10Quaternion6GetLogEv(ptr dead_on_unwind noalias writable sret(%"class.gazebo::math::Quaternion") align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(32) %1) local_unnamed_addr #0 align 2 {
  tail call void @_ZN6gazebo4math10QuaternionC1Ev(ptr noundef nonnull align 8 dereferenceable(32) %0)
  store double 0.000000e+00, ptr %0, align 8, !tbaa !5
  %3 = load double, ptr %1, align 8, !tbaa !5
  %4 = tail call double @llvm.fabs.f64(double %3)
  %5 = fcmp olt double %4, 1.000000e+00
  br i1 %5, label %6, label %.critedge11

6:                                                ; preds = %2
  %7 = tail call double @acos(double noundef %3) #3
  %8 = tail call double @sin(double noundef %7) #3
  %9 = tail call double @llvm.fabs.f64(double %8)
  %10 = fcmp ult double %9, 1.000000e-03
  br i1 %10, label %.critedge11, label %11

11:                                               ; preds = %6
  %12 = fdiv double %7, %8
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load <2 x double>, ptr %13, align 8, !tbaa !10
  %16 = insertelement <2 x double> poison, double %12, i64 0
  %17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> zeroinitializer
  %18 = fmul <2 x double> %17, %15
  store <2 x double> %18, ptr %14, align 8, !tbaa !10
  %19 = getelementptr inbounds i8, ptr %1, i64 24
  %20 = load double, ptr %19, align 8, !tbaa !11
  %21 = fmul double %12, %20
  br label %.critedge13

.critedge11:                                      ; preds = %6, %2
  %22 = getelementptr inbounds i8, ptr %1, i64 8
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = load <2 x double>, ptr %22, align 8, !tbaa !10
  store <2 x double> %24, ptr %23, align 8, !tbaa !10
  %25 = getelementptr inbounds i8, ptr %1, i64 24
  %26 = load double, ptr %25, align 8, !tbaa !11
  br label %.critedge13

.critedge13:                                      ; preds = %11, %.critedge11
  %.sink = phi double [ %21, %11 ], [ %26, %.critedge11 ]
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  store double %.sink, ptr %27, align 8, !tbaa !11
  ret void
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @acos(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #2

declare void @_ZN6gazebo4math10QuaternionC1Ev(ptr) local_unnamed_addr

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write) "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 = { 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 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass