; LLVM IR from ARM-software/Arm-2D :: Helper/Source (arm_2d_helper)

; 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.arm_2d_byte_fifo_t = type { %struct.anon.17 }
%struct.anon.17 = type { ptr, i16, i16, %struct.__arm_2d_fifo_reader_pointer, %struct.__arm_2d_fifo_reader_pointer }
%struct.__arm_2d_fifo_reader_pointer = type { i16, i16 }

@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__.arm_2d_byte_fifo_dequeue = external hidden unnamed_addr constant [64 x i8], align 1

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @arm_2d_byte_fifo_dequeue(ptr noundef nonnull %0, ptr noundef %1) #3 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr null, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  br label %15

14:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 955, ptr noundef @__PRETTY_FUNCTION__.arm_2d_byte_fifo_dequeue) #4
  unreachable

15:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #5
  store i8 0, ptr %6, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds %struct.anon.17, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = icmp eq ptr null, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %15
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %106

22:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  store ptr null, ptr %10, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %102, %22
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds i32, ptr %24, i32 1
  store ptr %25, ptr %10, align 8, !tbaa !5
  %26 = icmp eq ptr %24, null
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %103

28:                                               ; preds = %23
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.anon.17, ptr %31, i32 0, i32 3
  %33 = getelementptr inbounds %struct.__arm_2d_fifo_reader_pointer, ptr %32, i32 0, i32 0
  %34 = load i16, ptr %33, align 4, !tbaa !18
  %35 = zext i16 %34 to i32
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds %struct.anon.17, ptr %37, i32 0, i32 2
  %39 = load i16, ptr %38, align 2, !tbaa !19
  %40 = zext i16 %39 to i32
  %41 = icmp eq i32 %35, %40
  br i1 %41, label %42, label %51

42:                                               ; preds = %29
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %struct.anon.17, ptr %44, i32 0, i32 3
  %46 = getelementptr inbounds %struct.__arm_2d_fifo_reader_pointer, ptr %45, i32 0, i32 1
  %47 = load i16, ptr %46, align 2, !tbaa !20
  %48 = zext i16 %47 to i32
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %42
  br label %102

51:                                               ; preds = %42, %29
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds %struct.anon.17, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !11
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds %struct.anon.17, ptr %57, i32 0, i32 3
  %59 = getelementptr inbounds %struct.__arm_2d_fifo_reader_pointer, ptr %58, i32 0, i32 0
  %60 = load i16, ptr %59, align 4, !tbaa !18
  %61 = add i16 %60, 1
  store i16 %61, ptr %59, align 4, !tbaa !18
  %62 = zext i16 %60 to i64
  %63 = getelementptr inbounds i8, ptr %55, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !21
  store i8 %64, ptr %7, align 1, !tbaa !21
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %65, i32 0, i32 0
  %67 = getelementptr inbounds %struct.anon.17, ptr %66, i32 0, i32 3
  %68 = getelementptr inbounds %struct.__arm_2d_fifo_reader_pointer, ptr %67, i32 0, i32 0
  %69 = load i16, ptr %68, align 4, !tbaa !18
  %70 = zext i16 %69 to i32
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %71, i32 0, i32 0
  %73 = getelementptr inbounds %struct.anon.17, ptr %72, i32 0, i32 1
  %74 = load i16, ptr %73, align 8, !tbaa !22
  %75 = zext i16 %74 to i32
  %76 = icmp sge i32 %70, %75
  br i1 %76, label %77, label %82

77:                                               ; preds = %51
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %78, i32 0, i32 0
  %80 = getelementptr inbounds %struct.anon.17, ptr %79, i32 0, i32 3
  %81 = getelementptr inbounds %struct.__arm_2d_fifo_reader_pointer, ptr %80, i32 0, i32 0
  store i16 0, ptr %81, align 4, !tbaa !18
  br label %82

82:                                               ; preds = %77, %51
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %83, i32 0, i32 0
  %85 = getelementptr inbounds %struct.anon.17, ptr %84, i32 0, i32 3
  %86 = getelementptr inbounds %struct.__arm_2d_fifo_reader_pointer, ptr %85, i32 0, i32 1
  %87 = load i16, ptr %86, align 2, !tbaa !20
  %88 = add i16 %87, -1
  store i16 %88, ptr %86, align 2, !tbaa !20
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %89, i32 0, i32 0
  %91 = getelementptr inbounds %struct.anon.17, ptr %90, i32 0, i32 4
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %92, i32 0, i32 0
  %94 = getelementptr inbounds %struct.anon.17, ptr %93, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %91, ptr align 4 %94, i64 4, i1 false), !tbaa.struct !23
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = icmp ne ptr null, %95
  br i1 %96, label %97, label %100

97:                                               ; preds = %82
  %98 = load i8, ptr %7, align 1, !tbaa !21
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  store i8 %98, ptr %99, align 1, !tbaa !21
  br label %100

100:                                              ; preds = %97, %82
  store i8 1, ptr %6, align 1, !tbaa !9
  br label %101

101:                                              ; preds = %100
  br label %102

102:                                              ; preds = %101, %50
  br label %23, !llvm.loop !25

103:                                              ; preds = %27
  %104 = load i8, ptr %6, align 1, !tbaa !9, !range !27, !noundef !28
  %105 = trunc i8 %104 to i1
  store i1 %105, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %106

106:                                              ; preds = %103, %21
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  %107 = load i1, ptr %3, align 1
  ret i1 %107
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noreturn nounwind "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 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 #4 = { noreturn nounwind }
attributes #5 = { 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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"arm_2d_byte_fifo_t", !13, i64 0}
!13 = !{!"", !6, i64 0, !14, i64 8, !14, i64 10, !15, i64 12, !15, i64 16}
!14 = !{!"short", !7, i64 0}
!15 = !{!"__arm_2d_fifo_reader_pointer", !14, i64 0, !14, i64 2}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!12, !14, i64 12}
!19 = !{!12, !14, i64 10}
!20 = !{!12, !14, i64 14}
!21 = !{!7, !7, i64 0}
!22 = !{!12, !14, i64 8}
!23 = !{i64 0, i64 2, !24, i64 2, i64 2, !24}
!24 = !{!14, !14, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{i8 0, i8 2}
!28 = !{}


; 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 nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @arm_2d_byte_fifo_dequeue(ptr nocapture noundef nonnull %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = getelementptr inbounds i8, ptr %0, i64 10
  %7 = getelementptr inbounds i8, ptr %0, i64 14
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %.not21 = icmp eq ptr %1, null
  %.pre23 = load i16, ptr %7, align 2, !tbaa !13
  %10 = icmp eq i16 %.pre23, 0
  br i1 %.not21, label %.preheader.split.us, label %.preheader.split

.preheader.split.us:                              ; preds = %.preheader
  %11 = load i16, ptr %6, align 2, !tbaa !14
  %12 = load i16, ptr %5, align 4, !tbaa !15
  %13 = icmp eq i16 %12, %11
  %or.cond = select i1 %13, i1 %10, i1 false
  br i1 %or.cond, label %.loopexit, label %14

14:                                               ; preds = %.preheader.split.us
  %15 = add i16 %12, 1
  %16 = load i16, ptr %8, align 8, !tbaa !16
  %.not.us = icmp ult i16 %15, %16
  %spec.store.select.us = select i1 %.not.us, i16 %15, i16 0
  store i16 %spec.store.select.us, ptr %5, align 4
  %17 = add i16 %.pre23, -1
  store i16 %17, ptr %7, align 2, !tbaa !13
  %18 = load i32, ptr %5, align 4
  store i32 %18, ptr %9, align 8
  br label %.loopexit

.preheader.split:                                 ; preds = %.preheader
  %19 = load i16, ptr %5, align 4, !tbaa !15
  %20 = load i16, ptr %6, align 2, !tbaa !14
  %21 = icmp eq i16 %19, %20
  %or.cond24 = select i1 %21, i1 %10, i1 false
  br i1 %or.cond24, label %.loopexit, label %22

22:                                               ; preds = %.preheader.split
  %23 = add i16 %19, 1
  store i16 %23, ptr %5, align 4, !tbaa !15
  %24 = zext i16 %19 to i64
  %25 = getelementptr inbounds i8, ptr %3, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !17
  %27 = load i16, ptr %8, align 8, !tbaa !16
  %.not = icmp ult i16 %23, %27
  %spec.store.select = select i1 %.not, i16 %23, i16 0
  store i16 %spec.store.select, ptr %5, align 4
  %28 = add i16 %.pre23, -1
  store i16 %28, ptr %7, align 2, !tbaa !13
  %29 = load i32, ptr %5, align 4
  store i32 %29, ptr %9, align 8
  store i8 %26, ptr %1, align 1, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.split, %.preheader.split.us, %22, %14, %2
  %.018 = phi i1 [ false, %2 ], [ true, %14 ], [ true, %22 ], [ false, %.preheader.split.us ], [ false, %.preheader.split ]
  ret i1 %.018
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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, !8, i64 0}
!6 = !{!"arm_2d_byte_fifo_t", !7, i64 0}
!7 = !{!"", !8, i64 0, !11, i64 8, !11, i64 10, !12, i64 12, !12, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"short", !9, i64 0}
!12 = !{!"__arm_2d_fifo_reader_pointer", !11, i64 0, !11, i64 2}
!13 = !{!6, !11, i64 14}
!14 = !{!6, !11, i64 10}
!15 = !{!6, !11, i64 12}
!16 = !{!6, !11, i64 8}
!17 = !{!9, !9, i64 0}


; Effective O3 passes: AggressiveInstCombinePass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass