; LLVM IR from ARM-software/Arm-2D :: Library/Source/arm_2d.ll_ (arm_mask_validate)

; 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_tile_t = type { %union.anon.24, %union.anon.33, %union.anon.36 }
%union.anon.24 = type { %struct.anon.25 }
%struct.anon.25 = type { i8, %union.arm_2d_color_info_t, %union.anon.26 }
%union.arm_2d_color_info_t = type { %struct.anon.3 }
%struct.anon.3 = type { i8 }
%union.anon.26 = type { i16 }
%union.anon.33 = type { %struct.arm_2d_region_t }
%struct.arm_2d_region_t = type { %union.anon.34, %union.anon.35 }
%union.anon.34 = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.35 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%union.anon.36 = type { ptr }
%struct.anon.29 = type { i8, %union.arm_2d_color_info_t, %union.anon.30 }
%union.anon.30 = type { i16 }

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @__arm_2d_valid_mask(ptr noundef, i8 noundef zeroext) #1

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

17:                                               ; preds = %5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = call zeroext i1 @__arm_2d_valid_mask(ptr noundef %18, i8 noundef zeroext 24)
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 -2, ptr %6, align 4
  br label %71

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = call i32 @arm_2d_tile_shape_compare(ptr noundef %22, ptr noundef %23)
  store i32 %24, ptr %12, align 4, !tbaa !9
  %25 = load i32, ptr %12, align 4, !tbaa !9
  %26 = icmp eq i32 -1, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  store i32 -2, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %29

28:                                               ; preds = %21
  store i32 0, ptr %13, align 4
  br label %29

29:                                               ; preds = %28, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %30 = load i32, ptr %13, align 4
  switch i32 %30, label %73 [
    i32 0, label %31
    i32 1, label %71
  ]

31:                                               ; preds = %29
  br label %32

32:                                               ; preds = %31, %5
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = icmp ne ptr null, %33
  br i1 %34, label %35, label %70

35:                                               ; preds = %32
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = call zeroext i1 @__arm_2d_valid_mask(ptr noundef %36, i8 noundef zeroext 24)
  br i1 %37, label %39, label %38

38:                                               ; preds = %35
  store i32 -2, ptr %6, align 4
  br label %71

39:                                               ; preds = %35
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = call i32 @arm_2d_tile_width_compare(ptr noundef %40, ptr noundef %41)
  %43 = icmp eq i32 -1, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %39
  store i32 -2, ptr %6, align 4
  br label %71

45:                                               ; preds = %39
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = call i32 @arm_2d_tile_height_compare(ptr noundef %46, ptr noundef %47)
  %49 = icmp eq i32 -1, %48
  br i1 %49, label %50, label %69

50:                                               ; preds = %45
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds %struct.arm_2d_region_t, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds %struct.arm_2d_size_t, ptr %53, i32 0, i32 1
  %55 = load i16, ptr %54, align 2, !tbaa !11
  %56 = sext i16 %55 to i32
  %57 = icmp ne i32 1, %56
  br i1 %57, label %58, label %59

58:                                               ; preds = %50
  store i32 -2, ptr %6, align 4
  br label %71

59:                                               ; preds = %50
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.anon.29, ptr %61, i32 0, i32 1
  %63 = load i8, ptr %62, align 1, !tbaa !11
  %64 = zext i8 %63 to i32
  %65 = icmp eq i32 107, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %59
  store i32 -2, ptr %6, align 4
  br label %71

67:                                               ; preds = %59
  br label %68

68:                                               ; preds = %67
  br label %69

69:                                               ; preds = %68, %45
  br label %70

70:                                               ; preds = %69, %32
  store i32 0, ptr %6, align 4
  br label %71

71:                                               ; preds = %70, %66, %58, %44, %38, %29, %20
  %72 = load i32, ptr %6, align 4
  ret i32 %72

73:                                               ; preds = %29
  unreachable
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @arm_2d_tile_shape_compare(ptr noundef nonnull, ptr noundef nonnull) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @arm_2d_tile_width_compare(ptr noundef nonnull, ptr noundef nonnull) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @arm_2d_tile_height_compare(ptr noundef nonnull, ptr noundef nonnull) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 = !{!"int", !7, i64 0}
!11 = !{!7, !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: nounwind uwtable
declare dso_local zeroext i1 @__arm_2d_valid_mask(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2, 1) i32 @__arm_mask_validate(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %10, label %6

6:                                                ; preds = %5
  %7 = tail call zeroext i1 @__arm_2d_valid_mask(ptr noundef nonnull %1, i8 noundef zeroext 24)
  br i1 %7, label %8, label %27

8:                                                ; preds = %6
  %9 = tail call i32 @arm_2d_tile_shape_compare(ptr noundef %1, ptr noundef %0)
  %.not20 = icmp eq i32 %9, -1
  br i1 %.not20, label %27, label %10

10:                                               ; preds = %8, %5
  %.not18 = icmp eq ptr %3, null
  br i1 %.not18, label %26, label %11

11:                                               ; preds = %10
  %12 = tail call zeroext i1 @__arm_2d_valid_mask(ptr noundef nonnull %3, i8 noundef zeroext 24)
  br i1 %12, label %13, label %27

13:                                               ; preds = %11
  %14 = tail call i32 @arm_2d_tile_width_compare(ptr noundef %3, ptr noundef %2)
  %15 = icmp eq i32 %14, -1
  br i1 %15, label %27, label %16

16:                                               ; preds = %13
  %17 = tail call i32 @arm_2d_tile_height_compare(ptr noundef %3, ptr noundef %2)
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %19, label %26

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %3, i64 10
  %21 = load i16, ptr %20, align 2, !tbaa !5
  %.not19 = icmp eq i16 %21, 1
  br i1 %.not19, label %22, label %27

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %3, i64 1
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %25 = icmp eq i8 %24, 107
  br i1 %25, label %27, label %26

26:                                               ; preds = %16, %22, %10
  br label %27

27:                                               ; preds = %8, %22, %19, %13, %11, %6, %26
  %.1 = phi i32 [ -2, %8 ], [ 0, %26 ], [ -2, %6 ], [ -2, %11 ], [ -2, %13 ], [ -2, %19 ], [ -2, %22 ]
  ret i32 %.1
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @arm_2d_tile_shape_compare(ptr noundef nonnull, ptr noundef nonnull) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @arm_2d_tile_width_compare(ptr noundef nonnull, ptr noundef nonnull) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @arm_2d_tile_height_compare(ptr noundef nonnull, ptr noundef nonnull) local_unnamed_addr #0

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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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