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

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

; Function Attrs: nounwind uwtable
define dso_local void @setpoint_update_position(ptr noundef %0, float noundef %1, float noundef %2, float noundef %3, i1 noundef zeroext %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %6, align 8, !tbaa !5
  store float %1, ptr %7, align 4, !tbaa !9
  store float %2, ptr %8, align 4, !tbaa !9
  store float %3, ptr %9, align 4, !tbaa !9
  %11 = zext i1 %4 to i8
  store i8 %11, ptr %10, align 1, !tbaa !11
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.setpoint_interpolator_t, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = icmp eq i32 %14, 2
  br i1 %15, label %16, label %23

16:                                               ; preds = %5
  %17 = load float, ptr %8, align 4, !tbaa !9
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.setpoint_interpolator_t, ptr %18, i32 0, i32 5
  store float %17, ptr %19, align 4, !tbaa !16
  %20 = load float, ptr %9, align 4, !tbaa !9
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.setpoint_interpolator_t, ptr %21, i32 0, i32 6
  store float %20, ptr %22, align 4, !tbaa !17
  br label %23

23:                                               ; preds = %16, %5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.setpoint_interpolator_t, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %32

28:                                               ; preds = %23
  %29 = load float, ptr %8, align 4, !tbaa !9
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.setpoint_interpolator_t, ptr %30, i32 0, i32 5
  store float %29, ptr %31, align 4, !tbaa !16
  br label %32

32:                                               ; preds = %28, %23
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.setpoint_interpolator_t, ptr %33, i32 0, i32 0
  store i32 0, ptr %34, align 4, !tbaa !13
  %35 = load float, ptr %7, align 4, !tbaa !9
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.setpoint_interpolator_t, ptr %36, i32 0, i32 1
  store float %35, ptr %37, align 4, !tbaa !18
  %38 = load i8, ptr %10, align 1, !tbaa !11, !range !19, !noundef !20
  %39 = trunc i8 %38 to i1
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.setpoint_interpolator_t, ptr %40, i32 0, i32 11
  %42 = zext i1 %39 to i8
  store i8 %42, ptr %41, align 4, !tbaa !21
  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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"", !15, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !15, i64 32, !10, i64 36, !10, i64 40, !12, i64 44}
!15 = !{!"int", !7, i64 0}
!16 = !{!14, !10, i64 20}
!17 = !{!14, !10, i64 24}
!18 = !{!14, !10, i64 4}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!14, !12, i64 44}


; 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 @setpoint_update_position(ptr nocapture noundef %0, float noundef %1, float noundef %2, float noundef %3, i1 noundef zeroext %4) local_unnamed_addr #0 {
  %6 = load i32, ptr %0, align 4, !tbaa !5
  switch i32 %6, label %9 [
    i32 2, label %.thread
    i32 1, label %.sink.split
  ]

.thread:                                          ; preds = %5
  %7 = getelementptr inbounds i8, ptr %0, i64 20
  store float %2, ptr %7, align 4, !tbaa !12
  br label %.sink.split

.sink.split:                                      ; preds = %5, %.thread
  %.sink13 = phi i64 [ 24, %.thread ], [ 20, %5 ]
  %.sink = phi float [ %3, %.thread ], [ %2, %5 ]
  %8 = getelementptr inbounds i8, ptr %0, i64 %.sink13
  store float %.sink, ptr %8, align 4, !tbaa !13
  br label %9

9:                                                ; preds = %.sink.split, %5
  %10 = zext i1 %4 to i8
  store i32 0, ptr %0, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  store float %1, ptr %11, align 4, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %0, i64 44
  store i8 %10, ptr %12, align 4, !tbaa !15
  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 0}
!6 = !{!"", !7, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !7, i64 32, !10, i64 36, !10, i64 40, !11, i64 44}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!6, !10, i64 20}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !10, i64 4}
!15 = !{!6, !11, i64 44}


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