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

; 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.parameter_s = type { ptr, ptr, ptr, i8, i8, i8, %union.anon }
%union.anon = type { %struct._param_val_str_s }
%struct._param_val_str_s = type { ptr, i16, i16 }
%struct._param_val_vector_s = type { ptr, i16, i16 }

declare void @parameter_port_lock() #0

declare void @parameter_port_unlock() #0

; 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

; Function Attrs: nounwind uwtable
declare dso_local void @_parameter_changed_set(ptr noundef) #2

declare void @parameter_port_assert(i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @parameter_variable_vector_set(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i16 %2, ptr %6, align 2, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.parameter_s, ptr %8, i32 0, i32 5
  %10 = load i8, ptr %9, align 2, !tbaa !11
  %11 = zext i8 %10 to i32
  %12 = icmp eq i32 %11, 6
  %13 = zext i1 %12 to i32
  call void @parameter_port_assert(i32 noundef %13)
  call void @parameter_port_lock()
  %14 = load i16, ptr %6, align 2, !tbaa !9
  %15 = zext i16 %14 to i32
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.parameter_s, ptr %16, i32 0, i32 6
  %18 = getelementptr inbounds %struct._param_val_vector_s, ptr %17, i32 0, i32 1
  %19 = load i16, ptr %18, align 8, !tbaa !14
  %20 = zext i16 %19 to i32
  %21 = icmp sle i32 %15, %20
  %22 = zext i1 %21 to i32
  call void @parameter_port_assert(i32 noundef %22)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !15
  br label %23

23:                                               ; preds = %41, %3
  %24 = load i32, ptr %7, align 4, !tbaa !15
  %25 = load i16, ptr %6, align 2, !tbaa !9
  %26 = zext i16 %25 to i32
  %27 = icmp slt i32 %24, %26
  br i1 %27, label %28, label %44

28:                                               ; preds = %23
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i32, ptr %7, align 4, !tbaa !15
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds float, ptr %29, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !17
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.parameter_s, ptr %34, i32 0, i32 6
  %36 = getelementptr inbounds %struct._param_val_vector_s, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = load i32, ptr %7, align 4, !tbaa !15
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %37, i64 %39
  store float %33, ptr %40, align 4, !tbaa !17
  br label %41

41:                                               ; preds = %28
  %42 = load i32, ptr %7, align 4, !tbaa !15
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %7, align 4, !tbaa !15
  br label %23, !llvm.loop !19

44:                                               ; preds = %23
  %45 = load i16, ptr %6, align 2, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.parameter_s, ptr %46, i32 0, i32 6
  %48 = getelementptr inbounds %struct._param_val_vector_s, ptr %47, i32 0, i32 2
  store i16 %45, ptr %48, align 2, !tbaa !14
  call void @parameter_port_unlock()
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_parameter_changed_set(ptr noundef %49)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"short", !7, i64 0}
!11 = !{!12, !7, i64 26}
!12 = !{!"parameter_s", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 25, !7, i64 26, !7, i64 32}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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

declare void @parameter_port_lock() local_unnamed_addr #0

declare void @parameter_port_unlock() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @_parameter_changed_set(ptr noundef) local_unnamed_addr #1

declare void @parameter_port_assert(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @parameter_variable_vector_set(ptr noundef %0, ptr nocapture noundef readonly %1, i16 noundef zeroext %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 26
  %5 = load i8, ptr %4, align 2, !tbaa !5
  %6 = icmp eq i8 %5, 6
  %7 = zext i1 %6 to i32
  tail call void @parameter_port_assert(i32 noundef %7) #2
  tail call void @parameter_port_lock() #2
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = load i16, ptr %9, align 8, !tbaa !11
  %11 = icmp uge i16 %10, %2
  %12 = zext i1 %11 to i32
  tail call void @parameter_port_assert(i32 noundef %12) #2
  %.not = icmp eq i16 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext i16 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %13 = icmp ult i16 %2, 4
  br i1 %13, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 65532
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %14 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  %15 = load float, ptr %14, align 4, !tbaa !12
  %16 = load ptr, ptr %8, align 8, !tbaa !11
  %17 = getelementptr inbounds float, ptr %16, i64 %indvars.iv
  store float %15, ptr %17, align 4, !tbaa !12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %18 = getelementptr inbounds float, ptr %1, i64 %indvars.iv.next
  %19 = load float, ptr %18, align 4, !tbaa !12
  %20 = load ptr, ptr %8, align 8, !tbaa !11
  %21 = getelementptr inbounds float, ptr %20, i64 %indvars.iv.next
  store float %19, ptr %21, align 4, !tbaa !12
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %22 = getelementptr inbounds float, ptr %1, i64 %indvars.iv.next.1
  %23 = load float, ptr %22, align 4, !tbaa !12
  %24 = load ptr, ptr %8, align 8, !tbaa !11
  %25 = getelementptr inbounds float, ptr %24, i64 %indvars.iv.next.1
  store float %23, ptr %25, align 4, !tbaa !12
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %26 = getelementptr inbounds float, ptr %1, i64 %indvars.iv.next.2
  %27 = load float, ptr %26, align 4, !tbaa !12
  %28 = load ptr, ptr %8, align 8, !tbaa !11
  %29 = getelementptr inbounds float, ptr %28, i64 %indvars.iv.next.2
  store float %27, ptr %29, align 4, !tbaa !12
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !14

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %30 = getelementptr inbounds float, ptr %1, i64 %indvars.iv.epil
  %31 = load float, ptr %30, align 4, !tbaa !12
  %32 = load ptr, ptr %8, align 8, !tbaa !11
  %33 = getelementptr inbounds float, ptr %32, i64 %indvars.iv.epil
  store float %31, ptr %33, align 4, !tbaa !12
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !16

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %3
  %34 = getelementptr inbounds i8, ptr %0, i64 42
  store i16 %2, ptr %34, align 2, !tbaa !11
  tail call void @parameter_port_unlock() #2
  tail call void @_parameter_changed_set(ptr noundef nonnull %0)
  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, !8, i64 26}
!6 = !{!"parameter_s", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 25, !8, i64 26, !8, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass