; LLVM IR from ClecioJung/digital-control :: digitalControl (piDiscreet)

; 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.PI = type { float, float, i8, %struct.Saturator, float, float, float }
%struct.Saturator = type { float, float }

; Function Attrs: nounwind uwtable
define dso_local void @piDiscreet(ptr noundef %0, float noundef %1, float noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  store float %2, ptr %6, align 4, !tbaa !9
  %7 = load float, ptr %5, align 4, !tbaa !9
  %8 = fpext float %7 to double
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.PI, ptr %9, i32 0, i32 4
  %11 = load float, ptr %10, align 4, !tbaa !11
  %12 = load float, ptr %6, align 4, !tbaa !9
  %13 = fdiv float %11, %12
  %14 = fpext float %13 to double
  %15 = fadd double 2.000000e+00, %14
  %16 = fmul double %8, %15
  %17 = fdiv double %16, 2.000000e+00
  %18 = fptrunc double %17 to float
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.PI, ptr %19, i32 0, i32 5
  store float %18, ptr %20, align 4, !tbaa !15
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.PI, ptr %21, i32 0, i32 4
  %23 = load float, ptr %22, align 4, !tbaa !11
  %24 = load float, ptr %6, align 4, !tbaa !9
  %25 = fdiv float %23, %24
  %26 = fpext float %25 to double
  %27 = fsub double 2.000000e+00, %26
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.PI, ptr %28, i32 0, i32 4
  %30 = load float, ptr %29, align 4, !tbaa !11
  %31 = load float, ptr %6, align 4, !tbaa !9
  %32 = fdiv float %30, %31
  %33 = fpext float %32 to double
  %34 = fadd double 2.000000e+00, %33
  %35 = fdiv double %27, %34
  %36 = fptrunc double %35 to float
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.PI, ptr %37, i32 0, i32 6
  store float %36, ptr %38, align 4, !tbaa !16
  ret void
}

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

!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, !13, i64 8, !14, i64 12, !10, i64 20, !10, i64 24, !10, i64 28}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 4}
!15 = !{!12, !10, i64 24}
!16 = !{!12, !10, i64 28}


; 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 void @piDiscreet(ptr nocapture noundef %0, float noundef %1, float noundef %2) local_unnamed_addr #0 {
  %4 = fpext float %1 to double
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  %6 = load float, ptr %5, align 4, !tbaa !5
  %7 = fdiv float %6, %2
  %8 = fpext float %7 to double
  %9 = fadd double %8, 2.000000e+00
  %10 = fmul double %9, %4
  %11 = fmul double %10, 5.000000e-01
  %12 = fptrunc double %11 to float
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  store float %12, ptr %13, align 4, !tbaa !12
  %14 = fsub double 2.000000e+00, %8
  %15 = fdiv double %14, %9
  %16 = fptrunc double %15 to float
  %17 = getelementptr inbounds i8, ptr %0, i64 28
  store float %16, ptr %17, align 4, !tbaa !13
  ret void
}

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


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