; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/freertos (event_groups)

; 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.EventGroupDef_t = type { i32, %struct.xLIST, i64 }
%struct.xLIST = type { i64, ptr, %struct.xMINI_LIST_ITEM }
%struct.xMINI_LIST_ITEM = type { i32, ptr, ptr }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare void @vTaskSuspendAll() #1 section "privileged_functions"

declare i64 @xTaskResumeAll() #1 section "privileged_functions"

declare void @vTaskRemoveFromUnorderedEventList(ptr noundef, i32 noundef) #1 section "privileged_functions"

; Function Attrs: nounwind uwtable
define dso_local void @vEventGroupDelete(ptr noundef %0) #2 section "privileged_functions" {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %5, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %10

8:                                                ; preds = %1
  call void asm sideeffect " cpsid i ", "~{memory},~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !9
  br label %9

9:                                                ; preds = %9, %8
  br label %9

10:                                               ; preds = %1
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.EventGroupDef_t, ptr %11, i32 0, i32 1
  store ptr %12, ptr %4, align 8, !tbaa !5
  call void @vTaskSuspendAll()
  br label %13

13:                                               ; preds = %30, %10
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.xLIST, ptr %14, i32 0, i32 0
  %16 = load volatile i64, ptr %15, align 8, !tbaa !10
  %17 = icmp ugt i64 %16, 0
  br i1 %17, label %18, label %35

18:                                               ; preds = %13
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.xLIST, ptr %19, i32 0, i32 2
  %21 = getelementptr inbounds %struct.xMINI_LIST_ITEM, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.xLIST, ptr %23, i32 0, i32 2
  %25 = icmp ne ptr %22, %24
  %26 = zext i1 %25 to i32
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %30

28:                                               ; preds = %18
  call void asm sideeffect " cpsid i ", "~{memory},~{dirflag},~{fpsr},~{flags}"() #3, !srcloc !16
  br label %29

29:                                               ; preds = %29, %28
  br label %29

30:                                               ; preds = %18
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.xLIST, ptr %31, i32 0, i32 2
  %33 = getelementptr inbounds %struct.xMINI_LIST_ITEM, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  call void @vTaskRemoveFromUnorderedEventList(ptr noundef %34, i32 noundef 33554432)
  br label %13, !llvm.loop !17

35:                                               ; preds = %13
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  call void @vPortFree(ptr noundef %36)
  %37 = call i64 @xTaskResumeAll()
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare void @vPortFree(ptr noundef) #1 section "privileged_functions"

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = !{i64 2148256811}
!10 = !{!11, !12, i64 0}
!11 = !{!"xLIST", !12, i64 0, !6, i64 8, !13, i64 16}
!12 = !{!"long", !7, i64 0}
!13 = !{!"xMINI_LIST_ITEM", !14, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!11, !6, i64 24}
!16 = !{i64 2148257094}
!17 = distinct !{!17, !18}
!18 = !{!"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 @vTaskSuspendAll() local_unnamed_addr #0 section "privileged_functions"

declare i64 @xTaskResumeAll() local_unnamed_addr #0 section "privileged_functions"

declare void @vTaskRemoveFromUnorderedEventList(ptr noundef, i32 noundef) local_unnamed_addr #0 section "privileged_functions"

; Function Attrs: nounwind uwtable
define dso_local void @vEventGroupDelete(ptr noundef %0) local_unnamed_addr #1 section "privileged_functions" {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %3, label %5

3:                                                ; preds = %1
  tail call void asm sideeffect " cpsid i ", "~{memory},~{dirflag},~{fpsr},~{flags}"() #2, !srcloc !5
  br label %4

4:                                                ; preds = %4, %3
  br label %4

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @vTaskSuspendAll() #2
  %7 = load volatile i64, ptr %6, align 8, !tbaa !6
  %.not9 = icmp eq i64 %7, 0
  br i1 %.not9, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  br label %10

10:                                               ; preds = %.lr.ph, %14
  %11 = load ptr, ptr %9, align 8, !tbaa !14
  %.not8 = icmp eq ptr %11, %8
  br i1 %.not8, label %12, label %14

12:                                               ; preds = %10
  tail call void asm sideeffect " cpsid i ", "~{memory},~{dirflag},~{fpsr},~{flags}"() #2, !srcloc !15
  br label %13

13:                                               ; preds = %13, %12
  br label %13

14:                                               ; preds = %10
  tail call void @vTaskRemoveFromUnorderedEventList(ptr noundef %11, i32 noundef 33554432) #2
  %15 = load volatile i64, ptr %6, align 8, !tbaa !6
  %.not = icmp eq i64 %15, 0
  br i1 %.not, label %._crit_edge, label %10, !llvm.loop !16

._crit_edge:                                      ; preds = %14, %5
  tail call void @vPortFree(ptr noundef nonnull %0) #2
  %16 = tail call i64 @xTaskResumeAll() #2
  ret void
}

declare void @vPortFree(ptr noundef) local_unnamed_addr #0 section "privileged_functions"

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 = !{i64 2148256811}
!6 = !{!7, !8, i64 0}
!7 = !{!"xLIST", !8, i64 0, !11, i64 8, !12, i64 16}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"xMINI_LIST_ITEM", !13, i64 0, !11, i64 8, !11, i64 16}
!13 = !{!"int", !9, i64 0}
!14 = !{!7, !11, i64 24}
!15 = !{i64 2148257094}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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