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

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 zeroext i16 @parameter_string_read(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 i16, align 2
  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, 4
  %13 = zext i1 %12 to i32
  call void @parameter_port_assert(i32 noundef %13)
  call void @parameter_port_lock()
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.parameter_s, ptr %14, i32 0, i32 4
  %16 = load i8, ptr %15, align 1, !tbaa !14, !range !15, !noundef !16
  %17 = trunc i8 %16 to i1
  %18 = zext i1 %17 to i32
  %19 = icmp eq i32 %18, 1
  %20 = zext i1 %19 to i32
  call void @parameter_port_assert(i32 noundef %20)
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #4
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.parameter_s, ptr %21, i32 0, i32 6
  %23 = getelementptr inbounds %struct._param_val_str_s, ptr %22, i32 0, i32 2
  %24 = load i16, ptr %23, align 2, !tbaa !17
  store i16 %24, ptr %7, align 2, !tbaa !9
  %25 = load i16, ptr %6, align 2, !tbaa !9
  %26 = zext i16 %25 to i32
  %27 = load i16, ptr %7, align 2, !tbaa !9
  %28 = zext i16 %27 to i32
  %29 = icmp sgt i32 %26, %28
  br i1 %29, label %30, label %42

30:                                               ; preds = %3
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.parameter_s, ptr %32, i32 0, i32 6
  %34 = getelementptr inbounds %struct._param_val_str_s, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = load i16, ptr %7, align 2, !tbaa !9
  %37 = zext i16 %36 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %31, ptr align 1 %35, i64 %37, i1 false)
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i16, ptr %7, align 2, !tbaa !9
  %40 = zext i16 %39 to i64
  %41 = getelementptr inbounds i8, ptr %38, i64 %40
  store i8 0, ptr %41, align 1, !tbaa !17
  br label %58

42:                                               ; preds = %3
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.parameter_s, ptr %44, i32 0, i32 6
  %46 = getelementptr inbounds %struct._param_val_str_s, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !17
  %48 = load i16, ptr %6, align 2, !tbaa !9
  %49 = zext i16 %48 to i32
  %50 = sub nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %43, ptr align 1 %47, i64 %51, i1 false)
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i16, ptr %6, align 2, !tbaa !9
  %54 = zext i16 %53 to i32
  %55 = sub nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i8, ptr %52, i64 %56
  store i8 0, ptr %57, align 1, !tbaa !17
  br label %58

58:                                               ; preds = %42, %30
  call void @parameter_port_unlock()
  %59 = load i16, ptr %7, align 2, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #4
  ret i16 %59
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!12, !13, i64 25}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!7, !7, i64 0}


; 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 zeroext i16 @parameter_string_read(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %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, 4
  %7 = zext i1 %6 to i32
  tail call void @parameter_port_assert(i32 noundef %7) #3
  tail call void @parameter_port_lock() #3
  %8 = getelementptr inbounds i8, ptr %0, i64 25
  %9 = load i8, ptr %8, align 1, !tbaa !11, !range !12, !noundef !13
  %10 = zext nneg i8 %9 to i32
  tail call void @parameter_port_assert(i32 noundef %10) #3
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  %12 = getelementptr inbounds i8, ptr %0, i64 42
  %13 = load i16, ptr %12, align 2, !tbaa !14
  %14 = icmp ult i16 %13, %2
  br i1 %14, label %15, label %18

15:                                               ; preds = %3
  %16 = load ptr, ptr %11, align 8, !tbaa !14
  %17 = zext i16 %13 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr align 1 %16, i64 %17, i1 false)
  br label %22

18:                                               ; preds = %3
  %19 = zext i16 %2 to i64
  %20 = load ptr, ptr %11, align 8, !tbaa !14
  %21 = add nsw i64 %19, -1
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr align 1 %20, i64 %21, i1 false)
  br label %22

22:                                               ; preds = %18, %15
  %.sink15 = phi i64 [ %21, %18 ], [ %17, %15 ]
  %23 = getelementptr inbounds i8, ptr %1, i64 %.sink15
  store i8 0, ptr %23, align 1, !tbaa !14
  tail call void @parameter_port_unlock() #3
  ret i16 %13
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !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}


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