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

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@__PRETTY_FUNCTION__.arm_2d_dynamic_dirty_region_wait_next = external hidden unnamed_addr constant [80 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: nounwind uwtable
define dso_local zeroext i8 @arm_2d_dynamic_dirty_region_wait_next(ptr noundef nonnull %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  store i8 -1, ptr %3, align 1, !tbaa !9
  br label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = icmp eq ptr null, %5
  br i1 %6, label %7, label %8

7:                                                ; preds = %4
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 4207, ptr noundef @__PRETTY_FUNCTION__.arm_2d_dynamic_dirty_region_wait_next) #4
  unreachable

8:                                                ; preds = %4
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %9, i32 0, i32 3
  %11 = getelementptr inbounds %struct.anon.7, ptr %10, i32 0, i32 2
  %12 = load i16, ptr %11, align 2
  %13 = lshr i16 %12, 2
  %14 = and i16 %13, 3
  %15 = zext i16 %14 to i32
  switch i32 %15, label %59 [
    i32 0, label %16
    i32 1, label %33
    i32 2, label %60
  ]

16:                                               ; preds = %8
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %17, i32 0, i32 3
  %19 = getelementptr inbounds %struct.anon.7, ptr %18, i32 0, i32 0
  %20 = load i8, ptr %19, align 8, !tbaa !10
  store i8 %20, ptr %3, align 1, !tbaa !9
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %21, i32 0, i32 3
  %23 = getelementptr inbounds %struct.anon.7, ptr %22, i32 0, i32 2
  %24 = load i16, ptr %23, align 2
  %25 = and i16 %24, -13
  %26 = or i16 %25, 8
  store i16 %26, ptr %23, align 2
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %27, i32 0, i32 3
  %29 = getelementptr inbounds %struct.anon.7, ptr %28, i32 0, i32 1
  %30 = load i8, ptr %29, align 1
  %31 = and i8 %30, -2
  %32 = or i8 %31, 1
  store i8 %32, ptr %29, align 1
  br label %60

33:                                               ; preds = %8
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %34, i32 0, i32 3
  %36 = getelementptr inbounds %struct.anon.7, ptr %35, i32 0, i32 1
  %37 = load i8, ptr %36, align 1
  %38 = lshr i8 %37, 1
  %39 = and i8 %38, 1
  %40 = icmp ne i8 %39, 0
  br i1 %40, label %58, label %41

41:                                               ; preds = %33
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %42, i32 0, i32 3
  %44 = getelementptr inbounds %struct.anon.7, ptr %43, i32 0, i32 0
  %45 = load i8, ptr %44, align 8, !tbaa !10
  store i8 %45, ptr %3, align 1, !tbaa !9
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %46, i32 0, i32 3
  %48 = getelementptr inbounds %struct.anon.7, ptr %47, i32 0, i32 2
  %49 = load i16, ptr %48, align 2
  %50 = and i16 %49, -13
  %51 = or i16 %50, 8
  store i16 %51, ptr %48, align 2
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.arm_2d_region_list_item_t, ptr %52, i32 0, i32 3
  %54 = getelementptr inbounds %struct.anon.7, ptr %53, i32 0, i32 1
  %55 = load i8, ptr %54, align 1
  %56 = and i8 %55, -2
  %57 = or i8 %56, 1
  store i8 %57, ptr %54, align 1
  br label %58

58:                                               ; preds = %41, %33
  br label %60

59:                                               ; preds = %8
  br label %60

60:                                               ; preds = %59, %58, %16, %8
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = load i8, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret i8 %63
}

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 = { 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 = { nounwind }
attributes #4 = { noreturn 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, !7, i64 24}
!11 = !{!"arm_2d_region_list_item_t", !6, i64 0, !12, i64 8, !13, i64 16, !14, i64 24}
!12 = !{!"", !6, i64 0}
!13 = !{!"arm_2d_region_t", !7, i64 0, !7, i64 4}
!14 = !{!"", !7, i64 0, !7, i64 1, !7, i64 1, !15, i64 2, !15, i64 2, !15, i64 2, !15, i64 2}
!15 = !{!"short", !7, i64 0}


; 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(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local zeroext i8 @arm_2d_dynamic_dirty_region_wait_next(ptr nocapture noundef nonnull %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = getelementptr inbounds i8, ptr %0, i64 26
  %4 = load i16, ptr %3, align 2
  %5 = lshr i16 %4, 2
  %6 = and i16 %5, 3
  switch i16 %6, label %default.unreachable9 [
    i16 0, label %7
    i16 1, label %13
    i16 2, label %22
    i16 3, label %22
  ]

7:                                                ; preds = %1
  %8 = load i8, ptr %2, align 8, !tbaa !5
  %9 = and i16 %4, -13
  %10 = or disjoint i16 %9, 8
  store i16 %10, ptr %3, align 2
  %11 = getelementptr inbounds i8, ptr %0, i64 25
  %12 = load i8, ptr %11, align 1
  br label %.sink.split

13:                                               ; preds = %1
  %14 = getelementptr inbounds i8, ptr %0, i64 25
  %15 = load i8, ptr %14, align 1
  %16 = and i8 %15, 2
  %.not = icmp eq i8 %16, 0
  br i1 %.not, label %17, label %22

17:                                               ; preds = %13
  %18 = load i8, ptr %2, align 8, !tbaa !5
  %19 = and i16 %4, -13
  %20 = or disjoint i16 %19, 8
  store i16 %20, ptr %3, align 2
  br label %.sink.split

default.unreachable9:                             ; preds = %1
  unreachable

.sink.split:                                      ; preds = %7, %17
  %.sink11 = phi i8 [ %15, %17 ], [ %12, %7 ]
  %.sink10 = phi ptr [ %14, %17 ], [ %11, %7 ]
  %.0.ph = phi i8 [ %18, %17 ], [ %8, %7 ]
  %21 = or i8 %.sink11, 1
  store i8 %21, ptr %.sink10, align 1
  br label %22

22:                                               ; preds = %.sink.split, %1, %13, %1
  %.0 = phi i8 [ -1, %1 ], [ -1, %1 ], [ -1, %13 ], [ %.0.ph, %.sink.split ]
  ret i8 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn 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 24}
!6 = !{!"arm_2d_region_list_item_t", !7, i64 0, !10, i64 8, !11, i64 16, !12, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !7, i64 0}
!11 = !{!"arm_2d_region_t", !8, i64 0, !8, i64 4}
!12 = !{!"", !8, i64 0, !8, i64 1, !8, i64 1, !13, i64 2, !13, i64 2, !13, i64 2, !13, i64 2}
!13 = !{!"short", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass