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

; 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.anon.13 = type { %struct.arm_2d_region_t, %struct.arm_2d_region_t, %struct.arm_2d_location_t, %struct.anon.14, ptr, i32, i32, i8, i8, %struct.anon.15, %struct.anon.16, %struct.anon.17, %struct.arm_2d_scratch_mem_t, %struct.arm_2d_region_t, ptr }
%struct.arm_2d_location_t = type { i16, i16 }
%struct.anon.14 = type { i16, i16 }
%struct.anon.15 = type { i8, i8 }
%struct.anon.16 = type { %struct.arm_2d_size_t, %struct.arm_2d_size_t, %struct.arm_2d_region_t }
%struct.arm_2d_size_t = type { i16, i16 }
%struct.anon.17 = type { %union.anon.18, i16, i16, [65 x i8] }
%union.anon.18 = type { i16 }
%struct.arm_2d_scratch_mem_t = type { %union.anon.19, i64 }
%union.anon.19 = type { %union.anon.20 }
%union.anon.20 = type { %struct.anon.21 }
%struct.anon.21 = type { i32 }
%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 }

@.str.1 = external hidden unnamed_addr constant [88 x i8], align 1
@s_tLCDTextControl = external hidden global %struct.anon.13, align 8
@.str.6 = external hidden unnamed_addr constant [18 x i8], align 1
@__PRETTY_FUNCTION__.arm_lcd_puts_label = external hidden unnamed_addr constant [54 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; 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) #2

; Function Attrs: nounwind uwtable
declare dso_local void @arm_lcd_text_set_draw_region(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @__arm_lcd_get_string_line_box(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @arm_lcd_puts(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @arm_lcd_puts_label(ptr noundef nonnull %0, i32 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %struct.arm_2d_size_t, align 2
  %6 = alloca %struct.arm_2d_region_t, align 2
  %7 = alloca %struct.arm_2d_region_t, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = icmp ne ptr null, %8
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 1300, ptr noundef @__PRETTY_FUNCTION__.arm_lcd_puts_label) #4
  unreachable

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call i32 @__arm_lcd_get_string_line_box(ptr noundef %13, ptr noundef null)
  store i32 %14, ptr %5, align 2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %6, ptr align 8 getelementptr inbounds (%struct.anon.13, ptr @s_tLCDTextControl, i32 0, i32 1), i64 8, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %15 = getelementptr inbounds %struct.arm_2d_region_t, ptr %7, i32 0, i32 0
  %16 = getelementptr inbounds %struct.arm_2d_region_t, ptr %6, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %15, ptr align 2 %16, i64 4, i1 false), !tbaa.struct !13
  %17 = getelementptr inbounds %struct.arm_2d_region_t, ptr %7, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %17, ptr align 2 %5, i64 4, i1 false), !tbaa.struct !13
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = and i32 %18, 3
  switch i32 %19, label %35 [
    i32 1, label %51
    i32 2, label %20
  ]

20:                                               ; preds = %12
  %21 = getelementptr inbounds %struct.arm_2d_region_t, ptr %6, i32 0, i32 1
  %22 = getelementptr inbounds %struct.arm_2d_size_t, ptr %21, i32 0, i32 0
  %23 = load i16, ptr %22, align 2, !tbaa !12
  %24 = sext i16 %23 to i32
  %25 = getelementptr inbounds %struct.arm_2d_size_t, ptr %5, i32 0, i32 0
  %26 = load i16, ptr %25, align 2, !tbaa !16
  %27 = sext i16 %26 to i32
  %28 = sub nsw i32 %24, %27
  %29 = getelementptr inbounds %struct.arm_2d_region_t, ptr %7, i32 0, i32 0
  %30 = getelementptr inbounds %struct.arm_2d_location_t, ptr %29, i32 0, i32 0
  %31 = load i16, ptr %30, align 2, !tbaa !12
  %32 = sext i16 %31 to i32
  %33 = add nsw i32 %32, %28
  %34 = trunc i32 %33 to i16
  store i16 %34, ptr %30, align 2, !tbaa !12
  br label %51

35:                                               ; preds = %12
  %36 = getelementptr inbounds %struct.arm_2d_region_t, ptr %6, i32 0, i32 1
  %37 = getelementptr inbounds %struct.arm_2d_size_t, ptr %36, i32 0, i32 0
  %38 = load i16, ptr %37, align 2, !tbaa !12
  %39 = sext i16 %38 to i32
  %40 = getelementptr inbounds %struct.arm_2d_size_t, ptr %5, i32 0, i32 0
  %41 = load i16, ptr %40, align 2, !tbaa !16
  %42 = sext i16 %41 to i32
  %43 = sub nsw i32 %39, %42
  %44 = ashr i32 %43, 1
  %45 = getelementptr inbounds %struct.arm_2d_region_t, ptr %7, i32 0, i32 0
  %46 = getelementptr inbounds %struct.arm_2d_location_t, ptr %45, i32 0, i32 0
  %47 = load i16, ptr %46, align 2, !tbaa !12
  %48 = sext i16 %47 to i32
  %49 = add nsw i32 %48, %44
  %50 = trunc i32 %49 to i16
  store i16 %50, ptr %46, align 2, !tbaa !12
  br label %51

51:                                               ; preds = %35, %20, %12
  %52 = load i32, ptr %4, align 4, !tbaa !9
  %53 = and i32 %52, 12
  switch i32 %53, label %69 [
    i32 4, label %85
    i32 8, label %54
  ]

54:                                               ; preds = %51
  %55 = getelementptr inbounds %struct.arm_2d_region_t, ptr %6, i32 0, i32 1
  %56 = getelementptr inbounds %struct.arm_2d_size_t, ptr %55, i32 0, i32 1
  %57 = load i16, ptr %56, align 2, !tbaa !12
  %58 = sext i16 %57 to i32
  %59 = getelementptr inbounds %struct.arm_2d_size_t, ptr %5, i32 0, i32 1
  %60 = load i16, ptr %59, align 2, !tbaa !18
  %61 = sext i16 %60 to i32
  %62 = sub nsw i32 %58, %61
  %63 = getelementptr inbounds %struct.arm_2d_region_t, ptr %7, i32 0, i32 0
  %64 = getelementptr inbounds %struct.arm_2d_location_t, ptr %63, i32 0, i32 1
  %65 = load i16, ptr %64, align 2, !tbaa !12
  %66 = sext i16 %65 to i32
  %67 = add nsw i32 %66, %62
  %68 = trunc i32 %67 to i16
  store i16 %68, ptr %64, align 2, !tbaa !12
  br label %85

69:                                               ; preds = %51
  %70 = getelementptr inbounds %struct.arm_2d_region_t, ptr %6, i32 0, i32 1
  %71 = getelementptr inbounds %struct.arm_2d_size_t, ptr %70, i32 0, i32 1
  %72 = load i16, ptr %71, align 2, !tbaa !12
  %73 = sext i16 %72 to i32
  %74 = getelementptr inbounds %struct.arm_2d_size_t, ptr %5, i32 0, i32 1
  %75 = load i16, ptr %74, align 2, !tbaa !18
  %76 = sext i16 %75 to i32
  %77 = sub nsw i32 %73, %76
  %78 = ashr i32 %77, 1
  %79 = getelementptr inbounds %struct.arm_2d_region_t, ptr %7, i32 0, i32 0
  %80 = getelementptr inbounds %struct.arm_2d_location_t, ptr %79, i32 0, i32 1
  %81 = load i16, ptr %80, align 2, !tbaa !12
  %82 = sext i16 %81 to i32
  %83 = add nsw i32 %82, %78
  %84 = trunc i32 %83 to i16
  store i16 %84, ptr %80, align 2, !tbaa !12
  br label %85

85:                                               ; preds = %69, %54, %51
  call void @arm_lcd_text_set_draw_region(ptr noundef %7)
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  call void @arm_lcd_puts(ptr noundef %86)
  call void @arm_lcd_text_set_draw_region(ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret void
}

attributes #0 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12}
!12 = !{!7, !7, i64 0}
!13 = !{i64 0, i64 2, !14, i64 2, i64 2, !14}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !15, i64 0}
!17 = !{!"arm_2d_size_t", !15, i64 0, !15, i64 2}
!18 = !{!17, !15, 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.anon.13 = type { %struct.arm_2d_region_t, %struct.arm_2d_region_t, %struct.arm_2d_location_t, %struct.anon.14, ptr, i32, i32, i8, i8, %struct.anon.15, %struct.anon.16, %struct.anon.17, %struct.arm_2d_scratch_mem_t, %struct.arm_2d_region_t, ptr }
%struct.arm_2d_location_t = type { i16, i16 }
%struct.anon.14 = type { i16, i16 }
%struct.anon.15 = type { i8, i8 }
%struct.anon.16 = type { %struct.arm_2d_size_t, %struct.arm_2d_size_t, %struct.arm_2d_region_t }
%struct.arm_2d_size_t = type { i16, i16 }
%struct.anon.17 = type { %union.anon.18, i16, i16, [65 x i8] }
%union.anon.18 = type { i16 }
%struct.arm_2d_scratch_mem_t = type { %union.anon.19, i64 }
%union.anon.19 = type { %union.anon.20 }
%union.anon.20 = type { %struct.anon.21 }
%struct.anon.21 = type { i32 }
%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 }

@s_tLCDTextControl = external hidden local_unnamed_addr global %struct.anon.13, align 8

; 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
declare dso_local void @arm_lcd_text_set_draw_region(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @arm_lcd_puts(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @arm_lcd_puts_label(ptr noundef nonnull %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.arm_2d_region_t, align 8
  %4 = alloca %struct.arm_2d_region_t, align 4
  %5 = tail call i32 @__arm_lcd_get_string_line_box(ptr noundef nonnull %0, ptr noundef null)
  %.sroa.0.0.extract.trunc = trunc i32 %5 to i16
  %.sroa.6.0.extract.shift = lshr i32 %5, 16
  %.sroa.6.0.extract.trunc = trunc nuw i32 %.sroa.6.0.extract.shift to i16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  %6 = load i64, ptr getelementptr inbounds (i8, ptr @s_tLCDTextControl, i64 8), align 8
  store i64 %6, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  %7 = trunc i64 %6 to i32
  store i32 %7, ptr %4, align 4
  %8 = getelementptr inbounds i8, ptr %4, i64 4
  store i16 %.sroa.0.0.extract.trunc, ptr %8, align 4, !tbaa !5
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %4, i64 6
  store i16 %.sroa.6.0.extract.trunc, ptr %.sroa.6.0..sroa_idx, align 2, !tbaa !5
  %9 = and i32 %1, 3
  %10 = lshr i64 %6, 32
  %11 = trunc i64 %10 to i16
  %12 = trunc i64 %6 to i16
  %13 = lshr i64 %6, 48
  %14 = trunc nuw i64 %13 to i16
  %15 = lshr i64 %6, 16
  %16 = trunc i64 %15 to i16
  switch i32 %9, label %20 [
    i32 1, label %27
    i32 2, label %17
  ]

17:                                               ; preds = %2
  %18 = sub i16 %11, %.sroa.0.0.extract.trunc
  %19 = add i16 %18, %12
  store i16 %19, ptr %4, align 4, !tbaa !9
  br label %27

20:                                               ; preds = %2
  %21 = sext i16 %11 to i32
  %sext = shl i32 %5, 16
  %22 = ashr exact i32 %sext, 16
  %23 = sub nsw i32 %21, %22
  %24 = lshr i32 %23, 1
  %25 = trunc i32 %24 to i16
  %26 = add i16 %12, %25
  store i16 %26, ptr %4, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %20, %17, %2
  %28 = and i32 %1, 12
  switch i32 %28, label %33 [
    i32 4, label %41
    i32 8, label %29
  ]

29:                                               ; preds = %27
  %30 = getelementptr inbounds i8, ptr %4, i64 2
  %31 = sub i16 %14, %.sroa.6.0.extract.trunc
  %32 = add i16 %31, %16
  store i16 %32, ptr %30, align 2, !tbaa !9
  br label %41

33:                                               ; preds = %27
  %34 = sext i16 %14 to i32
  %35 = ashr i32 %5, 16
  %36 = sub nsw i32 %34, %35
  %37 = lshr i32 %36, 1
  %38 = getelementptr inbounds i8, ptr %4, i64 2
  %39 = trunc i32 %37 to i16
  %40 = add i16 %16, %39
  store i16 %40, ptr %38, align 2, !tbaa !9
  br label %41

41:                                               ; preds = %33, %29, %27
  call void @arm_lcd_text_set_draw_region(ptr noundef nonnull %4)
  call void @arm_lcd_puts(ptr noundef nonnull %0)
  call void @arm_lcd_text_set_draw_region(ptr noundef nonnull %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  ret void
}

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 = { 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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass