; 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_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.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 }
%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] }

@.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_add_items = external hidden unnamed_addr constant [126 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_add_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
  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
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr null, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %3
  br label %13

12:                                               ; preds = %3
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 4365, ptr noundef @__PRETTY_FUNCTION__.arm_2d_helper_dirty_region_add_items) #4
  unreachable

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

16:                                               ; preds = %13
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = icmp eq i64 0, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %16, %13
  br label %55

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_t, ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_item_t, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.anon.34, ptr %23, i32 0, i32 0
  store ptr %24, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %25, ptr %8, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %50, %20
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %27, i8 0, i64 56, i1 false)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_item_t, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds %struct.anon.34, ptr %30, i32 0, i32 1
  store ptr %28, ptr %31, align 8, !tbaa !11
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_item_t, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds %struct.anon.34, ptr %35, i32 0, i32 0
  store ptr %33, ptr %36, align 8, !tbaa !16
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_item_t, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.anon.34, ptr %38, i32 0, i32 6
  store i16 -13570, ptr %39, align 2, !tbaa !17
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_item_t, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds %struct.anon.34, ptr %41, i32 0, i32 4
  %43 = load i8, ptr %42, align 8
  %44 = and i8 %43, -5
  %45 = or i8 %44, 4
  store i8 %45, ptr %42, align 8
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %46, ptr %47, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.arm_2d_helper_dirty_region_item_t, ptr %48, i32 1
  store ptr %49, ptr %8, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %26
  %51 = load i64, ptr %6, align 8, !tbaa !9
  %52 = add i64 %51, -1
  store i64 %52, ptr %6, align 8, !tbaa !9
  %53 = icmp ne i64 %52, 0
  br i1 %53, label %26, label %54, !llvm.loop !18

54:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %55

55:                                               ; preds = %54, %19
  ret void
}

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 8}
!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 = !{!12, !6, i64 0}
!17 = !{!12, !15, i64 42}
!18 = distinct !{!18, !19}
!19 = !{!"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 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(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @arm_2d_helper_dirty_region_add_items(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq i64 %2, 0
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 56
  %xtraiter = and i64 %2, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.loopexit.unr-lcssa

.prol.loopexit.unr-lcssa:                         ; preds = %5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %1, i8 0, i64 56, i1 false)
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %6, align 8, !tbaa !13
  store ptr %8, ptr %1, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %1, i64 42
  store i16 -13570, ptr %9, align 2, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %1, i64 40
  store i8 4, ptr %10, align 8
  store ptr %1, ptr %6, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %1, i64 56
  %12 = add nsw i64 %2, -1
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %5
  %.016.unr = phi i64 [ %2, %5 ], [ %12, %.prol.loopexit.unr-lcssa ]
  %.0.unr = phi ptr [ %1, %5 ], [ %11, %.prol.loopexit.unr-lcssa ]
  %13 = icmp eq i64 %2, 1
  br i1 %13, label %.loopexit, label %.new

.new:                                             ; preds = %.prol.loopexit, %.new
  %.016 = phi i64 [ %24, %.new ], [ %.016.unr, %.prol.loopexit ]
  %.0 = phi ptr [ %23, %.new ], [ %.0.unr, %.prol.loopexit ]
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %.0, i8 0, i64 56, i1 false)
  %14 = getelementptr inbounds i8, ptr %.0, i64 8
  store ptr %0, ptr %14, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !13
  store ptr %15, ptr %.0, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %.0, i64 42
  store i16 -13570, ptr %16, align 2, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %.0, i64 40
  store i8 4, ptr %17, align 8
  store ptr %.0, ptr %6, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %.0, i64 56
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %18, i8 0, i64 56, i1 false)
  %19 = getelementptr inbounds i8, ptr %.0, i64 64
  store ptr %0, ptr %19, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !13
  store ptr %20, ptr %18, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %.0, i64 98
  store i16 -13570, ptr %21, align 2, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %.0, i64 96
  store i8 4, ptr %22, align 8
  store ptr %18, ptr %6, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %.0, i64 112
  %24 = add i64 %.016, -2
  %.not.1 = icmp eq i64 %24, 0
  br i1 %.not.1, label %.loopexit, label %.new, !llvm.loop !16

.loopexit:                                        ; preds = %.prol.loopexit, %.new, %3
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nofree norecurse nosync nounwind memory(write, 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 8}
!6 = !{!"arm_2d_helper_dirty_region_item_t", !7, i64 0, !11, i64 48}
!7 = !{!"", !8, i64 0, !8, i64 8, !9, i64 16, !11, i64 32, !9, i64 40, !9, i64 40, !9, i64 40, !9, i64 40, !9, i64 41, !12, i64 42}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"arm_2d_region_t", !9, i64 0, !9, i64 4}
!12 = !{!"short", !9, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!6, !8, i64 0}
!15 = !{!6, !12, i64 42}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass