; 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

declare void @parameter_port_assert(i32 noundef) #0

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

19:                                               ; preds = %40, %2
  %20 = load i32, ptr %5, align 4, !tbaa !15
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.parameter_s, ptr %21, i32 0, i32 6
  %23 = getelementptr inbounds %struct._param_val_vector_s, ptr %22, i32 0, i32 2
  %24 = load i16, ptr %23, align 2, !tbaa !17
  %25 = zext i16 %24 to i32
  %26 = icmp slt i32 %20, %25
  br i1 %26, label %27, label %43

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

40:                                               ; preds = %27
  %41 = load i32, ptr %5, align 4, !tbaa !15
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %5, align 4, !tbaa !15
  br label %19, !llvm.loop !20

43:                                               ; preds = %19
  call void @parameter_port_unlock()
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #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, !7, i64 26}
!10 = !{!"parameter_s", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 25, !7, i64 26, !7, i64 32}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!10, !11, i64 25}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"float", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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

declare void @parameter_port_assert(i32 noundef) local_unnamed_addr #0

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

.lr.ph:                                           ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  br label %13

13:                                               ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %14 = load ptr, ptr %12, align 8, !tbaa !14
  %15 = getelementptr inbounds float, ptr %14, i64 %indvars.iv
  %16 = load float, ptr %15, align 4, !tbaa !15
  %17 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  store float %16, ptr %17, align 4, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i16, ptr %10, align 2, !tbaa !14
  %19 = zext i16 %18 to i64
  %20 = icmp ult i64 %indvars.iv.next, %19
  br i1 %20, label %13, label %._crit_edge, !llvm.loop !17

._crit_edge:                                      ; preds = %13, %2
  tail call void @parameter_port_unlock() #2
  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 = !{!6, !10, i64 25}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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