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

; 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_a1_font_t = type { %union.anon.3, i32 }
%union.anon.3 = type { %struct.arm_2d_font_t }
%struct.arm_2d_font_t = type { %struct.arm_2d_tile_t, %struct.arm_2d_size_t, i32, ptr, ptr }
%struct.arm_2d_tile_t = type { %union.anon.4, %union.anon.15, %union.anon.16 }
%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, %union.anon.2 }
%union.anon = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.2 = type { %struct.arm_2d_size_t }
%union.anon.16 = type { ptr }
%struct.arm_2d_size_t = type { i16, i16 }
%struct.text_box_t = type { %struct.anon }
%struct.anon = type { %struct.text_box_cfg_t, %struct.anon.0, i32, i16, i16, %struct.__text_box_line_info_t, [1 x %struct.arm_2d_helper_dirty_region_item_t] }
%struct.text_box_cfg_t = type { ptr, float, %struct.text_box_io_text_stream_reader_t, ptr, i8, i8 }
%struct.text_box_io_text_stream_reader_t = type { ptr, i64 }
%struct.anon.0 = type { i32, i32 }
%struct.__text_box_line_info_t = type { %struct.anon.1 }
%struct.anon.1 = type { ptr, i32, i32, i16, i16, i16, i16, i16, i16, i32 }
%struct.arm_2d_helper_dirty_region_item_t = type { [48 x i8], %struct.arm_2d_region_t }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [89 x i8], align 1
@__PRETTY_FUNCTION__.text_box_init = external hidden unnamed_addr constant [51 x i8], align 1
@ARM_2D_FONT_6x8 = external constant %struct.arm_2d_a1_font_t, align 8

; Function Attrs: nounwind uwtable
define dso_local void @text_box_init(ptr noundef nonnull %0, ptr noundef nonnull %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %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 346, ptr noundef @__PRETTY_FUNCTION__.text_box_init) #4
  unreachable

9:                                                ; preds = %7
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 152, i1 false)
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.text_box_t, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %struct.anon, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %13, ptr align 8 %14, i64 48, i1 false), !tbaa.struct !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.text_box_t, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.anon, ptr %16, i32 0, i32 0
  %18 = getelementptr inbounds %struct.text_box_cfg_t, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = icmp eq ptr null, %19
  br i1 %20, label %21, label %26

21:                                               ; preds = %9
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.text_box_t, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.anon, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.text_box_cfg_t, ptr %24, i32 0, i32 0
  store ptr @ARM_2D_FONT_6x8, ptr %25, align 8, !tbaa !15
  br label %26

26:                                               ; preds = %21, %9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.text_box_cfg_t, ptr %27, i32 0, i32 4
  %29 = load i8, ptr %28, align 8
  %30 = lshr i8 %29, 6
  %31 = and i8 %30, 1
  %32 = zext i8 %31 to i32
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %42

34:                                               ; preds = %26
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.text_box_t, ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %struct.anon, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds %struct.text_box_cfg_t, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !25
  %40 = icmp ne ptr null, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %34
  br label %42

42:                                               ; preds = %41, %34, %26
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{i64 0, i64 8, !5, i64 8, i64 4, !10, i64 16, i64 8, !5, i64 24, i64 8, !12, i64 32, i64 8, !5, i64 40, i64 1, !14, i64 41, i64 1, !14}
!10 = !{!11, !11, i64 0}
!11 = !{!"float", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"text_box_t", !17, i64 0}
!17 = !{!"", !18, i64 0, !20, i64 48, !21, i64 56, !22, i64 60, !22, i64 62, !23, i64 64, !7, i64 96}
!18 = !{!"text_box_cfg_t", !6, i64 0, !11, i64 8, !19, i64 16, !6, i64 32, !7, i64 40, !7, i64 40, !7, i64 41}
!19 = !{!"text_box_io_text_stream_reader_t", !6, i64 0, !13, i64 8}
!20 = !{!"", !21, i64 0, !21, i64 4}
!21 = !{!"int", !7, i64 0}
!22 = !{!"short", !7, i64 0}
!23 = !{!"__text_box_line_info_t", !24, i64 0}
!24 = !{!"", !6, i64 0, !21, i64 8, !21, i64 12, !22, i64 16, !22, i64 18, !22, i64 20, !22, i64 22, !22, i64 24, !22, i64 26, !21, i64 28}
!25 = !{!16, !6, i64 32}


; 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_a1_font_t = type { %union.anon.3, i32 }
%union.anon.3 = type { %struct.arm_2d_font_t }
%struct.arm_2d_font_t = type { %struct.arm_2d_tile_t, %struct.arm_2d_size_t, i32, ptr, ptr }
%struct.arm_2d_tile_t = type { %union.anon.4, %union.anon.15, %union.anon.16 }
%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, %union.anon.2 }
%union.anon = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.2 = type { %struct.arm_2d_size_t }
%union.anon.16 = type { ptr }
%struct.arm_2d_size_t = type { i16, i16 }

@ARM_2D_FONT_6x8 = external constant %struct.arm_2d_a1_font_t, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @text_box_init(ptr nocapture noundef nonnull %0, ptr nocapture noundef nonnull readonly %1) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(152) %0, i8 0, i64 152, i1 false)
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(48) %1, i64 48, i1 false), !tbaa.struct !5
  %3 = load ptr, ptr %0, align 8, !tbaa !15
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %2
  store ptr @ARM_2D_FONT_6x8, ptr %0, align 8, !tbaa !15
  br label %6

6:                                                ; preds = %5, %2
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = !{i64 0, i64 8, !6, i64 8, i64 4, !10, i64 16, i64 8, !6, i64 24, i64 8, !12, i64 32, i64 8, !6, i64 40, i64 1, !14, i64 41, i64 1, !14}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"text_box_t", !17, i64 0}
!17 = !{!"", !18, i64 0, !20, i64 48, !21, i64 56, !22, i64 60, !22, i64 62, !23, i64 64, !8, i64 96}
!18 = !{!"text_box_cfg_t", !7, i64 0, !11, i64 8, !19, i64 16, !7, i64 32, !8, i64 40, !8, i64 40, !8, i64 41}
!19 = !{!"text_box_io_text_stream_reader_t", !7, i64 0, !13, i64 8}
!20 = !{!"", !21, i64 0, !21, i64 4}
!21 = !{!"int", !8, i64 0}
!22 = !{!"short", !8, i64 0}
!23 = !{!"__text_box_line_info_t", !24, i64 0}
!24 = !{!"", !7, i64 0, !21, i64 8, !21, i64 12, !22, i64 16, !22, i64 18, !22, i64 20, !22, i64 22, !22, i64 24, !22, i64 26, !21, i64 28}


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