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

; 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_region_list_item_t = type { ptr, %struct.anon.6, %struct.arm_2d_region_t, %struct.anon.7 }
%struct.anon.6 = type { ptr }
%struct.arm_2d_region_t = type { %union.anon, %union.anon.0 }
%union.anon = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.0 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%struct.anon.7 = type { i8, i8, i16 }

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @arm_2d_helper_pfb_append_dirty_regions_to_list(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %3
  %9 = load ptr, ptr %6, align 8, !tbaa !5
  %10 = icmp eq ptr null, %9
  br i1 %10, label %17, label %11

11:                                               ; preds = %8
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = icmp eq i64 0, %12
  br i1 %13, label %17, label %14

14:                                               ; preds = %11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = icmp eq ptr null, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %14, %11, %8
  br label %44

18:                                               ; preds = %14
  br label %19

19:                                               ; preds = %23, %18
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = icmp ne ptr null, %21
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %25, i32 0, i32 0
  store ptr %26, ptr %5, align 8, !tbaa !5
  br label %19, !llvm.loop !11

27:                                               ; preds = %19
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %28, ptr %29, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %34, %27
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = add i64 %31, -1
  store i64 %32, ptr %7, align 8, !tbaa !9
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %34, label %41

34:                                               ; preds = %30
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %35, i64 1
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %37, i32 0, i32 0
  store ptr %36, ptr %38, align 8, !tbaa !13
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %39, i32 1
  store ptr %40, ptr %6, align 8, !tbaa !5
  br label %30, !llvm.loop !19

41:                                               ; preds = %30
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %42, i32 0, i32 0
  store ptr null, ptr %43, align 8, !tbaa !13
  store i1 true, ptr %4, align 1
  br label %45

44:                                               ; preds = %17
  store i1 false, ptr %4, align 1
  br label %45

45:                                               ; preds = %44, %41
  %46 = load i1, ptr %4, align 1
  ret i1 %46
}

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

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 0}
!14 = !{!"arm_2d_region_list_item_t", !6, i64 0, !15, i64 8, !16, i64 16, !17, i64 24}
!15 = !{!"", !6, i64 0}
!16 = !{!"arm_2d_region_t", !7, i64 0, !7, i64 4}
!17 = !{!"", !7, i64 0, !7, i64 1, !7, i64 1, !18, i64 2, !18, i64 2, !18, i64 2, !18, i64 2}
!18 = !{!"short", !7, i64 0}
!19 = distinct !{!19, !12}


; 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @arm_2d_helper_pfb_append_dirty_regions_to_list(ptr nocapture noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp ne i64 %2, 0
  br i1 %4, label %.preheader, label %23

.preheader:                                       ; preds = %3, %.preheader
  %.016 = phi ptr [ %5, %.preheader ], [ %0, %3 ]
  %5 = load ptr, ptr %.016, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %6, label %.preheader, !llvm.loop !9

6:                                                ; preds = %.preheader
  store ptr %1, ptr %.016, align 8, !tbaa !5
  %7 = add i64 %2, -1
  %.not2021 = icmp eq i64 %7, 0
  br i1 %.not2021, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6
  %8 = add i64 %2, -2
  %xtraiter = and i64 %7, 7
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %9 = phi i64 [ %11, %.lr.ph.prol ], [ %7, %.lr.ph.preheader ]
  %.01522.prol = phi ptr [ %10, %.lr.ph.prol ], [ %1, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %10 = getelementptr inbounds i8, ptr %.01522.prol, i64 32
  store ptr %10, ptr %.01522.prol, align 8, !tbaa !11
  %11 = add i64 %9, -1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !17

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa.unr = phi ptr [ poison, %.lr.ph.preheader ], [ %10, %.lr.ph.prol ]
  %.unr = phi i64 [ %7, %.lr.ph.preheader ], [ %11, %.lr.ph.prol ]
  %.01522.unr = phi ptr [ %1, %.lr.ph.preheader ], [ %10, %.lr.ph.prol ]
  %12 = icmp ult i64 %8, 7
  br i1 %12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %13 = phi i64 [ %22, %.lr.ph ], [ %.unr, %.lr.ph.prol.loopexit ]
  %.01522 = phi ptr [ %21, %.lr.ph ], [ %.01522.unr, %.lr.ph.prol.loopexit ]
  %14 = getelementptr inbounds i8, ptr %.01522, i64 32
  store ptr %14, ptr %.01522, align 8, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %.01522, i64 64
  store ptr %15, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %.01522, i64 96
  store ptr %16, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %.01522, i64 128
  store ptr %17, ptr %16, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %.01522, i64 160
  store ptr %18, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %.01522, i64 192
  store ptr %19, ptr %18, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %.01522, i64 224
  store ptr %20, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %.01522, i64 256
  store ptr %21, ptr %20, align 8, !tbaa !11
  %22 = add i64 %13, -8
  %.not20.7 = icmp eq i64 %22, 0
  br i1 %.not20.7, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %6
  %.015.lcssa = phi ptr [ %1, %6 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %21, %.lr.ph ]
  store ptr null, ptr %.015.lcssa, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %3, %._crit_edge
  ret i1 %4
}

attributes #0 = { nofree norecurse nosync nounwind memory(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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 0}
!12 = !{!"arm_2d_region_list_item_t", !6, i64 0, !13, i64 8, !14, i64 16, !15, i64 24}
!13 = !{!"", !6, i64 0}
!14 = !{!"arm_2d_region_t", !7, i64 0, !7, i64 4}
!15 = !{!"", !7, i64 0, !7, i64 1, !7, i64 1, !16, i64 2, !16, i64 2, !16, i64 2, !16, i64 2}
!16 = !{!"short", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass