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

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@__PRETTY_FUNCTION__.progress_wheel_set_diameter = external hidden unnamed_addr constant [62 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local void @progress_wheel_set_diameter(ptr noundef nonnull %0, i16 noundef signext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i16 %1, ptr %4, align 2, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = icmp ne ptr null, %5
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  br label %9

8:                                                ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 170, ptr noundef @__PRETTY_FUNCTION__.progress_wheel_set_diameter) #2
  unreachable

9:                                                ; preds = %7
  %10 = load i16, ptr %4, align 2, !tbaa !9
  %11 = sext i16 %10 to i32
  %12 = icmp eq i32 0, %11
  br i1 %12, label %13, label %33

13:                                               ; preds = %9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.progress_wheel_t, ptr %14, i32 0, i32 0
  %16 = getelementptr inbounds %struct.anon, ptr %15, i32 0, i32 2
  store float 1.000000e+00, ptr %16, align 8, !tbaa !11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.progress_wheel_t, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.anon, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds %struct.progress_wheel_cfg_t, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !22
  %22 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds %struct.arm_2d_region_t, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds %struct.arm_2d_size_t, ptr %23, i32 0, i32 0
  %25 = load i16, ptr %24, align 4, !tbaa !23
  %26 = sext i16 %25 to i32
  %27 = mul nsw i32 %26, 2
  %28 = trunc i32 %27 to i16
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.progress_wheel_t, ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds %struct.anon, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds %struct.progress_wheel_cfg_t, ptr %31, i32 0, i32 2
  store i16 %28, ptr %32, align 8, !tbaa !24
  br label %56

33:                                               ; preds = %9
  %34 = load i16, ptr %4, align 2, !tbaa !9
  %35 = sitofp i16 %34 to float
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.progress_wheel_t, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds %struct.anon, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.progress_wheel_cfg_t, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !22
  %41 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds %struct.arm_2d_region_t, ptr %41, i32 0, i32 1
  %43 = getelementptr inbounds %struct.arm_2d_size_t, ptr %42, i32 0, i32 0
  %44 = load i16, ptr %43, align 4, !tbaa !23
  %45 = sitofp i16 %44 to float
  %46 = fmul float %45, 2.000000e+00
  %47 = fdiv float %35, %46
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.progress_wheel_t, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds %struct.anon, ptr %49, i32 0, i32 2
  store float %47, ptr %50, align 8, !tbaa !11
  %51 = load i16, ptr %4, align 2, !tbaa !9
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.progress_wheel_t, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds %struct.anon, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds %struct.progress_wheel_cfg_t, ptr %54, i32 0, i32 2
  store i16 %51, ptr %55, align 8, !tbaa !24
  br label %56

56:                                               ; preds = %33, %13
  ret void
}

attributes #0 = { 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 #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 = { noreturn 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 = !{!12, !16, i64 40}
!12 = !{!"progress_wheel_t", !13, i64 0}
!13 = !{!"", !14, i64 0, !6, i64 32, !16, i64 40, !16, i64 44, !7, i64 48, !17, i64 1336, !20, i64 1456, !21, i64 1488, !7, i64 1512, !10, i64 1514, !10, i64 1516, !10, i64 1518, !15, i64 1520}
!14 = !{!"progress_wheel_cfg_t", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 18, !10, i64 20, !10, i64 22, !15, i64 24, !15, i64 24, !15, i64 24, !15, i64 26}
!15 = !{!"int", !7, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!"arm_2d_helper_dirty_region_transform_t", !16, i64 0, !7, i64 4, !16, i64 8, !18, i64 16, !7, i64 72}
!18 = !{!"arm_2d_helper_dirty_region_item_t", !7, i64 0, !19, i64 48}
!19 = !{!"arm_2d_region_t", !7, i64 0, !7, i64 4}
!20 = !{!"arm_2d_region_list_item_t", !6, i64 0, !7, i64 8, !19, i64 16, !7, i64 24}
!21 = !{!"arm_2d_tile_t", !7, i64 0, !7, i64 4, !7, i64 16}
!22 = !{!12, !6, i64 0}
!23 = !{!7, !7, i64 0}
!24 = !{!12, !10, i64 16}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @progress_wheel_set_diameter(ptr nocapture noundef nonnull %0, i16 noundef signext %1) local_unnamed_addr #0 {
  %3 = icmp eq i16 %1, 0
  br i1 %3, label %4, label %10

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  store float 1.000000e+00, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %0, align 8, !tbaa !20
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load i16, ptr %7, align 4, !tbaa !21
  %9 = shl i16 %8, 1
  br label %19

10:                                               ; preds = %2
  %11 = sitofp i16 %1 to float
  %12 = load ptr, ptr %0, align 8, !tbaa !20
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = load i16, ptr %13, align 4, !tbaa !21
  %15 = sitofp i16 %14 to float
  %16 = fmul float %15, 2.000000e+00
  %17 = fdiv float %11, %16
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  store float %17, ptr %18, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %10, %4
  %.sink = phi i16 [ %9, %4 ], [ %1, %10 ]
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  store i16 %.sink, ptr %20, align 8
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

!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, !14, i64 40}
!6 = !{!"progress_wheel_t", !7, i64 0}
!7 = !{!"", !8, i64 0, !9, i64 32, !14, i64 40, !14, i64 44, !10, i64 48, !15, i64 1336, !18, i64 1456, !19, i64 1488, !10, i64 1512, !12, i64 1514, !12, i64 1516, !12, i64 1518, !13, i64 1520}
!8 = !{!"progress_wheel_cfg_t", !9, i64 0, !9, i64 8, !12, i64 16, !12, i64 18, !12, i64 20, !12, i64 22, !13, i64 24, !13, i64 24, !13, i64 24, !13, i64 26}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"short", !10, i64 0}
!13 = !{!"int", !10, i64 0}
!14 = !{!"float", !10, i64 0}
!15 = !{!"arm_2d_helper_dirty_region_transform_t", !14, i64 0, !10, i64 4, !14, i64 8, !16, i64 16, !10, i64 72}
!16 = !{!"arm_2d_helper_dirty_region_item_t", !10, i64 0, !17, i64 48}
!17 = !{!"arm_2d_region_t", !10, i64 0, !10, i64 4}
!18 = !{!"arm_2d_region_list_item_t", !9, i64 0, !10, i64 8, !17, i64 16, !10, i64 24}
!19 = !{!"arm_2d_tile_t", !10, i64 0, !10, i64 4, !10, i64 16}
!20 = !{!6, !9, i64 0}
!21 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass