; LLVM IR from ARM-software/Arm-2D :: examples/common/controls (icon_list)

; 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.icon_list_t = type { %union.anon, %struct.anon.27 }
%union.anon = type { %struct.__simple_list_t }
%struct.__simple_list_t = type { %union.anon.0, %struct.anon.24, [192 x i8] }
%union.anon.0 = type { %struct.__arm_2d_list_core_t }
%struct.__arm_2d_list_core_t = type { %struct.anon, %struct.anon.2, %struct.anon.21 }
%struct.anon = type { %struct.__arm_2d_list_core_cfg_t }
%struct.__arm_2d_list_core_cfg_t = type { %struct.arm_2d_size_t, ptr, %union.anon.1, ptr, ptr, ptr, i32, ptr, i16, i16, i16, i16, ptr }
%struct.arm_2d_size_t = type { i16, i16 }
%union.anon.1 = type { ptr }
%struct.anon.2 = type { %struct.anon.3, [112 x i8] }
%struct.anon.3 = type { %struct.arm_2d_tile_t, %struct.arm_2d_tile_t, %struct.__arm_2d_list_work_area_t, i8, %union.anon.19 }
%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 }
%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 }
%union.anon.18 = type { ptr }
%struct.__arm_2d_list_work_area_t = type { ptr, %struct.arm_2d_region_t, %struct.arm_2d_list_item_param_t, i32 }
%struct.arm_2d_list_item_param_t = type { i8, i8, i16 }
%union.anon.19 = type { %struct.anon.20 }
%struct.anon.20 = type { i16 }
%struct.anon.21 = type { i8, i8, i16, i32, %union.anon.22 }
%union.anon.22 = type { %struct.anon.23 }
%struct.anon.23 = type { i16, i16, i16, i16 }
%struct.anon.24 = type { %struct.__simple_list_cfg_t }
%struct.__simple_list_cfg_t = type { i16, i8, i8, i8, %union.anon.25, %union.anon.26, %union.COLOUR_TYPE_T, %struct.arm_2d_size_t, %struct.arm_2d_size_t, i8, i8, i16, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr }
%union.anon.25 = type { %union.COLOUR_TYPE_T }
%union.anon.26 = type { %union.COLOUR_TYPE_T }
%union.COLOUR_TYPE_T = type { i32 }
%struct.anon.27 = type { ptr, i16 }

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [90 x i8], align 1
@__PRETTY_FUNCTION__.icon_list_get_item_icon = external hidden unnamed_addr constant [75 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 ptr @icon_list_get_item_icon(ptr noundef nonnull %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp ne ptr null, %6
  br i1 %7, label %8, label %9

8:                                                ; preds = %2
  br label %10

9:                                                ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 214, ptr noundef @__PRETTY_FUNCTION__.icon_list_get_item_icon) #2
  unreachable

10:                                               ; preds = %8
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.icon_list_t, ptr %12, i32 0, i32 0
  %14 = getelementptr inbounds %struct.__simple_list_t, ptr %13, i32 0, i32 1
  %15 = getelementptr inbounds %struct.anon.24, ptr %14, i32 0, i32 0
  %16 = getelementptr inbounds %struct.__simple_list_cfg_t, ptr %15, i32 0, i32 0
  %17 = load i16, ptr %16, align 8, !tbaa !11
  %18 = zext i16 %17 to i64
  %19 = icmp uge i64 %11, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %10
  store ptr null, ptr %3, align 8
  br label %29

21:                                               ; preds = %10
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.icon_list_t, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds %struct.anon.27, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds ptr, ptr %25, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  store ptr %28, ptr %3, align 8
  br label %29

29:                                               ; preds = %21, %20
  %30 = load ptr, ptr %3, align 8
  ret ptr %30
}

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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 576}
!13 = !{!"icon_list_t", !7, i64 0, !14, i64 576}
!14 = !{!"", !6, i64 0, !15, i64 8}
!15 = !{!"short", !7, i64 0}


; 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, inaccessiblemem: none) uwtable
define dso_local ptr @icon_list_get_item_icon(ptr nocapture noundef nonnull readonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 288
  %4 = load i16, ptr %3, align 8, !tbaa !5
  %5 = zext i16 %4 to i64
  %.not = icmp ugt i64 %5, %1
  br i1 %.not, label %6, label %11

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 576
  %8 = load ptr, ptr %7, align 8, !tbaa !8
  %9 = getelementptr inbounds ptr, ptr %8, i64 %1
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  br label %11

11:                                               ; preds = %2, %6
  %.0 = phi ptr [ %10, %6 ], [ null, %2 ]
  ret ptr %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !11, i64 576}
!9 = !{!"icon_list_t", !6, i64 0, !10, i64 576}
!10 = !{!"", !11, i64 0, !12, i64 8}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!"short", !6, i64 0}
!13 = !{!11, !11, i64 0}


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