; 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_helper_dirty_region_item_t = type { %struct.anon.34, %struct.arm_2d_region_t }
%struct.anon.34 = type { ptr, ptr, %union.anon.35, %struct.arm_2d_region_t, i8, i8, i16 }
%union.anon.35 = type { [2 x %struct.arm_2d_region_t] }
%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.arm_2d_helper_dirty_region_t = type { %struct.anon.33, %struct.arm_2d_helper_dirty_region_item_t }
%struct.anon.33 = type <{ %struct.arm_2d_region_list_item_t, ptr, ptr, i8, i32, [3 x i8] }>
%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.anon.7 = type { i8, i8, i16 }

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__.arm_2d_helper_dirty_region_remove_items = external hidden unnamed_addr constant [129 x i8], align 1

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

15:                                               ; preds = %3
  br label %17

16:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 4396, ptr noundef @__PRETTY_FUNCTION__.arm_2d_helper_dirty_region_remove_items) #4
  unreachable

17:                                               ; preds = %15
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = icmp eq ptr null, %18
  br i1 %19, label %23, label %20

20:                                               ; preds = %17
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = icmp eq i64 0, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %20, %17
  br label %91

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %25, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %26, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store ptr null, ptr %9, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %88, %24
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_item_t, ptr %28, i32 1
  store ptr %29, ptr %9, align 8, !tbaa !5
  %30 = icmp eq ptr %28, null
  br i1 %30, label %31, label %33

31:                                               ; preds = %27
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  br label %34

33:                                               ; preds = %27
  br label %34

34:                                               ; preds = %33, %31
  %35 = phi i32 [ 1, %31 ], [ 0, %33 ]
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  store i32 2, ptr %10, align 4
  br label %89

38:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %39 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %39, ptr %11, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %79, %38
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = icmp ugt i64 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  store i32 5, ptr %10, align 4
  br label %85

44:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_t, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_item_t, ptr %46, i32 0, i32 0
  %48 = getelementptr inbounds %struct.anon.34, ptr %47, i32 0, i32 0
  store ptr %48, ptr %12, align 8, !tbaa !5
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = icmp eq ptr null, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %44
  store i32 1, ptr %10, align 4
  br label %76

53:                                               ; preds = %44
  br label %54

54:                                               ; preds = %71, %53
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = icmp eq ptr %56, %57
  br i1 %58, label %59, label %66

59:                                               ; preds = %54
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_item_t, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.anon.34, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !11
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %63, ptr %64, align 8, !tbaa !5
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %65, i8 0, i64 56, i1 false)
  br label %75

66:                                               ; preds = %54
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_item_t, ptr %68, i32 0, i32 0
  %70 = getelementptr inbounds %struct.anon.34, ptr %69, i32 0, i32 0
  store ptr %70, ptr %12, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %66
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = icmp ne ptr null, %73
  br i1 %74, label %54, label %75, !llvm.loop !16

75:                                               ; preds = %71, %59
  store i32 0, ptr %10, align 4
  br label %76

76:                                               ; preds = %75, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %77 = load i32, ptr %10, align 4
  switch i32 %77, label %85 [
    i32 0, label %78
  ]

78:                                               ; preds = %76
  br label %79

79:                                               ; preds = %78
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_item_t, ptr %80, i32 1
  store ptr %81, ptr %7, align 8, !tbaa !5
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %82, ptr %8, align 8, !tbaa !5
  %83 = load i64, ptr %11, align 8, !tbaa !9
  %84 = add i64 %83, -1
  store i64 %84, ptr %11, align 8, !tbaa !9
  br label %40, !llvm.loop !18

85:                                               ; preds = %76, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  %86 = load i32, ptr %10, align 4
  switch i32 %86, label %89 [
    i32 5, label %87
  ]

87:                                               ; preds = %85
  br label %88

88:                                               ; preds = %87
  br label %27, !llvm.loop !19

89:                                               ; preds = %85, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %90 = load i32, ptr %10, align 4
  switch i32 %90, label %92 [
    i32 2, label %91
    i32 1, label %91
  ]

91:                                               ; preds = %89, %89, %23
  ret void

92:                                               ; preds = %89
  unreachable
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"arm_2d_helper_dirty_region_item_t", !13, i64 0, !14, i64 48}
!13 = !{!"", !6, i64 0, !6, i64 8, !7, i64 16, !14, i64 32, !7, i64 40, !7, i64 40, !7, i64 40, !7, i64 40, !7, i64 41, !15, i64 42}
!14 = !{!"arm_2d_region_t", !7, i64 0, !7, i64 4}
!15 = !{!"short", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}


; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @arm_2d_helper_dirty_region_remove_items(ptr nocapture noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq i64 %2, 0
  br i1 %4, label %.critedge, label %.critedge34.preheader

.critedge34.preheader:                            ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 56
  br label %6

6:                                                ; preds = %.critedge34.preheader, %.loopexit
  %.02342 = phi i64 [ %2, %.critedge34.preheader ], [ %14, %.loopexit ]
  %.12741 = phi ptr [ %1, %.critedge34.preheader ], [ %13, %.loopexit ]
  %7 = load ptr, ptr %5, align 8, !tbaa !5
  %.not33 = icmp eq ptr %7, null
  br i1 %.not33, label %.critedge, label %.preheader.preheader, !llvm.loop !9

.preheader.preheader:                             ; preds = %6
  %8 = icmp eq ptr %7, %.12741
  br i1 %8, label %.preheader._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %9 = icmp eq ptr %12, %.12741
  br i1 %9, label %.preheader._crit_edge, label %.lr.ph, !llvm.loop !11

.preheader._crit_edge:                            ; preds = %.preheader, %.preheader.preheader
  %.0.lcssa = phi ptr [ %5, %.preheader.preheader ], [ %11, %.preheader ]
  %10 = load ptr, ptr %.12741, align 8, !tbaa !12
  store ptr %10, ptr %.0.lcssa, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %.12741, i8 0, i64 56, i1 false)
  br label %.loopexit

.lr.ph:                                           ; preds = %.preheader.preheader, %.preheader
  %11 = phi ptr [ %12, %.preheader ], [ %7, %.preheader.preheader ]
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %.not32 = icmp eq ptr %12, null
  br i1 %.not32, label %.loopexit, label %.preheader, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph, %.preheader._crit_edge
  %13 = getelementptr inbounds i8, ptr %.12741, i64 56
  %14 = add i64 %.02342, -1
  %.not = icmp eq i64 %14, 0
  br i1 %.not, label %.critedge, label %6, !llvm.loop !17

.critedge:                                        ; preds = %6, %.loopexit, %3
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { 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 = distinct !{!11, !10}
!12 = !{!13, !6, i64 0}
!13 = !{!"arm_2d_helper_dirty_region_item_t", !14, i64 0, !15, i64 48}
!14 = !{!"", !6, i64 0, !6, i64 8, !7, i64 16, !15, i64 32, !7, i64 40, !7, i64 40, !7, i64 40, !7, i64 40, !7, i64 41, !16, i64 42}
!15 = !{!"arm_2d_region_t", !7, i64 0, !7, i64 4}
!16 = !{!"short", !7, i64 0}
!17 = distinct !{!17, !10}


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