; 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.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 }
%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 }
%struct.arm_2d_size_t = type { i16, i16 }

@.str.1 = external hidden unnamed_addr constant [89 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__.text_box_set_start_line = external hidden unnamed_addr constant [55 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 @text_box_set_start_line(ptr noundef nonnull %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, 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.2, ptr noundef @.str.1, i32 noundef 421, ptr noundef @__PRETTY_FUNCTION__.text_box_set_start_line) #3
  unreachable

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %30, %12
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds i32, ptr %14, i32 1
  store ptr %15, ptr %7, align 8, !tbaa !5
  %16 = icmp eq ptr %14, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %31

18:                                               ; preds = %13
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.text_box_t, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 8, !tbaa !11
  store i32 %22, ptr %5, align 4, !tbaa !9
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = icmp sge i32 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %18
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.text_box_t, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds %struct.anon, ptr %28, i32 0, i32 2
  store i32 %26, ptr %29, align 8, !tbaa !11
  br label %30

30:                                               ; preds = %25, %18
  br label %13, !llvm.loop !22

31:                                               ; preds = %17
  %32 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %32
}

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

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

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


; 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: readwrite) uwtable
define dso_local i32 @text_box_set_start_line(ptr nocapture noundef nonnull %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 56
  %4 = icmp sgt i32 %1, -1
  %.promoted = load i32, ptr %3, align 8, !tbaa !5
  br i1 %4, label %.split.us, label %.split

.split.us:                                        ; preds = %2
  store i32 %1, ptr %3, align 8, !tbaa !5
  br label %.split

.split:                                           ; preds = %2, %.split.us
  ret i32 %.promoted
}

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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass