; LLVM IR from ARM-software/Arm-2D :: examples/common/controls (number_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.number_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, i32, i16 }

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [92 x i8], align 1
@__PRETTY_FUNCTION__.number_list_get_item_number = external hidden unnamed_addr constant [68 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 i32 @number_list_get_item_number(ptr noundef nonnull %0, i64 noundef %1) #1 {
  %3 = alloca i32, align 4
  %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 212, ptr noundef @__PRETTY_FUNCTION__.number_list_get_item_number) #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.number_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 i32 -1, ptr %3, align 4
  br label %36

21:                                               ; preds = %10
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.number_list_t, ptr %22, i32 0, i32 1
  %24 = getelementptr inbounds %struct.anon.27, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !12
  %26 = sext i32 %25 to i64
  %27 = load i64, ptr %5, align 8, !tbaa !9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.number_list_t, ptr %28, i32 0, i32 1
  %30 = getelementptr inbounds %struct.anon.27, ptr %29, i32 0, i32 2
  %31 = load i16, ptr %30, align 4, !tbaa !17
  %32 = sext i16 %31 to i64
  %33 = mul i64 %27, %32
  %34 = add i64 %26, %33
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %3, align 4
  br label %36

36:                                               ; preds = %21, %20
  %37 = load i32, ptr %3, align 4
  ret i32 %37
}

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, !15, i64 584}
!13 = !{!"number_list_t", !7, i64 0, !14, i64 576}
!14 = !{!"", !6, i64 0, !15, i64 8, !16, i64 12}
!15 = !{!"int", !7, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = !{!13, !16, i64 588}


; 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(argmem: read) uwtable
define dso_local i32 @number_list_get_item_number(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 %15

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 584
  %8 = load i32, ptr %7, align 8, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %0, i64 588
  %10 = load i16, ptr %9, align 4, !tbaa !14
  %11 = sext i16 %10 to i64
  %12 = mul nsw i64 %11, %1
  %13 = trunc i64 %12 to i32
  %14 = add i32 %8, %13
  br label %15

15:                                               ; preds = %2, %6
  %.0 = phi i32 [ %14, %6 ], [ -1, %2 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !12, i64 584}
!9 = !{!"number_list_t", !6, i64 0, !10, i64 576}
!10 = !{!"", !11, i64 0, !12, i64 8, !13, i64 12}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!"short", !6, i64 0}
!14 = !{!9, !13, i64 588}


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