; LLVM IR from ARM-software/Arm-2D :: Helper/Source (arm_2d_helper)

; 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_t = type { %union.anon, %union.anon.1 }
%union.anon = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.1 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%union.arm_2d_color_rgb565_t = type { i16 }
%struct.arm_2d_tile_t = type { %union.anon.2, %union.anon.13, %union.anon.14 }
%union.anon.2 = type { %struct.anon.3 }
%struct.anon.3 = type { i8, %union.arm_2d_color_info_t, %union.anon.6 }
%union.arm_2d_color_info_t = type { %struct.anon.4 }
%struct.anon.4 = type { i8 }
%union.anon.6 = type { i16 }
%union.anon.13 = type { %struct.arm_2d_region_t }
%union.anon.14 = type { ptr }

@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__.arm_2d_helper_draw_box = external hidden unnamed_addr constant [104 x i8], align 1

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @arm_2d_helper_draw_box(ptr noundef %0, ptr noundef %1, i16 noundef signext %2, i16 noundef zeroext %3, i8 noundef zeroext %4) #4 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca i8, align 1
  %11 = alloca %struct.arm_2d_region_t, align 2
  %12 = alloca %struct.arm_2d_region_t, align 2
  %13 = alloca %union.arm_2d_color_rgb565_t, align 2
  %14 = alloca %union.arm_2d_color_rgb565_t, align 2
  %15 = alloca %union.arm_2d_color_rgb565_t, align 2
  %16 = alloca %union.arm_2d_color_rgb565_t, align 2
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i16 %2, ptr %8, align 2, !tbaa !9
  store i16 %3, ptr %9, align 2, !tbaa !9
  store i8 %4, ptr %10, align 1, !tbaa !11
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp ne ptr null, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %5
  br label %21

20:                                               ; preds = %5
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.1, i32 noundef 600, ptr noundef @__PRETTY_FUNCTION__.arm_2d_helper_draw_box) #6
  unreachable

21:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %22 = getelementptr inbounds %struct.arm_2d_region_t, ptr %11, i32 0, i32 0
  call void @llvm.memset.p0.i64(ptr align 2 %22, i8 0, i64 4, i1 false)
  %23 = getelementptr inbounds %struct.arm_2d_region_t, ptr %11, i32 0, i32 1
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %24, i32 0, i32 1
  %26 = getelementptr inbounds %struct.arm_2d_region_t, ptr %25, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %23, ptr align 4 %26, i64 4, i1 false), !tbaa.struct !12
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = icmp eq ptr null, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %21
  store ptr %11, ptr %7, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %29, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %12, ptr align 2 %31, i64 8, i1 false), !tbaa.struct !13
  %32 = load i16, ptr %8, align 2, !tbaa !9
  %33 = getelementptr inbounds %struct.arm_2d_region_t, ptr %12, i32 0, i32 1
  %34 = getelementptr inbounds %struct.arm_2d_size_t, ptr %33, i32 0, i32 1
  store i16 %32, ptr %34, align 2, !tbaa !11
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i16, ptr %9, align 2, !tbaa !9
  store i16 %36, ptr %13, align 2, !tbaa !11
  %37 = load i8, ptr %10, align 1, !tbaa !11
  %38 = getelementptr inbounds %union.arm_2d_color_rgb565_t, ptr %13, i32 0, i32 0
  %39 = load i16, ptr %38, align 2
  %40 = call i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef null, ptr noundef %35, ptr noundef %12, i16 %39, i8 noundef zeroext %37)
  %41 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null)
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.arm_2d_region_t, ptr %42, i32 0, i32 1
  %44 = getelementptr inbounds %struct.arm_2d_size_t, ptr %43, i32 0, i32 1
  %45 = load i16, ptr %44, align 2, !tbaa !11
  %46 = sext i16 %45 to i32
  %47 = load i16, ptr %8, align 2, !tbaa !9
  %48 = sext i16 %47 to i32
  %49 = sub nsw i32 %46, %48
  %50 = getelementptr inbounds %struct.arm_2d_region_t, ptr %12, i32 0, i32 0
  %51 = getelementptr inbounds %struct.arm_2d_location_t, ptr %50, i32 0, i32 1
  %52 = load i16, ptr %51, align 2, !tbaa !11
  %53 = sext i16 %52 to i32
  %54 = add nsw i32 %53, %49
  %55 = trunc i32 %54 to i16
  store i16 %55, ptr %51, align 2, !tbaa !11
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i16, ptr %9, align 2, !tbaa !9
  store i16 %57, ptr %14, align 2, !tbaa !11
  %58 = load i8, ptr %10, align 1, !tbaa !11
  %59 = getelementptr inbounds %union.arm_2d_color_rgb565_t, ptr %14, i32 0, i32 0
  %60 = load i16, ptr %59, align 2
  %61 = call i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef null, ptr noundef %56, ptr noundef %12, i16 %60, i8 noundef zeroext %58)
  %62 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null)
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %12, ptr align 2 %63, i64 8, i1 false), !tbaa.struct !13
  %64 = load i16, ptr %8, align 2, !tbaa !9
  %65 = getelementptr inbounds %struct.arm_2d_region_t, ptr %12, i32 0, i32 1
  %66 = getelementptr inbounds %struct.arm_2d_size_t, ptr %65, i32 0, i32 0
  store i16 %64, ptr %66, align 2, !tbaa !11
  %67 = load i16, ptr %8, align 2, !tbaa !9
  %68 = sext i16 %67 to i32
  %69 = getelementptr inbounds %struct.arm_2d_region_t, ptr %12, i32 0, i32 0
  %70 = getelementptr inbounds %struct.arm_2d_location_t, ptr %69, i32 0, i32 1
  %71 = load i16, ptr %70, align 2, !tbaa !11
  %72 = sext i16 %71 to i32
  %73 = add nsw i32 %72, %68
  %74 = trunc i32 %73 to i16
  store i16 %74, ptr %70, align 2, !tbaa !11
  %75 = load i16, ptr %8, align 2, !tbaa !9
  %76 = sext i16 %75 to i32
  %77 = mul nsw i32 %76, 2
  %78 = getelementptr inbounds %struct.arm_2d_region_t, ptr %12, i32 0, i32 1
  %79 = getelementptr inbounds %struct.arm_2d_size_t, ptr %78, i32 0, i32 1
  %80 = load i16, ptr %79, align 2, !tbaa !11
  %81 = sext i16 %80 to i32
  %82 = sub nsw i32 %81, %77
  %83 = trunc i32 %82 to i16
  store i16 %83, ptr %79, align 2, !tbaa !11
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = load i16, ptr %9, align 2, !tbaa !9
  store i16 %85, ptr %15, align 2, !tbaa !11
  %86 = load i8, ptr %10, align 1, !tbaa !11
  %87 = getelementptr inbounds %union.arm_2d_color_rgb565_t, ptr %15, i32 0, i32 0
  %88 = load i16, ptr %87, align 2
  %89 = call i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef null, ptr noundef %84, ptr noundef %12, i16 %88, i8 noundef zeroext %86)
  %90 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null)
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.arm_2d_region_t, ptr %91, i32 0, i32 1
  %93 = getelementptr inbounds %struct.arm_2d_size_t, ptr %92, i32 0, i32 0
  %94 = load i16, ptr %93, align 2, !tbaa !11
  %95 = sext i16 %94 to i32
  %96 = load i16, ptr %8, align 2, !tbaa !9
  %97 = sext i16 %96 to i32
  %98 = sub nsw i32 %95, %97
  %99 = getelementptr inbounds %struct.arm_2d_region_t, ptr %12, i32 0, i32 0
  %100 = getelementptr inbounds %struct.arm_2d_location_t, ptr %99, i32 0, i32 0
  %101 = load i16, ptr %100, align 2, !tbaa !11
  %102 = sext i16 %101 to i32
  %103 = add nsw i32 %102, %98
  %104 = trunc i32 %103 to i16
  store i16 %104, ptr %100, align 2, !tbaa !11
  %105 = load ptr, ptr %6, align 8, !tbaa !5
  %106 = load i16, ptr %9, align 2, !tbaa !9
  store i16 %106, ptr %16, align 2, !tbaa !11
  %107 = load i8, ptr %10, align 1, !tbaa !11
  %108 = getelementptr inbounds %union.arm_2d_color_rgb565_t, ptr %16, i32 0, i32 0
  %109 = load i16, ptr %108, align 2
  %110 = call i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef null, ptr noundef %105, ptr noundef %12, i16 %109, i8 noundef zeroext %107)
  %111 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  ret void
}

declare i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef, ptr noundef, ptr noundef, i16, i8 noundef zeroext) #5

declare zeroext i1 @arm_2d_op_wait_async(ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { "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 #6 = { noreturn nounwind }
attributes #7 = { 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 = !{!"short", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{i64 0, i64 2, !9, i64 2, i64 2, !9}
!13 = !{i64 0, i64 4, !11, i64 4, i64 4, !11}


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

%struct.arm_2d_region_t = type { %union.anon, %union.anon.1 }
%union.anon = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.1 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }

@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__.arm_2d_helper_draw_box = external hidden unnamed_addr constant [104 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @arm_2d_helper_draw_box(ptr noundef %0, ptr noundef readonly %1, i16 noundef signext %2, i16 noundef zeroext %3, i8 noundef zeroext %4) local_unnamed_addr #2 {
  %6 = alloca %struct.arm_2d_region_t, align 4
  %7 = alloca %struct.arm_2d_region_t, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %8, label %9

8:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.1, i32 noundef 600, ptr noundef nonnull @__PRETTY_FUNCTION__.arm_2d_helper_draw_box) #4
  unreachable

9:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6)
  store i32 0, ptr %6, align 4
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i32, ptr %10, align 4
  %.4.sroa_idx = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %11, ptr %.4.sroa_idx, align 4
  %12 = icmp eq ptr %1, null
  %spec.store.select = select i1 %12, ptr %6, ptr %1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  %13 = load i64, ptr %spec.store.select, align 2
  store i64 %13, ptr %7, align 8
  %14 = getelementptr inbounds i8, ptr %7, i64 4
  %15 = getelementptr inbounds i8, ptr %7, i64 6
  store i16 %2, ptr %15, align 2, !tbaa !5
  %16 = call i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef null, ptr noundef nonnull %0, ptr noundef nonnull %7, i16 %3, i8 noundef zeroext %4) #5
  %17 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null) #5
  %spec.store.select.sroa.sel.v = select i1 %12, ptr %6, ptr %1
  %spec.store.select.sroa.sel = getelementptr inbounds i8, ptr %spec.store.select.sroa.sel.v, i64 4
  %spec.store.select.sroa.sel30.v.sroa.sel.v.sroa.sel.v = select i1 %12, ptr %6, ptr %1
  %spec.store.select.sroa.sel30.v.sroa.sel.v.sroa.sel = getelementptr inbounds i8, ptr %spec.store.select.sroa.sel30.v.sroa.sel.v.sroa.sel.v, i64 6
  %18 = load i16, ptr %spec.store.select.sroa.sel30.v.sroa.sel.v.sroa.sel, align 2, !tbaa !5
  %19 = sub i16 %18, %2
  %20 = getelementptr inbounds i8, ptr %7, i64 2
  %21 = load i16, ptr %20, align 2, !tbaa !5
  %22 = add i16 %19, %21
  store i16 %22, ptr %20, align 2, !tbaa !5
  %23 = call i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef null, ptr noundef nonnull %0, ptr noundef nonnull %7, i16 %3, i8 noundef zeroext %4) #5
  %24 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null) #5
  %25 = load i64, ptr %spec.store.select, align 2
  store i64 %25, ptr %7, align 8
  store i16 %2, ptr %14, align 4, !tbaa !5
  %26 = lshr i64 %25, 16
  %27 = trunc i64 %26 to i16
  %28 = add i16 %27, %2
  store i16 %28, ptr %20, align 2, !tbaa !5
  %29 = shl i16 %2, 1
  %30 = lshr i64 %25, 48
  %31 = trunc nuw i64 %30 to i16
  %32 = sub i16 %31, %29
  store i16 %32, ptr %15, align 2, !tbaa !5
  %33 = call i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef null, ptr noundef nonnull %0, ptr noundef nonnull %7, i16 %3, i8 noundef zeroext %4) #5
  %34 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null) #5
  %35 = load i16, ptr %spec.store.select.sroa.sel, align 2, !tbaa !5
  %36 = sub i16 %35, %2
  %37 = load i16, ptr %7, align 8, !tbaa !5
  %38 = add i16 %36, %37
  store i16 %38, ptr %7, align 8, !tbaa !5
  %39 = call i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef null, ptr noundef nonnull %0, ptr noundef nonnull %7, i16 %3, i8 noundef zeroext %4) #5
  %40 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6)
  ret void
}

declare i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef, ptr noundef, ptr noundef, i16, i8 noundef zeroext) local_unnamed_addr #3

declare zeroext i1 @arm_2d_op_wait_async(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass