; LLVM IR from Rangobotics/differential-robot :: src (Position)

; 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.Position = type { float, float, float }

@Displacement = external dso_local global float, align 4
@Orientation = external dso_local global float, align 4
@DeltaPosX = external global float, align 4
@DeltaPosY = external global float, align 4
@LeftEncoderValue = external global i32, align 4
@RightEncoderValue = external global i32, align 4
@linearVelocity = external dso_local global float, align 4
@angularVelocity = external dso_local global float, align 4
@WLeftRotation = external dso_local global float, align 4
@WRightRotation = external dso_local global float, align 4

; Function Attrs: nounwind uwtable
define dso_local void @posUpdate(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load float, ptr @Displacement, align 4, !tbaa !9
  %4 = fpext float %3 to double
  %5 = load float, ptr @Orientation, align 4, !tbaa !9
  %6 = fpext float %5 to double
  %7 = call double @cos(double noundef %6) #2
  %8 = fmul double %4, %7
  %9 = fptrunc double %8 to float
  store float %9, ptr @DeltaPosX, align 4, !tbaa !9
  %10 = load float, ptr @Displacement, align 4, !tbaa !9
  %11 = fpext float %10 to double
  %12 = load float, ptr @Orientation, align 4, !tbaa !9
  %13 = fpext float %12 to double
  %14 = call double @sin(double noundef %13) #2
  %15 = fmul double %11, %14
  %16 = fptrunc double %15 to float
  store float %16, ptr @DeltaPosY, align 4, !tbaa !9
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Position, ptr %17, i32 0, i32 0
  %19 = load float, ptr %18, align 4, !tbaa !11
  %20 = load float, ptr @DeltaPosX, align 4, !tbaa !9
  %21 = fadd float %19, %20
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Position, ptr %22, i32 0, i32 0
  store float %21, ptr %23, align 4, !tbaa !11
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Position, ptr %24, i32 0, i32 1
  %26 = load float, ptr %25, align 4, !tbaa !13
  %27 = load float, ptr @DeltaPosY, align 4, !tbaa !9
  %28 = fadd float %26, %27
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Position, ptr %29, i32 0, i32 1
  store float %28, ptr %30, align 4, !tbaa !13
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Position, ptr %31, i32 0, i32 2
  %33 = load float, ptr %32, align 4, !tbaa !14
  %34 = load float, ptr @Orientation, align 4, !tbaa !9
  %35 = fadd float %33, %34
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Position, ptr %36, i32 0, i32 2
  store float %35, ptr %37, align 4, !tbaa !14
  %38 = load i32, ptr @LeftEncoderValue, align 4, !tbaa !15
  %39 = load i32, ptr @RightEncoderValue, align 4, !tbaa !15
  %40 = add nsw i32 %38, %39
  %41 = sitofp i32 %40 to double
  %42 = fmul double 0x402F6A7A2955385E, %41
  %43 = fdiv double %42, 1.000000e+01
  %44 = fptrunc double %43 to float
  store float %44, ptr @linearVelocity, align 4, !tbaa !9
  %45 = load i32, ptr @LeftEncoderValue, align 4, !tbaa !15
  %46 = load i32, ptr @RightEncoderValue, align 4, !tbaa !15
  %47 = sub nsw i32 %45, %46
  %48 = sitofp i32 %47 to double
  %49 = fmul double 0x402F6A7A2955385E, %48
  %50 = fdiv double %49, 2.000000e+02
  %51 = fptrunc double %50 to float
  store float %51, ptr @angularVelocity, align 4, !tbaa !9
  %52 = load float, ptr @linearVelocity, align 4, !tbaa !9
  %53 = fsub float %52, 1.000000e+01
  %54 = load float, ptr @angularVelocity, align 4, !tbaa !9
  %55 = fmul float %53, %54
  %56 = fdiv float %55, 5.000000e+00
  store float %56, ptr @WLeftRotation, align 4, !tbaa !9
  %57 = load float, ptr @linearVelocity, align 4, !tbaa !9
  %58 = fadd float %57, 1.000000e+01
  %59 = load float, ptr @angularVelocity, align 4, !tbaa !9
  %60 = fmul float %58, %59
  %61 = fdiv float %60, 5.000000e+00
  store float %61, ptr @WRightRotation, align 4, !tbaa !9
  ret void
}

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

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

attributes #0 = { 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 #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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}


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

@Displacement = external dso_local local_unnamed_addr global float, align 4
@Orientation = external dso_local local_unnamed_addr global float, align 4
@DeltaPosX = external local_unnamed_addr global float, align 4
@DeltaPosY = external local_unnamed_addr global float, align 4
@LeftEncoderValue = external local_unnamed_addr global i32, align 4
@RightEncoderValue = external local_unnamed_addr global i32, align 4
@linearVelocity = external dso_local local_unnamed_addr global float, align 4
@angularVelocity = external dso_local local_unnamed_addr global float, align 4
@WLeftRotation = external dso_local local_unnamed_addr global float, align 4
@WRightRotation = external dso_local local_unnamed_addr global float, align 4

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, inaccessiblemem: write) uwtable
define dso_local void @posUpdate(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load float, ptr @Displacement, align 4, !tbaa !5
  %3 = fpext float %2 to double
  %4 = load float, ptr @Orientation, align 4, !tbaa !5
  %5 = fpext float %4 to double
  %6 = tail call double @cos(double noundef %5) #2
  %7 = fmul double %6, %3
  %8 = fptrunc double %7 to float
  store float %8, ptr @DeltaPosX, align 4, !tbaa !5
  %9 = load float, ptr @Displacement, align 4, !tbaa !5
  %10 = fpext float %9 to double
  %11 = load float, ptr @Orientation, align 4, !tbaa !5
  %12 = fpext float %11 to double
  %13 = tail call double @sin(double noundef %12) #2
  %14 = fmul double %13, %10
  %15 = fptrunc double %14 to float
  store float %15, ptr @DeltaPosY, align 4, !tbaa !5
  %16 = load float, ptr %0, align 4, !tbaa !9
  %17 = load float, ptr @DeltaPosX, align 4, !tbaa !5
  %18 = fadd float %16, %17
  store float %18, ptr %0, align 4, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  %20 = load float, ptr @DeltaPosY, align 4, !tbaa !5
  %21 = load float, ptr @Orientation, align 4, !tbaa !5
  %22 = load <2 x float>, ptr %19, align 4, !tbaa !5
  %23 = insertelement <2 x float> poison, float %20, i64 0
  %24 = insertelement <2 x float> %23, float %21, i64 1
  %25 = fadd <2 x float> %22, %24
  store <2 x float> %25, ptr %19, align 4, !tbaa !5
  %26 = load i32, ptr @LeftEncoderValue, align 4, !tbaa !11
  %27 = load i32, ptr @RightEncoderValue, align 4, !tbaa !11
  %28 = add nsw i32 %27, %26
  %29 = sitofp i32 %28 to double
  %30 = fmul double %29, 0x402F6A7A2955385E
  %31 = fdiv double %30, 1.000000e+01
  %32 = fptrunc double %31 to float
  store float %32, ptr @linearVelocity, align 4, !tbaa !5
  %33 = sub nsw i32 %26, %27
  %34 = sitofp i32 %33 to double
  %35 = fmul double %34, 0x402F6A7A2955385E
  %36 = fdiv double %35, 2.000000e+02
  %37 = fptrunc double %36 to float
  store float %37, ptr @angularVelocity, align 4, !tbaa !5
  %38 = fadd float %32, -1.000000e+01
  %39 = fmul float %38, %37
  %40 = fdiv float %39, 5.000000e+00
  store float %40, ptr @WLeftRotation, align 4, !tbaa !5
  %41 = fadd float %32, 1.000000e+01
  %42 = fmul float %41, %37
  %43 = fdiv float %42, 5.000000e+00
  store float %43, ptr @WRightRotation, align 4, !tbaa !5
  ret void
}

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

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

attributes #0 = { mustprogress nofree nounwind willreturn memory(readwrite, inaccessiblemem: write) 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 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 #2 = { 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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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