; 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_pfb_t = type { %struct.anon, %struct.anon.30 }
%struct.anon = type { %struct.arm_2d_helper_pfb_cfg_t, %struct.anon.4 }
%struct.arm_2d_helper_pfb_cfg_t = type { %struct.arm_2d_region_t, %struct.anon.1, %struct.anon.2, %struct.arm_2d_helper_pfb_dependency_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.anon.1 = type <{ ptr, %struct.arm_2d_size_t, i64, [4 x i8] }>
%struct.anon.2 = type { ptr, i8 }
%struct.arm_2d_helper_pfb_dependency_t = type { %struct.arm_2d_helper_render_evt_t, %struct.arm_2d_helper_draw_evt_t, %struct.arm_2d_evt_t, %struct.arm_2d_evt_t, %struct.anon.3, %struct.arm_2d_helper_before_flushing_evt_t }
%struct.arm_2d_helper_render_evt_t = type { ptr, ptr }
%struct.arm_2d_helper_draw_evt_t = type { ptr, ptr }
%struct.arm_2d_evt_t = type { ptr, ptr }
%struct.anon.3 = type { %struct.arm_2d_helper_draw_evt_t, ptr }
%struct.arm_2d_helper_before_flushing_evt_t = type { ptr, ptr }
%struct.anon.4 = type { %struct.arm_2d_location_t, %struct.arm_2d_region_t, ptr, %struct.anon.5, %struct.arm_2d_tile_t, %struct.arm_2d_size_t, i32, i8, i8, i16, %struct.anon.21, %union.arm_2d_colour_t, i64, ptr, ptr, ptr, %struct.anon.29, ptr }
%struct.anon.5 = type { ptr, ptr, ptr, ptr, %struct.arm_2d_region_list_item_t }
%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 }
%struct.arm_2d_tile_t = type { %union.anon.8, %union.anon.19, %union.anon.20 }
%union.anon.8 = type { %struct.anon.9 }
%struct.anon.9 = type { i8, %union.arm_2d_color_info_t, %union.anon.12 }
%union.arm_2d_color_info_t = type { %struct.anon.10 }
%struct.anon.10 = type { i8 }
%union.anon.12 = type { i16 }
%union.anon.19 = type { %struct.arm_2d_region_t }
%union.anon.20 = type { ptr }
%struct.anon.21 = type { i32 }
%union.arm_2d_colour_t = type { i32 }
%struct.anon.29 = type { ptr, ptr }
%struct.anon.30 = type { i64, i32, i32 }

@.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_pfb_enable_dirty_region_optimization = external hidden unnamed_addr constant [122 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
declare hidden void @__arm_2d_helper_dirty_region_pool_free(ptr noundef nonnull, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @arm_2d_helper_pfb_enable_dirty_region_optimization(ptr noundef nonnull %0, ptr noundef %1, i8 noundef zeroext %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i8 %2, ptr %6, align 1, !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 786, ptr noundef @__PRETTY_FUNCTION__.arm_2d_helper_pfb_enable_dirty_region_optimization) #4
  unreachable

13:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store ptr null, ptr %8, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %19, %13
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = getelementptr inbounds i32, ptr %15, i32 1
  store ptr %16, ptr %8, align 8, !tbaa !5
  %17 = icmp eq ptr %15, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %34

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.arm_2d_helper_pfb_t, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.anon, ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds %struct.anon.4, ptr %22, i32 0, i32 10
  %24 = load i32, ptr %23, align 4
  %25 = and i32 %24, -3
  %26 = or i32 %25, 2
  store i32 %26, ptr %23, align 4
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.arm_2d_helper_pfb_t, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds %struct.anon, ptr %28, i32 0, i32 1
  %30 = getelementptr inbounds %struct.anon.4, ptr %29, i32 0, i32 10
  %31 = load i32, ptr %30, align 4
  %32 = and i32 %31, -5
  %33 = or i32 %32, 0
  store i32 %33, ptr %30, align 4
  br label %14, !llvm.loop !12

34:                                               ; preds = %18
  %35 = load i8, ptr %6, align 1, !tbaa !9
  %36 = zext i8 %35 to i32
  %37 = icmp eq i32 0, %36
  br i1 %37, label %41, label %38

38:                                               ; preds = %34
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = icmp eq ptr null, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %38, %34
  br label %59

42:                                               ; preds = %38
  br label %43

43:                                               ; preds = %55, %42
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %44, i8 0, i64 32, i1 false)
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %45, i32 0, i32 3
  %47 = getelementptr inbounds %struct.anon.7, ptr %46, i32 0, i32 2
  %48 = load i16, ptr %47, align 2
  %49 = and i16 %48, -2
  %50 = or i16 %49, 1
  store i16 %50, ptr %47, align 2
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  call void @__arm_2d_helper_dirty_region_pool_free(ptr noundef %51, ptr noundef %52)
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %53, i32 1
  store ptr %54, ptr %5, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %43
  %56 = load i8, ptr %6, align 1, !tbaa !9
  %57 = add i8 %56, -1
  store i8 %57, ptr %6, align 1, !tbaa !9
  %58 = icmp ne i8 %57, 0
  br i1 %58, label %43, label %59, !llvm.loop !14

59:                                               ; preds = %55, %41
  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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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: nounwind uwtable
declare hidden void @__arm_2d_helper_dirty_region_pool_free(ptr noundef nonnull, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @arm_2d_helper_pfb_enable_dirty_region_optimization(ptr noundef nonnull %0, ptr noundef %1, i8 noundef zeroext %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 276
  %.promoted = load i32, ptr %4, align 4
  %5 = and i32 %.promoted, -7
  %6 = or disjoint i32 %5, 2
  store i32 %6, ptr %4, align 4
  %7 = icmp eq i8 %2, 0
  %8 = icmp eq ptr %1, null
  %or.cond = or i1 %8, %7
  br i1 %or.cond, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %3, %.preheader
  %.013 = phi i8 [ %11, %.preheader ], [ %2, %3 ]
  %.012 = phi ptr [ %10, %.preheader ], [ %1, %3 ]
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %.012, i8 0, i64 32, i1 false)
  %9 = getelementptr inbounds i8, ptr %.012, i64 26
  store i16 1, ptr %9, align 2
  tail call void @__arm_2d_helper_dirty_region_pool_free(ptr noundef %0, ptr noundef nonnull %.012)
  %10 = getelementptr inbounds i8, ptr %.012, i64 32
  %11 = add i8 %.013, -1
  %.not = icmp eq i8 %11, 0
  br i1 %.not, label %.loopexit, label %.preheader, !llvm.loop !5

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass