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

; 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.QueueDefinition = type { ptr, ptr, %union.anon, %struct.xLIST, %struct.xLIST, i64, i64, i64, i8, i8, ptr, i64, i8 }
%union.anon = type { %struct.QueuePointers }
%struct.QueuePointers = type { ptr, ptr }
%struct.xLIST = type { i64, ptr, %struct.xMINI_LIST_ITEM }
%struct.xMINI_LIST_ITEM = type { i32, ptr, ptr }

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

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

11:                                               ; preds = %11, %10
  br label %11

12:                                               ; preds = %2
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %97

15:                                               ; preds = %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.QueueDefinition, ptr %16, i32 0, i32 6
  %18 = load i64, ptr %17, align 8, !tbaa !12
  %19 = icmp uge i64 %18, 1
  br i1 %19, label %20, label %97

20:                                               ; preds = %15
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.QueueDefinition, ptr %21, i32 0, i32 6
  %23 = load i64, ptr %22, align 8, !tbaa !12
  %24 = udiv i64 -1, %23
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.QueueDefinition, ptr %25, i32 0, i32 7
  %27 = load i64, ptr %26, align 8, !tbaa !17
  %28 = icmp uge i64 %24, %27
  br i1 %28, label %29, label %97

29:                                               ; preds = %20
  call void @vPortEnterCritical()
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.QueueDefinition, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.QueueDefinition, ptr %33, i32 0, i32 6
  %35 = load i64, ptr %34, align 8, !tbaa !12
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.QueueDefinition, ptr %36, i32 0, i32 7
  %38 = load i64, ptr %37, align 8, !tbaa !17
  %39 = mul i64 %35, %38
  %40 = getelementptr inbounds i8, ptr %32, i64 %39
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.QueueDefinition, ptr %41, i32 0, i32 2
  %43 = getelementptr inbounds %struct.QueuePointers, ptr %42, i32 0, i32 0
  store ptr %40, ptr %43, align 8, !tbaa !19
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.QueueDefinition, ptr %44, i32 0, i32 5
  store volatile i64 0, ptr %45, align 8, !tbaa !20
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.QueueDefinition, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !18
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.QueueDefinition, ptr %49, i32 0, i32 1
  store ptr %48, ptr %50, align 8, !tbaa !21
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.QueueDefinition, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.QueueDefinition, ptr %54, i32 0, i32 6
  %56 = load i64, ptr %55, align 8, !tbaa !12
  %57 = sub i64 %56, 1
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.QueueDefinition, ptr %58, i32 0, i32 7
  %60 = load i64, ptr %59, align 8, !tbaa !17
  %61 = mul i64 %57, %60
  %62 = getelementptr inbounds i8, ptr %53, i64 %61
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.QueueDefinition, ptr %63, i32 0, i32 2
  %65 = getelementptr inbounds %struct.QueuePointers, ptr %64, i32 0, i32 1
  store ptr %62, ptr %65, align 8, !tbaa !19
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.QueueDefinition, ptr %66, i32 0, i32 8
  store volatile i8 -1, ptr %67, align 8, !tbaa !22
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.QueueDefinition, ptr %68, i32 0, i32 9
  store volatile i8 -1, ptr %69, align 1, !tbaa !23
  %70 = load i64, ptr %4, align 8, !tbaa !9
  %71 = icmp eq i64 %70, 0
  br i1 %71, label %72, label %91

72:                                               ; preds = %29
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.QueueDefinition, ptr %73, i32 0, i32 3
  %75 = getelementptr inbounds %struct.xLIST, ptr %74, i32 0, i32 0
  %76 = load volatile i64, ptr %75, align 8, !tbaa !24
  %77 = icmp eq i64 %76, 0
  %78 = zext i1 %77 to i64
  %79 = select i1 %77, i64 1, i64 0
  %80 = icmp eq i64 %79, 0
  br i1 %80, label %81, label %89

81:                                               ; preds = %72
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.QueueDefinition, ptr %82, i32 0, i32 3
  %84 = call i64 @xTaskRemoveFromEventList(ptr noundef %83)
  %85 = icmp ne i64 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %81
  call void @vPortYield()
  br label %88

87:                                               ; preds = %81
  br label %88

88:                                               ; preds = %87, %86
  br label %90

89:                                               ; preds = %72
  br label %90

90:                                               ; preds = %89, %88
  br label %96

91:                                               ; preds = %29
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.QueueDefinition, ptr %92, i32 0, i32 3
  call void @vListInitialise(ptr noundef %93)
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.QueueDefinition, ptr %94, i32 0, i32 4
  call void @vListInitialise(ptr noundef %95)
  br label %96

96:                                               ; preds = %91, %90
  call void @vPortExitCritical()
  br label %98

97:                                               ; preds = %20, %15, %12
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %98

98:                                               ; preds = %97, %96
  %99 = load i64, ptr %5, align 8, !tbaa !9
  %100 = icmp ne i64 %99, 0
  %101 = zext i1 %100 to i32
  %102 = icmp eq i32 %101, 0
  br i1 %102, label %103, label %105

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

104:                                              ; preds = %104, %103
  br label %104

105:                                              ; preds = %98
  %106 = load i64, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i64 %106
}

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

declare void @vPortEnterCritical() #2

declare i64 @xTaskRemoveFromEventList(ptr noundef) #2 section "privileged_functions"

declare void @vPortYield() #2

declare void @vListInitialise(ptr noundef) #2 section "privileged_functions"

declare void @vPortExitCritical() #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"long", !7, i64 0}
!11 = !{i64 2148317365}
!12 = !{!13, !10, i64 120}
!13 = !{!"QueueDefinition", !6, i64 0, !6, i64 8, !7, i64 16, !14, i64 32, !14, i64 72, !10, i64 112, !10, i64 120, !10, i64 128, !7, i64 136, !7, i64 137, !6, i64 144, !10, i64 152, !7, i64 160}
!14 = !{!"xLIST", !10, i64 0, !6, i64 8, !15, i64 16}
!15 = !{!"xMINI_LIST_ITEM", !16, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!"int", !7, i64 0}
!17 = !{!13, !10, i64 128}
!18 = !{!13, !6, i64 0}
!19 = !{!7, !7, i64 0}
!20 = !{!13, !10, i64 112}
!21 = !{!13, !6, i64 8}
!22 = !{!13, !7, i64 136}
!23 = !{!13, !7, i64 137}
!24 = !{!13, !10, i64 32}
!25 = !{i64 2148318009}


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

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

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

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

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 120
  %8 = load i64, ptr %7, align 8, !tbaa !6
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %36, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 128
  %11 = load i64, ptr %10, align 8, !tbaa !15
  %mul = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %8, i64 %11)
  %mul.ov = extractvalue { i64, i1 } %mul, 1
  br i1 %mul.ov, label %36, label %12

12:                                               ; preds = %9
  tail call void @vPortEnterCritical() #3
  %13 = load ptr, ptr %0, align 8, !tbaa !16
  %14 = load i64, ptr %7, align 8, !tbaa !6
  %15 = load i64, ptr %10, align 8, !tbaa !15
  %16 = mul i64 %15, %14
  %17 = getelementptr inbounds i8, ptr %13, i64 %16
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %17, ptr %18, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %0, i64 112
  store volatile i64 0, ptr %19, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %13, ptr %20, align 8, !tbaa !19
  %21 = add i64 %14, -1
  %22 = mul i64 %21, %15
  %23 = getelementptr inbounds i8, ptr %13, i64 %22
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %23, ptr %24, align 8, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %0, i64 136
  store volatile i8 -1, ptr %25, align 8, !tbaa !20
  %26 = getelementptr inbounds i8, ptr %0, i64 137
  store volatile i8 -1, ptr %26, align 1, !tbaa !21
  %27 = icmp eq i64 %1, 0
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  br i1 %27, label %29, label %34

29:                                               ; preds = %12
  %30 = load volatile i64, ptr %28, align 8, !tbaa !22
  %.not28 = icmp eq i64 %30, 0
  br i1 %.not28, label %38, label %31

31:                                               ; preds = %29
  %32 = tail call i64 @xTaskRemoveFromEventList(ptr noundef nonnull %28) #3
  %.not29 = icmp eq i64 %32, 0
  br i1 %.not29, label %38, label %33

33:                                               ; preds = %31
  tail call void @vPortYield() #3
  br label %38

34:                                               ; preds = %12
  tail call void @vListInitialise(ptr noundef nonnull %28) #3
  %35 = getelementptr inbounds i8, ptr %0, i64 72
  tail call void @vListInitialise(ptr noundef nonnull %35) #3
  br label %38

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

37:                                               ; preds = %37, %36
  br label %37

38:                                               ; preds = %31, %33, %29, %34
  tail call void @vPortExitCritical() #3
  ret i64 1
}

declare void @vPortEnterCritical() local_unnamed_addr #1

declare i64 @xTaskRemoveFromEventList(ptr noundef) local_unnamed_addr #1 section "privileged_functions"

declare void @vPortYield() local_unnamed_addr #1

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

declare void @vPortExitCritical() local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #2

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{i64 2148317365}
!6 = !{!7, !12, i64 120}
!7 = !{!"QueueDefinition", !8, i64 0, !8, i64 8, !9, i64 16, !11, i64 32, !11, i64 72, !12, i64 112, !12, i64 120, !12, i64 128, !9, i64 136, !9, i64 137, !8, i64 144, !12, i64 152, !9, i64 160}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"xLIST", !12, i64 0, !8, i64 8, !13, i64 16}
!12 = !{!"long", !9, i64 0}
!13 = !{!"xMINI_LIST_ITEM", !14, i64 0, !8, i64 8, !8, i64 16}
!14 = !{!"int", !9, i64 0}
!15 = !{!7, !12, i64 128}
!16 = !{!7, !8, i64 0}
!17 = !{!9, !9, i64 0}
!18 = !{!7, !12, i64 112}
!19 = !{!7, !8, i64 8}
!20 = !{!7, !9, i64 136}
!21 = !{!7, !9, i64 137}
!22 = !{!7, !12, i64 32}
!23 = !{i64 2148318009}


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