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

; 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, %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 }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.11 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%union.anon.12 = type { ptr }

@c_tileWhiteDotRGB565 = external constant %struct.arm_2d_tile_t, align 8
@s_tDotsLocation = external hidden global [8 x %struct.arm_2d_location_t], section ".bss.noinit", align 16
@s_tAlphaTable = external hidden global [8 x i8], section ".bss.noinit", align 1

; Function Attrs: nounwind uwtable
define dso_local void @busy_wheel_init() #0 {
  %1 = alloca i16, align 2
  %2 = alloca i16, align 2
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 2, ptr %1) #3
  %4 = load i16, ptr getelementptr inbounds (%struct.arm_2d_region_t, ptr getelementptr inbounds (%struct.arm_2d_tile_t, ptr @c_tileWhiteDotRGB565, i32 0, i32 1), i32 0, i32 1), align 4, !tbaa !5
  %5 = sext i16 %4 to i32
  %6 = ashr i32 %5, 2
  %7 = trunc i32 %6 to i16
  store i16 %7, ptr %1, align 2, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 2, ptr %2) #3
  %8 = load i16, ptr getelementptr inbounds (%struct.arm_2d_size_t, ptr getelementptr inbounds (%struct.arm_2d_region_t, ptr getelementptr inbounds (%struct.arm_2d_tile_t, ptr @c_tileWhiteDotRGB565, i32 0, i32 1), i32 0, i32 1), i32 0, i32 1), align 2, !tbaa !5
  %9 = sext i16 %8 to i32
  %10 = ashr i32 %9, 2
  %11 = trunc i32 %10 to i16
  store i16 %11, ptr %2, align 2, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  store i8 0, ptr %3, align 1, !tbaa !5
  br label %12

12:                                               ; preds = %58, %0
  %13 = load i8, ptr %3, align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = icmp slt i32 %14, 8
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  br label %61

17:                                               ; preds = %12
  %18 = load i8, ptr %3, align 1, !tbaa !5
  %19 = uitofp i8 %18 to float
  %20 = fmul float 0x400921FB40000000, %19
  %21 = fdiv float %20, 4.000000e+00
  %22 = call float @arm_sin_f32(float noundef %21)
  %23 = fmul float %22, 3.000000e+01
  %24 = fptosi float %23 to i16
  %25 = sext i16 %24 to i32
  %26 = load i16, ptr %1, align 2, !tbaa !8
  %27 = sext i16 %26 to i32
  %28 = add nsw i32 %25, %27
  %29 = trunc i32 %28 to i16
  %30 = load i8, ptr %3, align 1, !tbaa !5
  %31 = zext i8 %30 to i64
  %32 = getelementptr inbounds [8 x %struct.arm_2d_location_t], ptr @s_tDotsLocation, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.arm_2d_location_t, ptr %32, i32 0, i32 1
  store i16 %29, ptr %33, align 2, !tbaa !10
  %34 = load i8, ptr %3, align 1, !tbaa !5
  %35 = uitofp i8 %34 to float
  %36 = fmul float 0x400921FB40000000, %35
  %37 = fdiv float %36, 4.000000e+00
  %38 = call float @arm_cos_f32(float noundef %37)
  %39 = fmul float %38, 3.000000e+01
  %40 = fptosi float %39 to i16
  %41 = sext i16 %40 to i32
  %42 = load i16, ptr %2, align 2, !tbaa !8
  %43 = sext i16 %42 to i32
  %44 = add nsw i32 %41, %43
  %45 = trunc i32 %44 to i16
  %46 = load i8, ptr %3, align 1, !tbaa !5
  %47 = zext i8 %46 to i64
  %48 = getelementptr inbounds [8 x %struct.arm_2d_location_t], ptr @s_tDotsLocation, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.arm_2d_location_t, ptr %48, i32 0, i32 0
  store i16 %45, ptr %49, align 4, !tbaa !12
  %50 = load i8, ptr %3, align 1, !tbaa !5
  %51 = uitofp i8 %50 to float
  %52 = fmul float %51, 2.550000e+02
  %53 = fdiv float %52, 8.000000e+00
  %54 = fptoui float %53 to i8
  %55 = load i8, ptr %3, align 1, !tbaa !5
  %56 = zext i8 %55 to i64
  %57 = getelementptr inbounds [8 x i8], ptr @s_tAlphaTable, i64 0, i64 %56
  store i8 %54, ptr %57, align 1, !tbaa !5
  br label %58

58:                                               ; preds = %17
  %59 = load i8, ptr %3, align 1, !tbaa !5
  %60 = add i8 %59, 1
  store i8 %60, ptr %3, align 1, !tbaa !5
  br label %12, !llvm.loop !13

61:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 2, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %1) #3
  ret void
}

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

declare float @arm_sin_f32(float noundef) #2

declare float @arm_cos_f32(float noundef) #2

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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"}
!8 = !{!9, !9, i64 0}
!9 = !{!"short", !6, i64 0}
!10 = !{!11, !9, i64 2}
!11 = !{!"arm_2d_location_t", !9, i64 0, !9, i64 2}
!12 = !{!11, !9, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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_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 }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.11 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%union.anon.12 = type { ptr }

@c_tileWhiteDotRGB565 = external local_unnamed_addr constant %struct.arm_2d_tile_t, align 8
@s_tDotsLocation = external hidden local_unnamed_addr global [8 x %struct.arm_2d_location_t], section ".bss.noinit", align 16
@s_tAlphaTable = external hidden local_unnamed_addr global [8 x i8], section ".bss.noinit", align 1

; Function Attrs: nounwind uwtable
define dso_local void @busy_wheel_init() local_unnamed_addr #0 {
  %1 = load i16, ptr getelementptr inbounds (i8, ptr @c_tileWhiteDotRGB565, i64 8), align 8, !tbaa !5
  %2 = ashr i16 %1, 2
  %3 = load i16, ptr getelementptr inbounds (i8, ptr @c_tileWhiteDotRGB565, i64 10), align 2, !tbaa !5
  %4 = ashr i16 %3, 2
  %5 = tail call float @arm_sin_f32(float noundef 0.000000e+00) #2
  %6 = fmul float %5, 3.000000e+01
  %7 = fptosi float %6 to i16
  %8 = add i16 %2, %7
  store i16 %8, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 2), align 2, !tbaa !8
  %9 = tail call float @arm_cos_f32(float noundef 0.000000e+00) #2
  %10 = fmul float %9, 3.000000e+01
  %11 = fptosi float %10 to i16
  %12 = add i16 %4, %11
  store i16 %12, ptr @s_tDotsLocation, align 16, !tbaa !11
  store i8 0, ptr @s_tAlphaTable, align 1, !tbaa !5
  %13 = tail call float @arm_sin_f32(float noundef 0x3FE921FB40000000) #2
  %14 = fmul float %13, 3.000000e+01
  %15 = fptosi float %14 to i16
  %16 = add i16 %2, %15
  store i16 %16, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 6), align 2, !tbaa !8
  %17 = tail call float @arm_cos_f32(float noundef 0x3FE921FB40000000) #2
  %18 = fmul float %17, 3.000000e+01
  %19 = fptosi float %18 to i16
  %20 = add i16 %4, %19
  store i16 %20, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 4), align 4, !tbaa !11
  store i8 31, ptr getelementptr inbounds (i8, ptr @s_tAlphaTable, i64 1), align 1, !tbaa !5
  %21 = tail call float @arm_sin_f32(float noundef 0x3FF921FB40000000) #2
  %22 = fmul float %21, 3.000000e+01
  %23 = fptosi float %22 to i16
  %24 = add i16 %2, %23
  store i16 %24, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 10), align 2, !tbaa !8
  %25 = tail call float @arm_cos_f32(float noundef 0x3FF921FB40000000) #2
  %26 = fmul float %25, 3.000000e+01
  %27 = fptosi float %26 to i16
  %28 = add i16 %4, %27
  store i16 %28, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 8), align 8, !tbaa !11
  store i8 63, ptr getelementptr inbounds (i8, ptr @s_tAlphaTable, i64 2), align 1, !tbaa !5
  %29 = tail call float @arm_sin_f32(float noundef 0x4002D97C80000000) #2
  %30 = fmul float %29, 3.000000e+01
  %31 = fptosi float %30 to i16
  %32 = add i16 %2, %31
  store i16 %32, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 14), align 2, !tbaa !8
  %33 = tail call float @arm_cos_f32(float noundef 0x4002D97C80000000) #2
  %34 = fmul float %33, 3.000000e+01
  %35 = fptosi float %34 to i16
  %36 = add i16 %4, %35
  store i16 %36, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 12), align 4, !tbaa !11
  store i8 95, ptr getelementptr inbounds (i8, ptr @s_tAlphaTable, i64 3), align 1, !tbaa !5
  %37 = tail call float @arm_sin_f32(float noundef 0x400921FB40000000) #2
  %38 = fmul float %37, 3.000000e+01
  %39 = fptosi float %38 to i16
  %40 = add i16 %2, %39
  store i16 %40, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 18), align 2, !tbaa !8
  %41 = tail call float @arm_cos_f32(float noundef 0x400921FB40000000) #2
  %42 = fmul float %41, 3.000000e+01
  %43 = fptosi float %42 to i16
  %44 = add i16 %4, %43
  store i16 %44, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 16), align 16, !tbaa !11
  store i8 127, ptr getelementptr inbounds (i8, ptr @s_tAlphaTable, i64 4), align 1, !tbaa !5
  %45 = tail call float @arm_sin_f32(float noundef 0x400F6A7A00000000) #2
  %46 = fmul float %45, 3.000000e+01
  %47 = fptosi float %46 to i16
  %48 = add i16 %2, %47
  store i16 %48, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 22), align 2, !tbaa !8
  %49 = tail call float @arm_cos_f32(float noundef 0x400F6A7A00000000) #2
  %50 = fmul float %49, 3.000000e+01
  %51 = fptosi float %50 to i16
  %52 = add i16 %4, %51
  store i16 %52, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 20), align 4, !tbaa !11
  store i8 -97, ptr getelementptr inbounds (i8, ptr @s_tAlphaTable, i64 5), align 1, !tbaa !5
  %53 = tail call float @arm_sin_f32(float noundef 0x4012D97C80000000) #2
  %54 = fmul float %53, 3.000000e+01
  %55 = fptosi float %54 to i16
  %56 = add i16 %2, %55
  store i16 %56, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 26), align 2, !tbaa !8
  %57 = tail call float @arm_cos_f32(float noundef 0x4012D97C80000000) #2
  %58 = fmul float %57, 3.000000e+01
  %59 = fptosi float %58 to i16
  %60 = add i16 %4, %59
  store i16 %60, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 24), align 8, !tbaa !11
  store i8 -65, ptr getelementptr inbounds (i8, ptr @s_tAlphaTable, i64 6), align 1, !tbaa !5
  %61 = tail call float @arm_sin_f32(float noundef 0x4015FDBBE0000000) #2
  %62 = fmul float %61, 3.000000e+01
  %63 = fptosi float %62 to i16
  %64 = add i16 %2, %63
  store i16 %64, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 30), align 2, !tbaa !8
  %65 = tail call float @arm_cos_f32(float noundef 0x4015FDBBE0000000) #2
  %66 = fmul float %65, 3.000000e+01
  %67 = fptosi float %66 to i16
  %68 = add i16 %4, %67
  store i16 %68, ptr getelementptr inbounds (i8, ptr @s_tDotsLocation, i64 28), align 4, !tbaa !11
  store i8 -33, ptr getelementptr inbounds (i8, ptr @s_tAlphaTable, i64 7), align 1, !tbaa !5
  ret void
}

declare float @arm_sin_f32(float noundef) local_unnamed_addr #1

declare float @arm_cos_f32(float noundef) local_unnamed_addr #1

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" }
attributes #1 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 2}
!9 = !{!"arm_2d_location_t", !10, i64 0, !10, i64 2}
!10 = !{!"short", !6, i64 0}
!11 = !{!9, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass