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

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

; Function Attrs: nounwind uwtable
define dso_local float @motor_protection_update(ptr noundef %0, float noundef %1, float noundef %2) #0 {
  %4 = alloca float, align 4
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %12 = load float, ptr %6, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.motor_protection_t, ptr %13, i32 0, i32 5
  %15 = load float, ptr %14, align 4, !tbaa !11
  %16 = fmul float %12, %15
  store float %16, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.motor_protection_t, ptr %17, i32 0, i32 0
  %19 = load float, ptr %18, align 4, !tbaa !13
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.motor_protection_t, ptr %20, i32 0, i32 2
  %22 = load float, ptr %21, align 4, !tbaa !14
  %23 = fsub float %19, %22
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.motor_protection_t, ptr %24, i32 0, i32 3
  %26 = load float, ptr %25, align 4, !tbaa !15
  %27 = fdiv float %23, %26
  store float %27, ptr %9, align 4, !tbaa !9
  %28 = load float, ptr %8, align 4, !tbaa !9
  %29 = load float, ptr %9, align 4, !tbaa !9
  %30 = fsub float %28, %29
  %31 = load float, ptr %7, align 4, !tbaa !9
  %32 = fmul float %30, %31
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.motor_protection_t, ptr %33, i32 0, i32 4
  %35 = load float, ptr %34, align 4, !tbaa !16
  %36 = fdiv float %32, %35
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.motor_protection_t, ptr %37, i32 0, i32 0
  %39 = load float, ptr %38, align 4, !tbaa !13
  %40 = fadd float %39, %36
  store float %40, ptr %38, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %41 = load float, ptr %9, align 4, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.motor_protection_t, ptr %42, i32 0, i32 5
  %44 = load float, ptr %43, align 4, !tbaa !11
  %45 = fdiv float %41, %44
  store float %45, ptr %10, align 4, !tbaa !9
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.motor_protection_t, ptr %46, i32 0, i32 0
  %48 = load float, ptr %47, align 4, !tbaa !13
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.motor_protection_t, ptr %49, i32 0, i32 1
  %51 = load float, ptr %50, align 4, !tbaa !17
  %52 = fcmp oge float %48, %51
  br i1 %52, label %53, label %55

53:                                               ; preds = %3
  %54 = load float, ptr %10, align 4, !tbaa !9
  store float %54, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %56

55:                                               ; preds = %3
  store float 0x7FF0000000000000, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %56

56:                                               ; preds = %55, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %57 = load float, ptr %4, align 4
  ret float %57
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 20}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !10, i64 16}
!17 = !{!12, !10, i64 4}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local float @motor_protection_update(ptr nocapture noundef %0, float noundef %1, float noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 20
  %5 = load float, ptr %4, align 4, !tbaa !5
  %6 = fmul float %5, %1
  %7 = load float, ptr %0, align 4, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load float, ptr %8, align 4, !tbaa !11
  %10 = fsub float %7, %9
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  %12 = load float, ptr %11, align 4, !tbaa !12
  %13 = fdiv float %10, %12
  %14 = fsub float %6, %13
  %15 = fmul float %14, %2
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load float, ptr %16, align 4, !tbaa !13
  %18 = fdiv float %15, %17
  %19 = fadd float %7, %18
  store float %19, ptr %0, align 4, !tbaa !10
  %20 = getelementptr inbounds i8, ptr %0, i64 4
  %21 = load float, ptr %20, align 4, !tbaa !14
  %22 = fcmp ult float %19, %21
  %23 = fdiv float %13, %5
  %.0 = select i1 %22, float 0x7FF0000000000000, float %23
  ret float %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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" }

!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 20}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 12}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !7, i64 4}


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