; LLVM IR from cvra/robot-software :: lib/pid (pid)

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

; Function Attrs: nounwind uwtable
define dso_local float @pid_process(ptr noundef %0, float noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %6 = load float, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.pid_ctrl_t, ptr %7, i32 0, i32 3
  %9 = load float, ptr %8, align 4, !tbaa !11
  %10 = fadd float %9, %6
  store float %10, ptr %8, align 4, !tbaa !11
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.pid_ctrl_t, ptr %11, i32 0, i32 3
  %13 = load float, ptr %12, align 4, !tbaa !11
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.pid_ctrl_t, ptr %14, i32 0, i32 5
  %16 = load float, ptr %15, align 4, !tbaa !13
  %17 = fcmp ogt float %13, %16
  br i1 %17, label %18, label %24

18:                                               ; preds = %2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.pid_ctrl_t, ptr %19, i32 0, i32 5
  %21 = load float, ptr %20, align 4, !tbaa !13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.pid_ctrl_t, ptr %22, i32 0, i32 3
  store float %21, ptr %23, align 4, !tbaa !11
  br label %41

24:                                               ; preds = %2
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.pid_ctrl_t, ptr %25, i32 0, i32 3
  %27 = load float, ptr %26, align 4, !tbaa !11
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.pid_ctrl_t, ptr %28, i32 0, i32 5
  %30 = load float, ptr %29, align 4, !tbaa !13
  %31 = fneg float %30
  %32 = fcmp olt float %27, %31
  br i1 %32, label %33, label %40

33:                                               ; preds = %24
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.pid_ctrl_t, ptr %34, i32 0, i32 5
  %36 = load float, ptr %35, align 4, !tbaa !13
  %37 = fneg float %36
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.pid_ctrl_t, ptr %38, i32 0, i32 3
  store float %37, ptr %39, align 4, !tbaa !11
  br label %40

40:                                               ; preds = %33, %24
  br label %41

41:                                               ; preds = %40, %18
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.pid_ctrl_t, ptr %42, i32 0, i32 0
  %44 = load float, ptr %43, align 4, !tbaa !14
  %45 = fneg float %44
  %46 = load float, ptr %4, align 4, !tbaa !9
  %47 = fmul float %45, %46
  store float %47, ptr %5, align 4, !tbaa !9
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.pid_ctrl_t, ptr %48, i32 0, i32 1
  %50 = load float, ptr %49, align 4, !tbaa !15
  %51 = fneg float %50
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.pid_ctrl_t, ptr %52, i32 0, i32 3
  %54 = load float, ptr %53, align 4, !tbaa !11
  %55 = fmul float %51, %54
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.pid_ctrl_t, ptr %56, i32 0, i32 6
  %58 = load float, ptr %57, align 4, !tbaa !16
  %59 = fdiv float %55, %58
  %60 = load float, ptr %5, align 4, !tbaa !9
  %61 = fadd float %60, %59
  store float %61, ptr %5, align 4, !tbaa !9
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.pid_ctrl_t, ptr %62, i32 0, i32 2
  %64 = load float, ptr %63, align 4, !tbaa !17
  %65 = fneg float %64
  %66 = load float, ptr %4, align 4, !tbaa !9
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.pid_ctrl_t, ptr %67, i32 0, i32 4
  %69 = load float, ptr %68, align 4, !tbaa !18
  %70 = fsub float %66, %69
  %71 = fmul float %65, %70
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.pid_ctrl_t, ptr %72, i32 0, i32 6
  %74 = load float, ptr %73, align 4, !tbaa !16
  %75 = load float, ptr %5, align 4, !tbaa !9
  %76 = call float @llvm.fmuladd.f32(float %71, float %74, float %75)
  store float %76, ptr %5, align 4, !tbaa !9
  %77 = load float, ptr %4, align 4, !tbaa !9
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.pid_ctrl_t, ptr %78, i32 0, i32 4
  store float %77, ptr %79, align 4, !tbaa !18
  %80 = load float, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret float %80
}

; 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 speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 12}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!12, !10, i64 20}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !10, i64 4}
!16 = !{!12, !10, i64 24}
!17 = !{!12, !10, i64 8}
!18 = !{!12, !10, i64 16}


; 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 @pid_process(ptr nocapture noundef %0, float noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 12
  %4 = load float, ptr %3, align 4, !tbaa !5
  %5 = fadd float %4, %1
  store float %5, ptr %3, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  %7 = load float, ptr %6, align 4, !tbaa !10
  %8 = fcmp ogt float %5, %7
  br i1 %8, label %.sink.split, label %9

9:                                                ; preds = %2
  %10 = fneg float %7
  %11 = fcmp olt float %5, %10
  br i1 %11, label %.sink.split, label %12

.sink.split:                                      ; preds = %9, %2
  %.sink = phi float [ %7, %2 ], [ %10, %9 ]
  store float %.sink, ptr %3, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %.sink.split, %9
  %13 = phi float [ %5, %9 ], [ %.sink, %.sink.split ]
  %14 = load float, ptr %0, align 4, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  %16 = load float, ptr %15, align 4, !tbaa !12
  %17 = fneg float %16
  %18 = fmul float %13, %17
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  %20 = load float, ptr %19, align 4, !tbaa !13
  %21 = fdiv float %18, %20
  %22 = fmul float %14, %1
  %23 = fsub float %21, %22
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = load float, ptr %24, align 4, !tbaa !14
  %26 = fneg float %25
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  %28 = load float, ptr %27, align 4, !tbaa !15
  %29 = fsub float %1, %28
  %30 = fmul float %29, %26
  %31 = tail call float @llvm.fmuladd.f32(float %30, float %20, float %23)
  store float %1, ptr %27, align 4, !tbaa !15
  ret float %31
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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