; LLVM IR from ctlst-tech/catpilot :: os/freertos/core/src (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, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @vPortRaiseBASEPRI() #1

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

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

17:                                               ; preds = %5
  call void @vPortRaiseBASEPRI()
  br label %18

18:                                               ; preds = %18, %17
  br label %18

19:                                               ; preds = %5
  %20 = load ptr, ptr %9, align 8, !tbaa !9
  %21 = icmp ne ptr %20, null
  %22 = zext i1 %21 to i32
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %19
  call void @vPortRaiseBASEPRI()
  br label %25

25:                                               ; preds = %25, %24
  br label %25

26:                                               ; preds = %19
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %32

29:                                               ; preds = %26
  %30 = load i64, ptr %7, align 8, !tbaa !5
  %31 = icmp eq i64 %30, 0
  br label %32

32:                                               ; preds = %29, %26
  %33 = phi i1 [ false, %26 ], [ %31, %29 ]
  %34 = xor i1 %33, true
  %35 = zext i1 %34 to i32
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %32
  call void @vPortRaiseBASEPRI()
  br label %38

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

39:                                               ; preds = %32
  %40 = load ptr, ptr %8, align 8, !tbaa !9
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %45

42:                                               ; preds = %39
  %43 = load i64, ptr %7, align 8, !tbaa !5
  %44 = icmp ne i64 %43, 0
  br label %45

45:                                               ; preds = %42, %39
  %46 = phi i1 [ false, %39 ], [ %44, %42 ]
  %47 = xor i1 %46, true
  %48 = zext i1 %47 to i32
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %52

50:                                               ; preds = %45
  call void @vPortRaiseBASEPRI()
  br label %51

51:                                               ; preds = %51, %50
  br label %51

52:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store volatile i64 144, ptr %12, align 8, !tbaa !5
  %53 = load volatile i64, ptr %12, align 8, !tbaa !5
  %54 = icmp eq i64 %53, 144
  %55 = zext i1 %54 to i32
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %52
  call void @vPortRaiseBASEPRI()
  br label %58

58:                                               ; preds = %58, %57
  br label %58

59:                                               ; preds = %52
  %60 = load volatile i64, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %61 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %61, ptr %11, align 8, !tbaa !9
  %62 = load ptr, ptr %11, align 8, !tbaa !9
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %72

64:                                               ; preds = %59
  %65 = load ptr, ptr %11, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.QueueDefinition, ptr %65, i32 0, i32 10
  store i8 1, ptr %66, align 2, !tbaa !12
  %67 = load i64, ptr %6, align 8, !tbaa !5
  %68 = load i64, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !9
  %70 = load i8, ptr %10, align 1, !tbaa !11
  %71 = load ptr, ptr %11, align 8, !tbaa !9
  call void @prvInitialiseNewQueue(i64 noundef %67, i64 noundef %68, ptr noundef %69, i8 noundef zeroext %70, ptr noundef %71)
  br label %73

72:                                               ; preds = %59
  br label %73

73:                                               ; preds = %72, %64
  %74 = load ptr, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret ptr %74
}

; Function Attrs: nounwind uwtable
declare hidden void @prvInitialiseNewQueue(i64 noundef, i64 noundef, ptr noundef, i8 noundef zeroext, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 138}
!13 = !{!"QueueDefinition", !10, i64 0, !10, i64 8, !7, i64 16, !14, i64 32, !14, i64 72, !6, i64 112, !6, i64 120, !6, i64 128, !7, i64 136, !7, i64 137, !7, i64 138}
!14 = !{!"xLIST", !6, i64 0, !10, i64 8, !15, i64 16}
!15 = !{!"xMINI_LIST_ITEM", !16, i64 0, !10, i64 8, !10, i64 16}
!16 = !{!"int", !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"

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @vPortRaiseBASEPRI() local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @xQueueGenericCreateStatic(i64 noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef returned %3, i8 noundef zeroext %4) local_unnamed_addr #2 {
  %6 = alloca i64, align 8
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %7, label %9

7:                                                ; preds = %5
  tail call void @vPortRaiseBASEPRI()
  br label %8

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

9:                                                ; preds = %5
  %.not16 = icmp eq ptr %3, null
  br i1 %.not16, label %10, label %12

10:                                               ; preds = %9
  tail call void @vPortRaiseBASEPRI()
  br label %11

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

12:                                               ; preds = %9
  %13 = icmp ne ptr %2, null
  %14 = icmp eq i64 %1, 0
  %15 = and i1 %14, %13
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  tail call void @vPortRaiseBASEPRI()
  br label %17

17:                                               ; preds = %17, %16
  br label %17

18:                                               ; preds = %12
  %19 = icmp eq ptr %2, null
  %20 = icmp ne i64 %1, 0
  %21 = and i1 %20, %19
  br i1 %21, label %22, label %24

22:                                               ; preds = %18
  tail call void @vPortRaiseBASEPRI()
  br label %23

23:                                               ; preds = %23, %22
  br label %23

24:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6)
  store volatile i64 144, ptr %6, align 8, !tbaa !5
  %.0..0..0..0. = load volatile i64, ptr %6, align 8, !tbaa !5
  %.not17 = icmp eq i64 %.0..0..0..0., 144
  br i1 %.not17, label %27, label %25

25:                                               ; preds = %24
  tail call void @vPortRaiseBASEPRI()
  br label %26

26:                                               ; preds = %26, %25
  br label %26

27:                                               ; preds = %24
  %.0..0..0..0.1 = load volatile i64, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6)
  %28 = getelementptr inbounds i8, ptr %3, i64 138
  store i8 1, ptr %28, align 2, !tbaa !9
  tail call void @prvInitialiseNewQueue(i64 noundef %0, i64 noundef %1, ptr noundef %2, i8 noundef zeroext %4, ptr noundef nonnull %3)
  ret ptr %3
}

; Function Attrs: nounwind uwtable
declare hidden void @prvInitialiseNewQueue(i64 noundef, i64 noundef, ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 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" }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 138}
!10 = !{!"QueueDefinition", !11, i64 0, !11, i64 8, !7, i64 16, !12, i64 32, !12, i64 72, !6, i64 112, !6, i64 120, !6, i64 128, !7, i64 136, !7, i64 137, !7, i64 138}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"xLIST", !6, i64 0, !11, i64 8, !13, i64 16}
!13 = !{!"xMINI_LIST_ITEM", !14, i64 0, !11, i64 8, !11, i64 16}
!14 = !{!"int", !7, i64 0}


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