; LLVM IR from ARM-software/Arm-2D :: examples/common/controls (spinning_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_op_trans_opa_t = type { %struct.arm_2d_op_core_t, %struct.anon, %struct.anon.0, %union.anon, %struct.anon.2, %struct.__arm_2d_transform_info_t, i8 }
%struct.arm_2d_op_core_t = type { [40 x i8], i64 }
%struct.anon = type { ptr, ptr }
%struct.anon.0 = type { ptr }
%union.anon = type { %struct.anon.1 }
%struct.anon.1 = type { i32 }
%struct.anon.2 = type { ptr, %struct.arm_2d_tile_t }
%struct.arm_2d_tile_t = type { %union.anon.3, %union.anon.14, %union.anon.17 }
%union.anon.3 = type { %struct.anon.4 }
%struct.anon.4 = type { i8, %union.arm_2d_color_info_t, %union.anon.7 }
%union.arm_2d_color_info_t = type { %struct.anon.5 }
%struct.anon.5 = type { i8 }
%union.anon.7 = type { i16 }
%union.anon.14 = type { %struct.arm_2d_region_t }
%struct.arm_2d_region_t = type { %union.anon.15, %union.anon.16 }
%union.anon.15 = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.16 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%union.anon.17 = type { ptr }
%struct.__arm_2d_transform_info_t = type { float, float, float, %struct.arm_2d_point_float_t, %union.anon.18, [40 x i8] }
%struct.arm_2d_point_float_t = type { float, float }
%union.anon.18 = type { i32 }

@s_tMaskRotateCB = external hidden global [2 x %struct.arm_2d_op_trans_opa_t], align 16

; Function Attrs: nounwind uwtable
define dso_local void @spinning_wheel_init() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #3
  store ptr @s_tMaskRotateCB, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %6, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store ptr null, ptr %3, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %33, %0
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.arm_2d_op_trans_opa_t, ptr %8, i32 1
  store ptr %9, ptr %3, align 8, !tbaa !5
  %10 = icmp eq ptr %8, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %7
  %12 = load ptr, ptr %1, align 8, !tbaa !5
  br label %14

13:                                               ; preds = %7
  br label %14

14:                                               ; preds = %13, %11
  %15 = phi i32 [ 1, %11 ], [ 0, %13 ]
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  br label %34

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 2, ptr %5, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %26, %18
  %20 = load i64, ptr %5, align 8, !tbaa !9
  %21 = icmp ugt i64 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %32

23:                                               ; preds = %19
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call ptr @arm_2d_op_init(ptr noundef %24, i64 noundef 184)
  br label %26

26:                                               ; preds = %23
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.arm_2d_op_trans_opa_t, ptr %27, i32 1
  store ptr %28, ptr %1, align 8, !tbaa !5
  %29 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %29, ptr %2, align 8, !tbaa !5
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = add i64 %30, -1
  store i64 %31, ptr %5, align 8, !tbaa !9
  br label %19, !llvm.loop !11

32:                                               ; preds = %22
  br label %33

33:                                               ; preds = %32
  br label %7, !llvm.loop !13

34:                                               ; preds = %17
  ret void
}

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

declare ptr @arm_2d_op_init(ptr noundef, i64 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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_op_trans_opa_t = type { %struct.arm_2d_op_core_t, %struct.anon, %struct.anon.0, %union.anon, %struct.anon.2, %struct.__arm_2d_transform_info_t, i8 }
%struct.arm_2d_op_core_t = type { [40 x i8], i64 }
%struct.anon = type { ptr, ptr }
%struct.anon.0 = type { ptr }
%union.anon = type { %struct.anon.1 }
%struct.anon.1 = type { i32 }
%struct.anon.2 = type { ptr, %struct.arm_2d_tile_t }
%struct.arm_2d_tile_t = type { %union.anon.3, %union.anon.14, %union.anon.17 }
%union.anon.3 = type { %struct.anon.4 }
%struct.anon.4 = type { i8, %union.arm_2d_color_info_t, %union.anon.7 }
%union.arm_2d_color_info_t = type { %struct.anon.5 }
%struct.anon.5 = type { i8 }
%union.anon.7 = type { i16 }
%union.anon.14 = type { %struct.arm_2d_region_t }
%struct.arm_2d_region_t = type { %union.anon.15, %union.anon.16 }
%union.anon.15 = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.16 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%union.anon.17 = type { ptr }
%struct.__arm_2d_transform_info_t = type { float, float, float, %struct.arm_2d_point_float_t, %union.anon.18, [40 x i8] }
%struct.arm_2d_point_float_t = type { float, float }
%union.anon.18 = type { i32 }

@s_tMaskRotateCB = external hidden global [2 x %struct.arm_2d_op_trans_opa_t], align 16

; Function Attrs: nounwind uwtable
define dso_local void @spinning_wheel_init() local_unnamed_addr #0 {
.preheader:
  %0 = tail call ptr @arm_2d_op_init(ptr noundef nonnull @s_tMaskRotateCB, i64 noundef 184) #2
  %1 = tail call ptr @arm_2d_op_init(ptr noundef nonnull getelementptr inbounds (i8, ptr @s_tMaskRotateCB, i64 184), i64 noundef 184) #2
  ret void
}

declare ptr @arm_2d_op_init(ptr noundef, i64 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)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass