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

; 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.parameter_namespace_s = type { ptr, i32, ptr, ptr, ptr, ptr }

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
define dso_local void @_parameter_changed_set(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @parameter_port_lock()
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.parameter_s, ptr %6, i32 0, i32 3
  %8 = load i8, ptr %7, align 8, !tbaa !9, !range !12, !noundef !13
  %9 = trunc i8 %8 to i1
  %10 = zext i1 %9 to i8
  store i8 %10, ptr %3, align 1, !tbaa !14
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.parameter_s, ptr %11, i32 0, i32 3
  store i8 1, ptr %12, align 8, !tbaa !9
  call void @parameter_port_unlock()
  %13 = load i8, ptr %3, align 1, !tbaa !14, !range !12, !noundef !13
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %16

15:                                               ; preds = %1
  store i32 1, ptr %4, align 4
  br label %34

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.parameter_s, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  store ptr %19, ptr %5, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %23, %16
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %31

23:                                               ; preds = %20
  call void @parameter_port_lock()
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.parameter_namespace_s, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 8, !tbaa !16
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %25, align 8, !tbaa !16
  call void @parameter_port_unlock()
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.parameter_namespace_s, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !19
  store ptr %30, ptr %5, align 8, !tbaa !5
  br label %20, !llvm.loop !20

31:                                               ; preds = %20
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.parameter_s, ptr %32, i32 0, i32 4
  store i8 1, ptr %33, align 1, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  store i32 0, ptr %4, align 4
  br label %34

34:                                               ; preds = %31, %15
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  %35 = load i32, ptr %4, align 4
  switch i32 %35, label %37 [
    i32 0, label %36
    i32 1, label %36
  ]

36:                                               ; preds = %34, %34
  ret void

37:                                               ; preds = %34
  unreachable
}

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, !11, i64 24}
!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 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !6, i64 8}
!16 = !{!17, !18, i64 8}
!17 = !{!"parameter_namespace_s", !6, i64 0, !18, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!18 = !{!"int", !7, i64 0}
!19 = !{!17, !6, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !11, i64 25}


; 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
define dso_local void @_parameter_changed_set(ptr nocapture noundef %0) local_unnamed_addr #1 {
  tail call void @parameter_port_lock() #2
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load i8, ptr %2, align 8, !tbaa !5, !range !11, !noundef !12
  %4 = trunc nuw i8 %3 to i1
  store i8 1, ptr %2, align 8, !tbaa !5
  tail call void @parameter_port_unlock() #2
  br i1 %4, label %12, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %.07 = load ptr, ptr %6, align 8, !tbaa !13
  %.not8 = icmp eq ptr %.07, null
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.09 = phi ptr [ %.0, %.lr.ph ], [ %.07, %5 ]
  tail call void @parameter_port_lock() #2
  %7 = getelementptr inbounds i8, ptr %.09, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !14
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %7, align 8, !tbaa !14
  tail call void @parameter_port_unlock() #2
  %10 = getelementptr inbounds i8, ptr %.09, i64 16
  %.0 = load ptr, ptr %10, align 8, !tbaa !13
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %.lr.ph, %5
  %11 = getelementptr inbounds i8, ptr %0, i64 25
  store i8 1, ptr %11, align 1, !tbaa !19
  br label %12

12:                                               ; preds = %1, %._crit_edge
  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, !10, i64 24}
!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 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !16, i64 8}
!15 = !{!"parameter_namespace_s", !7, i64 0, !16, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!16 = !{!"int", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !10, i64 25}


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