; LLVM IR from cvra/robot-software :: motor-control-firmware/src (rpm)

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

@last_crossing = external hidden global i32, align 4

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

declare i32 @timestamp_get() #1

declare float @timestamp_duration_s(i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden float @get_period() #2

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

; Function Attrs: nounwind uwtable
define dso_local void @rpm_get_velocity_and_position(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  %7 = 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 4, ptr %5) #3
  %8 = call i32 @timestamp_get()
  store i32 %8, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %9 = load i32, ptr @last_crossing, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = call float @timestamp_duration_s(i32 noundef %9, i32 noundef %10)
  store float %11, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %12 = call float @get_period()
  store float %12, ptr %7, align 4, !tbaa !11
  %13 = load float, ptr %6, align 4, !tbaa !11
  %14 = load float, ptr %7, align 4, !tbaa !11
  %15 = fcmp olt float %13, %14
  br i1 %15, label %16, label %32

16:                                               ; preds = %2
  %17 = load float, ptr %7, align 4, !tbaa !11
  %18 = fdiv float 1.000000e+00, %17
  %19 = fmul float %18, 2.000000e+00
  %20 = fpext float %19 to double
  %21 = fmul double %20, 0x400921FB54442D18
  %22 = fptrunc double %21 to float
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  store float %22, ptr %23, align 4, !tbaa !11
  %24 = load float, ptr %6, align 4, !tbaa !11
  %25 = load float, ptr %7, align 4, !tbaa !11
  %26 = fdiv float %24, %25
  %27 = fmul float %26, 2.000000e+00
  %28 = fpext float %27 to double
  %29 = fmul double %28, 0x400921FB54442D18
  %30 = fptrunc double %29 to float
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  store float %30, ptr %31, align 4, !tbaa !11
  br label %41

32:                                               ; preds = %2
  %33 = load float, ptr %6, align 4, !tbaa !11
  %34 = fdiv float 1.000000e+00, %33
  %35 = fmul float %34, 2.000000e+00
  %36 = fpext float %35 to double
  %37 = fmul double %36, 0x400921FB54442D18
  %38 = fptrunc double %37 to float
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  store float %38, ptr %39, align 4, !tbaa !11
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  store float 0.000000e+00, ptr %40, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %32, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

attributes #0 = { 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 = { 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !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"

@last_crossing = external hidden local_unnamed_addr global i32, align 4

declare i32 @timestamp_get() local_unnamed_addr #0

declare float @timestamp_duration_s(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden float @get_period() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @rpm_get_velocity_and_position(ptr nocapture noundef writeonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 {
  %3 = tail call i32 @timestamp_get() #2
  %4 = load i32, ptr @last_crossing, align 4, !tbaa !5
  %5 = tail call float @timestamp_duration_s(i32 noundef %4, i32 noundef %3) #2
  %6 = tail call float @get_period()
  %7 = fcmp olt float %5, %6
  br i1 %7, label %8, label %14

8:                                                ; preds = %2
  %9 = fdiv float %5, %6
  %10 = fmul float %9, 2.000000e+00
  %11 = fpext float %10 to double
  %12 = fmul double %11, 0x400921FB54442D18
  %13 = fptrunc double %12 to float
  br label %14

14:                                               ; preds = %2, %8
  %.pn = phi float [ %6, %8 ], [ %5, %2 ]
  %storemerge = phi float [ %13, %8 ], [ 0.000000e+00, %2 ]
  %.sink.in.in.in.in = fdiv float 1.000000e+00, %.pn
  %.sink.in.in.in = fmul float %.sink.in.in.in.in, 2.000000e+00
  %.sink.in.in = fpext float %.sink.in.in.in to double
  %.sink.in = fmul double %.sink.in.in, 0x400921FB54442D18
  %.sink = fptrunc double %.sink.in to float
  store float %.sink, ptr %0, align 4
  store float %storemerge, ptr %1, align 4, !tbaa !9
  ret void
}

attributes #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 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass