; LLVM IR from ARM-software/Arm-2D :: examples/common/controls (text_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.text_list_t = type { %union.anon.2, %struct.anon.28 }
%union.anon.2 = type { %struct.__simple_list_t }
%struct.__simple_list_t = type { %union.anon.3, %struct.anon.27, [192 x i8] }
%union.anon.3 = type { %struct.__arm_2d_list_core_t }
%struct.__arm_2d_list_core_t = type { %struct.anon, %struct.anon.5, %struct.anon.24 }
%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.4, ptr, ptr, ptr, i32, ptr, i16, i16, i16, i16, ptr }
%struct.arm_2d_size_t = type { i16, i16 }
%union.anon.4 = type { ptr }
%struct.anon.5 = type { %struct.anon.6, [112 x i8] }
%struct.anon.6 = type { %struct.arm_2d_tile_t, %struct.arm_2d_tile_t, %struct.__arm_2d_list_work_area_t, i8, %union.anon.22 }
%struct.arm_2d_tile_t = type { %union.anon.7, %union.anon.18, %union.anon.21 }
%union.anon.7 = type { %struct.anon.8 }
%struct.anon.8 = type { i8, %union.arm_2d_color_info_t, %union.anon.11 }
%union.arm_2d_color_info_t = type { %struct.anon.9 }
%struct.anon.9 = type { i8 }
%union.anon.11 = type { i16 }
%union.anon.18 = type { %struct.arm_2d_region_t }
%struct.arm_2d_region_t = type { %union.anon.19, %union.anon.20 }
%union.anon.19 = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.20 = type { %struct.arm_2d_size_t }
%union.anon.21 = 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.22 = type { %struct.anon.23 }
%struct.anon.23 = type { i16 }
%struct.anon.24 = type { i8, i8, i16, i32, %union.anon.25 }
%union.anon.25 = type { %struct.anon.26 }
%struct.anon.26 = type { i16, i16, i16, i16 }
%struct.anon.27 = type { %struct.__simple_list_cfg_t }
%struct.__simple_list_cfg_t = type { i16, i8, i8, i8, %union.anon.0, %union.anon.1, %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.0 = type { %union.COLOUR_TYPE_T }
%union.anon.1 = type { %union.COLOUR_TYPE_T }
%union.COLOUR_TYPE_T = type { i32 }
%struct.anon.28 = type { %struct.anon.29 }
%struct.anon.29 = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [1 x i8], align 1
@__PRETTY_FUNCTION__.text_list_get_item_string = external hidden unnamed_addr constant [72 x i8], align 1

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

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

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

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

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 221, ptr noundef @__PRETTY_FUNCTION__.text_list_get_item_string) #3
  unreachable

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

22:                                               ; preds = %12
  store ptr @.str.6, ptr %3, align 8
  br label %38

23:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.text_list_t, ptr %24, i32 0, i32 1
  %26 = getelementptr inbounds %struct.anon.28, ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds %struct.anon.29, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !12
  %29 = load i64, ptr %5, align 8, !tbaa !9
  %30 = getelementptr inbounds ptr, ptr %28, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  store ptr %31, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = icmp eq ptr null, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %23
  store ptr @.str.6, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %37

35:                                               ; preds = %23
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %36, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %37

37:                                               ; preds = %35, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %38

38:                                               ; preds = %37, %22
  %39 = load ptr, ptr %3, align 8
  ret ptr %39
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { noreturn nounwind }
attributes #4 = { 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 584}
!13 = !{!"text_list_t", !7, i64 0, !14, i64 576}
!14 = !{!"", !15, i64 0}
!15 = !{!"", !6, i64 0, !6, i64 8}


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

@.str.6 = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local nonnull ptr @text_list_get_item_string(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 %12

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 584
  %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
  %11 = icmp eq ptr %10, null
  %.str.6. = select i1 %11, ptr @.str.6, ptr %10
  br label %12

12:                                               ; preds = %2, %6
  %.1 = phi ptr [ %.str.6., %6 ], [ @.str.6, %2 ]
  ret ptr %.1
}

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, !12, i64 584}
!9 = !{!"text_list_t", !6, i64 0, !10, i64 576}
!10 = !{!"", !11, i64 0}
!11 = !{!"", !12, i64 0, !12, i64 8}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!12, !12, i64 0}


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