; LLVM IR from ARM-software/Arm-2D :: Helper/Source/arm_2d_helper_font.ll_ (arm_2d_lcd_text_default_a8_font_draw_char)

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

%union.arm_2d_color_rgb565_t = type { i16 }
%struct.arm_2d_size_t = type { i16, i16 }
%struct.arm_2d_location_t = type { i16, i16 }
%struct.arm_2d_tile_t = type { %union.anon, %union.anon.9, %union.anon.12 }
%union.anon = type { %struct.anon }
%struct.anon = type { i8, %union.arm_2d_color_info_t, %union.anon.2 }
%union.arm_2d_color_info_t = type { %struct.anon.0 }
%struct.anon.0 = type { i8 }
%union.anon.2 = type { i16 }
%union.anon.9 = type { %struct.arm_2d_region_t }
%struct.arm_2d_region_t = type { %union.anon.10, %union.anon.11 }
%union.anon.10 = type { %struct.arm_2d_location_t }
%union.anon.11 = type { %struct.arm_2d_size_t }
%union.anon.12 = type { ptr }

; 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: nounwind uwtable
define dso_local i32 @__arm_2d_lcd_text_default_a8_font_draw_char(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i16 noundef zeroext %4, i8 noundef zeroext %5, i32 noundef %6) #2 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i16, align 2
  %14 = alloca i8, align 1
  %15 = alloca i32, align 4
  %16 = alloca %union.arm_2d_color_rgb565_t, align 2
  %17 = alloca %struct.arm_2d_size_t, align 2
  %18 = alloca %struct.arm_2d_location_t, align 2
  %19 = alloca %struct.arm_2d_location_t, align 2
  %20 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store i16 %4, ptr %13, align 2, !tbaa !9
  store i8 %5, ptr %14, align 1, !tbaa !11
  store i32 %6, ptr %15, align 4, !tbaa !12
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = load i32, ptr %15, align 4, !tbaa !12
  %23 = load i32, ptr %15, align 4, !tbaa !12
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %34

25:                                               ; preds = %7
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = load i16, ptr %13, align 2, !tbaa !9
  store i16 %29, ptr %16, align 2, !tbaa !11
  %30 = load i8, ptr %14, align 1, !tbaa !11
  %31 = getelementptr inbounds %union.arm_2d_color_rgb565_t, ptr %16, i32 0, i32 0
  %32 = load i16, ptr %31, align 2
  %33 = call i32 @arm_2dp_rgb565_fill_colour_with_mask_and_opacity(ptr noundef null, ptr noundef %26, ptr noundef %27, ptr noundef %28, i16 %32, i8 noundef zeroext %30)
  store i32 %33, ptr %8, align 4
  br label %85

34:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  %35 = load ptr, ptr %12, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %35, i32 0, i32 1
  %37 = getelementptr inbounds %struct.arm_2d_region_t, ptr %36, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %17, ptr align 4 %37, i64 4, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %38 = getelementptr inbounds %struct.arm_2d_location_t, ptr %18, i32 0, i32 0
  %39 = getelementptr inbounds %struct.arm_2d_size_t, ptr %17, i32 0, i32 0
  %40 = load i16, ptr %39, align 2, !tbaa !15
  %41 = sext i16 %40 to i32
  %42 = ashr i32 %41, 1
  %43 = trunc i32 %42 to i16
  store i16 %43, ptr %38, align 2, !tbaa !17
  %44 = getelementptr inbounds %struct.arm_2d_location_t, ptr %18, i32 0, i32 1
  %45 = getelementptr inbounds %struct.arm_2d_size_t, ptr %17, i32 0, i32 1
  %46 = load i16, ptr %45, align 2, !tbaa !19
  %47 = sext i16 %46 to i32
  %48 = ashr i32 %47, 1
  %49 = trunc i32 %48 to i16
  store i16 %49, ptr %44, align 2, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #5
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.arm_2d_region_t, ptr %50, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %19, ptr align 2 %51, i64 4, i1 false), !tbaa.struct !14
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %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 0
  %55 = load i16, ptr %54, align 2, !tbaa !11
  %56 = sext i16 %55 to i32
  %57 = ashr i32 %56, 1
  %58 = getelementptr inbounds %struct.arm_2d_location_t, ptr %19, i32 0, i32 0
  %59 = load i16, ptr %58, align 2, !tbaa !17
  %60 = sext i16 %59 to i32
  %61 = add nsw i32 %60, %57
  %62 = trunc i32 %61 to i16
  store i16 %62, ptr %58, align 2, !tbaa !17
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.arm_2d_region_t, ptr %63, i32 0, i32 1
  %65 = getelementptr inbounds %struct.arm_2d_size_t, ptr %64, i32 0, i32 1
  %66 = load i16, ptr %65, align 2, !tbaa !11
  %67 = sext i16 %66 to i32
  %68 = ashr i32 %67, 1
  %69 = getelementptr inbounds %struct.arm_2d_location_t, ptr %19, i32 0, i32 1
  %70 = load i16, ptr %69, align 2, !tbaa !20
  %71 = sext i16 %70 to i32
  %72 = add nsw i32 %71, %68
  %73 = trunc i32 %72 to i16
  store i16 %73, ptr %69, align 2, !tbaa !20
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = load i32, ptr %15, align 4, !tbaa !12
  %76 = call float @reinterpret_f32_q16(i32 noundef %75)
  %77 = load i16, ptr %13, align 2, !tbaa !9
  %78 = zext i16 %77 to i64
  %79 = load i8, ptr %14, align 1, !tbaa !11
  %80 = load i32, ptr %18, align 2
  %81 = call i32 @arm_2dp_rgb565_fill_colour_with_mask_opacity_and_transform_prepare(ptr noundef null, ptr noundef %74, i32 %80, float noundef 0.000000e+00, float noundef %76, i64 noundef %78, i8 noundef zeroext %79)
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = call i32 @arm_2dp_tile_transform(ptr noundef null, ptr noundef %82, ptr noundef null, ptr noundef %19)
  store i32 %83, ptr %20, align 4, !tbaa !12
  %84 = load i32, ptr %20, align 4, !tbaa !12
  store i32 %84, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  br label %85

85:                                               ; preds = %34, %25
  %86 = load i32, ptr %8, align 4
  ret i32 %86
}

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

declare i32 @arm_2dp_rgb565_fill_colour_with_mask_opacity_and_transform_prepare(ptr noundef, ptr noundef, i32, float noundef, float noundef, i64 noundef, i8 noundef zeroext) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @reinterpret_f32_q16(i32 noundef) #4

declare i32 @arm_2dp_tile_transform(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { "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 = { inlinehint 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 = { 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 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{i64 0, i64 2, !9, i64 2, i64 2, !9}
!15 = !{!16, !10, i64 0}
!16 = !{!"arm_2d_size_t", !10, i64 0, !10, i64 2}
!17 = !{!18, !10, i64 0}
!18 = !{!"arm_2d_location_t", !10, i64 0, !10, i64 2}
!19 = !{!16, !10, i64 2}
!20 = !{!18, !10, i64 2}


; 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_location_t = type { i16, i16 }

; 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: nounwind uwtable
define dso_local i32 @__arm_2d_lcd_text_default_a8_font_draw_char(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readnone %2, ptr noundef %3, i16 noundef zeroext %4, i8 noundef zeroext %5, i32 noundef %6) local_unnamed_addr #1 {
  %8 = alloca %struct.arm_2d_location_t, align 4
  %9 = icmp eq i32 %6, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = tail call i32 @arm_2dp_rgb565_fill_colour_with_mask_and_opacity(ptr noundef null, ptr noundef %0, ptr noundef %1, ptr noundef %3, i16 %4, i8 noundef zeroext %5) #4
  br label %25

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %3, i64 8
  %.sroa.01.0.copyload = load i16, ptr %13, align 4, !tbaa !5
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 10
  %.sroa.42.0.copyload = load i16, ptr %.sroa.42.0..sroa_idx, align 2, !tbaa !5
  %14 = ashr i16 %.sroa.01.0.copyload, 1
  %15 = ashr i16 %.sroa.42.0.copyload, 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #4
  %16 = load <2 x i16>, ptr %1, align 2
  %17 = getelementptr inbounds i8, ptr %1, i64 4
  %18 = load <2 x i16>, ptr %17, align 2, !tbaa !9
  %19 = ashr <2 x i16> %18, <i16 1, i16 1>
  %20 = add <2 x i16> %19, %16
  store <2 x i16> %20, ptr %8, align 4, !tbaa !5
  %21 = tail call float @reinterpret_f32_q16(i32 noundef %6)
  %22 = zext i16 %4 to i64
  %.sroa.4.0.insert.ext = zext i16 %15 to i32
  %.sroa.4.0.insert.shift = shl nuw i32 %.sroa.4.0.insert.ext, 16
  %.sroa.0.0.insert.ext = zext i16 %14 to i32
  %.sroa.0.0.insert.insert = or disjoint i32 %.sroa.4.0.insert.shift, %.sroa.0.0.insert.ext
  %23 = tail call i32 @arm_2dp_rgb565_fill_colour_with_mask_opacity_and_transform_prepare(ptr noundef null, ptr noundef %3, i32 %.sroa.0.0.insert.insert, float noundef 0.000000e+00, float noundef %21, i64 noundef %22, i8 noundef zeroext %5) #4
  %24 = call i32 @arm_2dp_tile_transform(ptr noundef null, ptr noundef %0, ptr noundef null, ptr noundef nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #4
  br label %25

25:                                               ; preds = %12, %10
  %.0 = phi i32 [ %11, %10 ], [ %24, %12 ]
  ret i32 %.0
}

declare i32 @arm_2dp_rgb565_fill_colour_with_mask_and_opacity(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i16, i8 noundef zeroext) local_unnamed_addr #2

declare i32 @arm_2dp_rgb565_fill_colour_with_mask_opacity_and_transform_prepare(ptr noundef, ptr noundef, i32, float noundef, float noundef, i64 noundef, i8 noundef zeroext) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @reinterpret_f32_q16(i32 noundef) local_unnamed_addr #3

declare i32 @arm_2dp_tile_transform(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { "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 = { inlinehint 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 = { 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SLPVectorizerPass,SROAPass,TailCallElimPass