; 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_peek = external hidden unnamed_addr constant [68 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

16:                                               ; preds = %3
  br label %18

17:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 998, ptr noundef @__PRETTY_FUNCTION__.arm_2d_byte_fifo_peek) #3
  unreachable

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

24:                                               ; preds = %18
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %107

25:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store ptr null, ptr %12, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %103, %25
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = getelementptr inbounds i32, ptr %27, i32 1
  store ptr %28, ptr %12, align 8, !tbaa !5
  %29 = icmp eq ptr %27, null
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %104

31:                                               ; preds = %26
  br label %32

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

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

53:                                               ; preds = %45
  br label %103

54:                                               ; preds = %45, %32
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %55, i32 0, i32 0
  %57 = getelementptr inbounds %struct.anon.17, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds %struct.anon.17, ptr %60, i32 0, i32 4
  %62 = getelementptr inbounds %struct.__arm_2d_fifo_reader_pointer, ptr %61, i32 0, i32 0
  %63 = load i16, ptr %62, align 8, !tbaa !18
  %64 = zext i16 %63 to i64
  %65 = getelementptr inbounds i8, ptr %58, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !21
  store i8 %66, ptr %9, align 1, !tbaa !21
  %67 = load i8, ptr %7, align 1, !tbaa !9, !range !22, !noundef !23
  %68 = trunc i8 %67 to i1
  br i1 %68, label %69, label %95

69:                                               ; preds = %54
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %70, i32 0, i32 0
  %72 = getelementptr inbounds %struct.anon.17, ptr %71, i32 0, i32 4
  %73 = getelementptr inbounds %struct.__arm_2d_fifo_reader_pointer, ptr %72, i32 0, i32 0
  %74 = load i16, ptr %73, align 8, !tbaa !18
  %75 = add i16 %74, 1
  store i16 %75, ptr %73, align 8, !tbaa !18
  %76 = zext i16 %75 to i32
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds %struct.anon.17, ptr %78, i32 0, i32 1
  %80 = load i16, ptr %79, align 8, !tbaa !24
  %81 = zext i16 %80 to i32
  %82 = icmp sge i32 %76, %81
  br i1 %82, label %83, label %88

83:                                               ; preds = %69
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.arm_2d_byte_fifo_t, ptr %84, i32 0, i32 0
  %86 = getelementptr inbounds %struct.anon.17, ptr %85, i32 0, i32 4
  %87 = getelementptr inbounds %struct.__arm_2d_fifo_reader_pointer, ptr %86, i32 0, i32 0
  store i16 0, ptr %87, align 8, !tbaa !18
  br label %88

88:                                               ; preds = %83, %69
  %89 = load ptr, ptr %5, 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 = getelementptr inbounds %struct.__arm_2d_fifo_reader_pointer, ptr %91, i32 0, i32 1
  %93 = load i16, ptr %92, align 2, !tbaa !20
  %94 = add i16 %93, -1
  store i16 %94, ptr %92, align 2, !tbaa !20
  br label %95

95:                                               ; preds = %88, %54
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = icmp ne ptr null, %96
  br i1 %97, label %98, label %101

98:                                               ; preds = %95
  %99 = load i8, ptr %9, align 1, !tbaa !21
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 %99, ptr %100, align 1, !tbaa !21
  br label %101

101:                                              ; preds = %98, %95
  store i8 1, ptr %8, align 1, !tbaa !9
  br label %102

102:                                              ; preds = %101
  br label %103

103:                                              ; preds = %102, %53
  br label %26, !llvm.loop !25

104:                                              ; preds = %30
  %105 = load i8, ptr %8, align 1, !tbaa !9, !range !22, !noundef !23
  %106 = trunc i8 %105 to i1
  store i1 %106, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %107

107:                                              ; preds = %104, %24
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  %108 = load i1, ptr %4, align 1
  ret i1 %108
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { noreturn nounwind }
attributes #4 = { 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 16}
!19 = !{!12, !14, i64 10}
!20 = !{!12, !14, i64 18}
!21 = !{!7, !7, i64 0}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!12, !14, i64 8}
!25 = distinct !{!25, !26}
!26 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local zeroext i1 @arm_2d_byte_fifo_peek(ptr nocapture noundef nonnull %0, ptr noundef writeonly %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = getelementptr inbounds i8, ptr %0, i64 10
  %8 = getelementptr inbounds i8, ptr %0, i64 18
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %.not20 = icmp eq ptr %1, null
  br i1 %2, label %.preheader.split.us, label %.preheader.split

.preheader.split.us:                              ; preds = %.preheader
  %.pre31 = load i16, ptr %8, align 2, !tbaa !13
  %10 = icmp eq i16 %.pre31, 0
  br i1 %.not20, label %.preheader.split.us.split.us, label %.preheader.split.us.split

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

13:                                               ; preds = %.preheader.split.us.split.us
  %14 = add i16 %.promoted, 1
  %15 = load i16, ptr %9, align 8, !tbaa !15
  %.not.us.us = icmp ult i16 %14, %15
  %spec.store.select.us.us = select i1 %.not.us.us, i16 %14, i16 0
  store i16 %spec.store.select.us.us, ptr %6, align 8
  %16 = add i16 %.pre31, -1
  store i16 %16, ptr %8, align 2, !tbaa !13
  br label %.loopexit

.preheader.split.us.split:                        ; preds = %.preheader.split.us
  %17 = load i16, ptr %6, align 8, !tbaa !16
  %18 = load i16, ptr %7, align 2, !tbaa !14
  %19 = icmp eq i16 %17, %18
  %or.cond32 = select i1 %19, i1 %10, i1 false
  br i1 %or.cond32, label %.loopexit, label %20

20:                                               ; preds = %.preheader.split.us.split
  %21 = zext i16 %17 to i64
  %22 = getelementptr inbounds i8, ptr %4, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !17
  %24 = add i16 %17, 1
  %25 = load i16, ptr %9, align 8, !tbaa !15
  %.not.us = icmp ult i16 %24, %25
  %spec.store.select.us = select i1 %.not.us, i16 %24, i16 0
  store i16 %spec.store.select.us, ptr %6, align 8
  %26 = add i16 %.pre31, -1
  store i16 %26, ptr %8, align 2, !tbaa !13
  store i8 %23, ptr %1, align 1, !tbaa !17
  br label %.loopexit

.preheader.split:                                 ; preds = %.preheader
  %27 = load i16, ptr %6, align 8, !tbaa !16
  %28 = load i16, ptr %7, align 2, !tbaa !14
  %29 = icmp eq i16 %27, %28
  br i1 %.not20, label %.preheader.split.split.us, label %.preheader.split.split

.preheader.split.split.us:                        ; preds = %.preheader.split
  br i1 %29, label %.preheader.split.split.us.split.us, label %.loopexit

.preheader.split.split.us.split.us:               ; preds = %.preheader.split.split.us
  %30 = load i16, ptr %8, align 2, !tbaa !13
  %31 = icmp ne i16 %30, 0
  br label %.loopexit

.preheader.split.split:                           ; preds = %.preheader.split
  br i1 %29, label %32, label %35

32:                                               ; preds = %.preheader.split.split
  %33 = load i16, ptr %8, align 2, !tbaa !13
  %34 = icmp eq i16 %33, 0
  br i1 %34, label %.loopexit, label %35

35:                                               ; preds = %32, %.preheader.split.split
  %36 = zext i16 %27 to i64
  %37 = getelementptr inbounds i8, ptr %4, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !17
  store i8 %38, ptr %1, align 1, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.split.split.us.split.us, %.preheader.split.us.split, %.preheader.split.us.split.us, %32, %35, %.preheader.split.split.us, %20, %13, %3
  %.017 = phi i1 [ false, %3 ], [ true, %13 ], [ true, %20 ], [ true, %.preheader.split.split.us ], [ false, %32 ], [ true, %35 ], [ false, %.preheader.split.us.split.us ], [ false, %.preheader.split.us.split ], [ %31, %.preheader.split.split.us.split.us ]
  ret i1 %.017
}

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 18}
!14 = !{!6, !11, i64 10}
!15 = !{!6, !11, i64 8}
!16 = !{!6, !11, i64 16}
!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