; LLVM IR from ARM-software/Arm-2D :: examples/common/controls//simple_list.ll_ (arm_2d_simple_list_draw_background)

; 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_region_t = type { %union.anon, %union.anon.0 }
%union.anon = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.0 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%union.arm_2d_color_rgb565_t = type { i16 }
%struct.arm_2d_tile_t = type { %union.anon.1, %union.anon.11, %union.anon.12 }
%union.anon.1 = type { %struct.anon }
%struct.anon = type { i8, %union.arm_2d_color_info_t, %union.anon.4 }
%union.arm_2d_color_info_t = type { %struct.anon.2 }
%struct.anon.2 = type { i8 }
%union.anon.4 = type { i16 }
%union.anon.11 = type { %struct.arm_2d_region_t }
%union.anon.12 = type { ptr }
%struct.__simple_list_t = type { %union.anon.13, %struct.anon.23, %struct.anon.26 }
%union.anon.13 = type { %struct.__arm_2d_list_core_t }
%struct.__arm_2d_list_core_t = type { %struct.anon.14, %struct.anon.16, %struct.anon.20 }
%struct.anon.14 = type { %struct.__arm_2d_list_core_cfg_t }
%struct.__arm_2d_list_core_cfg_t = type { %struct.arm_2d_size_t, ptr, %union.anon.15, ptr, ptr, ptr, i32, ptr, i16, i16, i16, i16, ptr }
%union.anon.15 = type { ptr }
%struct.anon.16 = type { %struct.anon.17, [112 x i8] }
%struct.anon.17 = type { %struct.arm_2d_tile_t, %struct.arm_2d_tile_t, %struct.__arm_2d_list_work_area_t, i8, %union.anon.18 }
%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.18 = type { %struct.anon.19 }
%struct.anon.19 = type { i16 }
%struct.anon.20 = type { i8, i8, i16, i32, %union.anon.21 }
%union.anon.21 = type { %struct.anon.22 }
%struct.anon.22 = type { i16, i16, i16, i16 }
%struct.anon.23 = type { %struct.__simple_list_cfg_t }
%struct.__simple_list_cfg_t = type { i16, i8, i8, i8, %union.anon.24, %union.anon.25, %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.24 = type { %union.COLOUR_TYPE_T }
%union.anon.25 = type { %union.COLOUR_TYPE_T }
%union.COLOUR_TYPE_T = type { i32 }
%struct.anon.26 = type { %struct.arm_2d_list_item_t, i16, i8, i8, %struct.arm_2d_region_t, i64, [2 x %struct.arm_2d_helper_dirty_region_item_t] }
%struct.arm_2d_list_item_t = type { %struct.anon.27, i16, %union.anon.28, ptr, ptr, %struct.anon.30, %struct.arm_2d_margin_t, %struct.arm_2d_size_t, i64 }
%struct.anon.27 = type { ptr }
%union.anon.28 = type { i16 }
%struct.anon.30 = type { i8, i8 }
%struct.arm_2d_margin_t = type { i8, i8, i8, i8 }
%struct.arm_2d_helper_dirty_region_item_t = type { [48 x i8], %struct.arm_2d_region_t }

; Function Attrs: nounwind uwtable
define dso_local i32 @__arm_2d_simple_list_draw_background(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca %struct.arm_2d_region_t, align 2
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca %union.arm_2d_color_rgb565_t, align 2
  %14 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %15 = zext i1 %2 to i8
  store i8 %15, ptr %6, align 1, !tbaa !9
  %16 = load i8, ptr %6, align 1, !tbaa !9, !range !11, !noundef !12
  %17 = trunc i8 %16 to i1
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %18, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.memset.p0.i64(ptr align 2 %8, i8 0, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store ptr null, ptr %9, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %67, %3
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.arm_2d_region_t, ptr %20, i32 1
  store ptr %21, ptr %9, align 8, !tbaa !5
  %22 = icmp eq ptr %20, null
  br i1 %22, label %23, label %28

23:                                               ; preds = %19
  %24 = getelementptr inbounds %struct.arm_2d_region_t, ptr %8, i32 0, i32 1
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %25, i32 0, i32 1
  %27 = getelementptr inbounds %struct.arm_2d_region_t, ptr %26, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %24, ptr align 4 %27, i64 4, i1 false), !tbaa.struct !13
  br label %29

28:                                               ; preds = %19
  br label %29

29:                                               ; preds = %28, %23
  %30 = phi i32 [ 1, %23 ], [ 0, %28 ]
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %72

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %34, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store ptr null, ptr %12, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %64, %33
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %36, i32 1
  store ptr %37, ptr %12, align 8, !tbaa !5
  %38 = icmp eq ptr %36, null
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %66

40:                                               ; preds = %35
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.__simple_list_t, ptr %41, i32 0, i32 1
  %43 = getelementptr inbounds %struct.anon.23, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.__simple_list_cfg_t, ptr %43, i32 0, i32 1
  %45 = load i8, ptr %44, align 2
  %46 = and i8 %45, 1
  %47 = icmp ne i8 %46, 0
  br i1 %47, label %63, label %48

48:                                               ; preds = %40
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.__simple_list_t, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds %struct.anon.23, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds %struct.__simple_list_cfg_t, ptr %52, i32 0, i32 5
  %54 = load i16, ptr %53, align 4, !tbaa !16
  store i16 %54, ptr %13, align 2, !tbaa !16
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.__simple_list_t, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds %struct.anon.23, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds %struct.__simple_list_cfg_t, ptr %57, i32 0, i32 3
  %59 = load i8, ptr %58, align 4, !tbaa !17
  %60 = getelementptr inbounds %union.arm_2d_color_rgb565_t, ptr %13, i32 0, i32 0
  %61 = load i16, ptr %60, align 2
  %62 = call i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef null, ptr noundef %49, ptr noundef %8, i16 %61, i8 noundef zeroext %59)
  br label %63

63:                                               ; preds = %48, %40
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  br label %35, !llvm.loop !30

66:                                               ; preds = %39
  br label %67

67:                                               ; preds = %66
  %68 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null)
  %69 = zext i1 %68 to i8
  store i8 %69, ptr %14, align 1, !tbaa !9
  %70 = load i8, ptr %14, align 1, !tbaa !9, !range !11, !noundef !12
  %71 = trunc i8 %70 to i1
  br label %19, !llvm.loop !32

72:                                               ; preds = %32
  %73 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null)
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  ret i32 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 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

declare i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef, ptr noundef, ptr noundef, i16, i8 noundef zeroext) #4

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

declare zeroext i1 @arm_2d_op_wait_async(ptr noundef) #4

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { 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 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{i64 0, i64 2, !14, i64 2, i64 2, !14}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !7, i64 292}
!18 = !{!"__simple_list_t", !7, i64 0, !19, i64 288, !23, i64 384}
!19 = !{!"", !20, i64 0}
!20 = !{!"__simple_list_cfg_t", !15, i64 0, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !21, i64 20, !21, i64 24, !7, i64 28, !7, i64 29, !15, i64 30, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !22, i64 72, !6, i64 80, !6, i64 88}
!21 = !{!"arm_2d_size_t", !15, i64 0, !15, i64 2}
!22 = !{!"int", !7, i64 0}
!23 = !{!"", !24, i64 0, !15, i64 56, !7, i64 58, !7, i64 58, !7, i64 58, !7, i64 58, !7, i64 58, !7, i64 59, !29, i64 60, !28, i64 72, !7, i64 80}
!24 = !{!"arm_2d_list_item_t", !25, i64 0, !15, i64 8, !7, i64 10, !6, i64 16, !6, i64 24, !26, i64 32, !27, i64 34, !21, i64 38, !28, i64 48}
!25 = !{!"", !6, i64 0}
!26 = !{!"", !7, i64 0, !7, i64 1}
!27 = !{!"arm_2d_margin_t", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!28 = !{!"long", !7, i64 0}
!29 = !{!"arm_2d_region_t", !7, i64 0, !7, i64 4}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}
!32 = distinct !{!32, !31}


; 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_region_t = type { %union.anon, %union.anon.0 }
%union.anon = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.0 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @__arm_2d_simple_list_draw_background(ptr nocapture noundef readonly %0, ptr noundef %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = alloca %struct.arm_2d_region_t, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store i64 0, ptr %4, align 8
  %5 = getelementptr inbounds i8, ptr %4, i64 4
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = getelementptr inbounds i8, ptr %0, i64 290
  %8 = load i32, ptr %6, align 4
  store i32 %8, ptr %5, align 4
  %9 = load i8, ptr %7, align 2
  %10 = and i8 %9, 1
  %.not12 = icmp eq i8 %10, 0
  br i1 %.not12, label %11, label %.critedge

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 292
  %13 = getelementptr inbounds i8, ptr %0, i64 300
  %14 = load i16, ptr %13, align 4, !tbaa !5
  %15 = load i8, ptr %12, align 4, !tbaa !8
  %16 = call i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef null, ptr noundef nonnull %1, ptr noundef nonnull %4, i16 %14, i8 noundef zeroext %15) #3
  br label %.critedge

.critedge:                                        ; preds = %3, %11
  %17 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  %18 = call zeroext i1 @arm_2d_op_wait_async(ptr noundef null) #3
  ret i32 0
}

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

declare i32 @arm_2dp_rgb565_fill_colour_with_opacity(ptr noundef, ptr noundef, ptr noundef, i16, i8 noundef zeroext) local_unnamed_addr #2

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

declare zeroext i1 @arm_2d_op_wait_async(ptr noundef) local_unnamed_addr #2

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !6, i64 292}
!9 = !{!"__simple_list_t", !6, i64 0, !10, i64 288, !16, i64 384}
!10 = !{!"", !11, i64 0}
!11 = !{!"__simple_list_cfg_t", !12, i64 0, !6, i64 2, !6, i64 2, !6, i64 2, !6, i64 2, !6, i64 2, !6, i64 2, !6, i64 2, !6, i64 3, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !13, i64 20, !13, i64 24, !6, i64 28, !6, i64 29, !12, i64 30, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !15, i64 72, !14, i64 80, !14, i64 88}
!12 = !{!"short", !6, i64 0}
!13 = !{!"arm_2d_size_t", !12, i64 0, !12, i64 2}
!14 = !{!"any pointer", !6, i64 0}
!15 = !{!"int", !6, i64 0}
!16 = !{!"", !17, i64 0, !12, i64 56, !6, i64 58, !6, i64 58, !6, i64 58, !6, i64 58, !6, i64 58, !6, i64 59, !22, i64 60, !21, i64 72, !6, i64 80}
!17 = !{!"arm_2d_list_item_t", !18, i64 0, !12, i64 8, !6, i64 10, !14, i64 16, !14, i64 24, !19, i64 32, !20, i64 34, !13, i64 38, !21, i64 48}
!18 = !{!"", !14, i64 0}
!19 = !{!"", !6, i64 0, !6, i64 1}
!20 = !{!"arm_2d_margin_t", !6, i64 0, !6, i64 1, !6, i64 2, !6, i64 3}
!21 = !{!"long", !6, i64 0}
!22 = !{!"arm_2d_region_t", !6, i64 0, !6, i64 4}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass