; LLVM IR from ventZl/cmrx :: src/extra/queue_server (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.Queue = type { i16, i16, i8, i8, i8, [0 x i8] }

; 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

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

18:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %82

19:                                               ; preds = %3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call zeroext i1 @queue_empty(ptr noundef %20)
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %82

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Queue, ptr %24, i32 0, i32 3
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Queue, ptr %28, i32 0, i32 4
  %30 = load i8, ptr %29, align 2, !tbaa !11
  %31 = zext i8 %30 to i32
  %32 = mul nsw i32 %27, %31
  store i32 %32, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #3
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Queue, ptr %33, i32 0, i32 1
  %35 = load volatile i16, ptr %34, align 2, !tbaa !12
  %36 = trunc i16 %35 to i8
  store i8 %36, ptr %11, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #3
  store i8 0, ptr %12, align 1, !tbaa !11
  br label %37

37:                                               ; preds = %63, %23
  %38 = load i8, ptr %12, align 1, !tbaa !11
  %39 = zext i8 %38 to i32
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Queue, ptr %40, i32 0, i32 4
  %42 = load i8, ptr %41, align 2, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = icmp slt i32 %39, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %37
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  br label %66

46:                                               ; preds = %37
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Queue, ptr %47, i32 0, i32 5
  %49 = load i8, ptr %11, align 1, !tbaa !11
  %50 = zext i8 %49 to i64
  %51 = getelementptr inbounds [0 x i8], ptr %48, i64 0, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !11
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load i8, ptr %12, align 1, !tbaa !11
  %55 = zext i8 %54 to i64
  %56 = getelementptr inbounds i8, ptr %53, i64 %55
  store i8 %52, ptr %56, align 1, !tbaa !11
  %57 = load i8, ptr %11, align 1, !tbaa !11
  %58 = zext i8 %57 to i32
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = urem i32 %59, %60
  %62 = trunc i32 %61 to i8
  store i8 %62, ptr %11, align 1, !tbaa !11
  br label %63

63:                                               ; preds = %46
  %64 = load i8, ptr %12, align 1, !tbaa !11
  %65 = add i8 %64, 1
  store i8 %65, ptr %12, align 1, !tbaa !11
  br label %37, !llvm.loop !14

66:                                               ; preds = %45
  %67 = load i8, ptr %11, align 1, !tbaa !11
  %68 = zext i8 %67 to i32
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.Queue, ptr %69, i32 0, i32 0
  %71 = load volatile i16, ptr %70, align 2, !tbaa !12
  %72 = zext i16 %71 to i32
  %73 = icmp eq i32 %68, %72
  br i1 %73, label %74, label %77

74:                                               ; preds = %66
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.Queue, ptr %75, i32 0, i32 2
  store volatile i8 1, ptr %76, align 2, !tbaa !16
  br label %77

77:                                               ; preds = %74, %66
  %78 = load i8, ptr %11, align 1, !tbaa !11
  %79 = zext i8 %78 to i16
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.Queue, ptr %80, i32 0, i32 1
  store volatile i16 %79, ptr %81, align 2, !tbaa !12
  store i1 true, ptr %4, align 1
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %82

82:                                               ; preds = %77, %22, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %83 = load i1, ptr %4, align 1
  ret i1 %83
}

declare i32 @wait_for_object(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @queue_empty(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !17, i64 0}
!17 = !{!"_Bool", !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: nounwind uwtable
define dso_local noundef zeroext i1 @queue_receive_timeout(ptr noundef %0, ptr nocapture noundef writeonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call i32 @wait_for_object(ptr noundef %0, i32 noundef %2) #2
  %5 = icmp eq i32 %4, 14
  br i1 %5, label %36, label %6

6:                                                ; preds = %3
  %7 = tail call zeroext i1 @queue_empty(ptr noundef %0)
  br i1 %7, label %36, label %8

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 5
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = zext i8 %10 to i16
  %12 = getelementptr inbounds i8, ptr %0, i64 6
  %13 = load i8, ptr %12, align 2, !tbaa !5
  %14 = zext i8 %13 to i16
  %15 = mul nuw i16 %14, %11
  %16 = getelementptr inbounds i8, ptr %0, i64 2
  %17 = load volatile i16, ptr %16, align 2, !tbaa !8
  %.not = icmp eq i8 %13, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %18 = getelementptr inbounds i8, ptr %0, i64 7
  br label %22

._crit_edge:                                      ; preds = %22, %8
  %.021.in.lcssa = phi i16 [ %17, %8 ], [ %29, %22 ]
  %19 = load volatile i16, ptr %0, align 2, !tbaa !8
  %20 = and i16 %.021.in.lcssa, 255
  %21 = icmp eq i16 %19, %20
  br i1 %21, label %33, label %35

22:                                               ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %.021.in23 = phi i16 [ %17, %.lr.ph ], [ %29, %22 ]
  %23 = and i16 %.021.in23, 255
  %24 = zext nneg i16 %23 to i64
  %25 = getelementptr inbounds [0 x i8], ptr %18, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  store i8 %26, ptr %27, align 1, !tbaa !5
  %28 = add nuw nsw i16 %23, 1
  %29 = urem i16 %28, %15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %30 = load i8, ptr %12, align 2, !tbaa !5
  %31 = zext i8 %30 to i64
  %32 = icmp ult i64 %indvars.iv.next, %31
  br i1 %32, label %22, label %._crit_edge, !llvm.loop !10

33:                                               ; preds = %._crit_edge
  %34 = getelementptr inbounds i8, ptr %0, i64 4
  store volatile i8 1, ptr %34, align 2, !tbaa !12
  br label %35

35:                                               ; preds = %33, %._crit_edge
  store volatile i16 %20, ptr %16, align 2, !tbaa !8
  br label %36

36:                                               ; preds = %6, %3, %35
  %.022 = phi i1 [ true, %35 ], [ false, %3 ], [ false, %6 ]
  ret i1 %.022
}

declare i32 @wait_for_object(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @queue_empty(ptr noundef) local_unnamed_addr #0

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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"_Bool", !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass