; LLVM IR from ARM-software/Arm-2D :: Helper/Source (arm_2d_helper)

; 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_helper_film_t = type { %union.anon.16, i16, i16, i16, i16 }
%union.anon.16 = type { %struct.arm_2d_tile_t }
%struct.arm_2d_tile_t = type { %union.anon.2, %union.anon.13, %union.anon.14 }
%union.anon.2 = type { %struct.anon.3 }
%struct.anon.3 = type { i8, %union.arm_2d_color_info_t, %union.anon.6 }
%union.arm_2d_color_info_t = type { %struct.anon.4 }
%struct.anon.4 = type { i8 }
%union.anon.6 = type { i16 }
%union.anon.13 = type { %struct.arm_2d_region_t }
%struct.arm_2d_region_t = type { %union.anon, %union.anon.1 }
%union.anon = type { %struct.arm_2d_location_t }
%struct.arm_2d_location_t = type { i16, i16 }
%union.anon.1 = type { %struct.arm_2d_size_t }
%struct.arm_2d_size_t = type { i16, i16 }
%union.anon.14 = type { ptr }

@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__.arm_2d_helper_film_set_frame = external hidden unnamed_addr constant [67 x i8], align 1

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

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

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

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

10:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.arm_2d_helper_film_t, ptr %11, i32 0, i32 0
  store ptr %12, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.arm_2d_helper_film_t, ptr %13, i32 0, i32 2
  %15 = load i16, ptr %14, align 2, !tbaa !11
  %16 = zext i16 %15 to i32
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = srem i32 %17, %16
  store i32 %18, ptr %4, align 4, !tbaa !9
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = icmp slt i32 %19, 0
  br i1 %20, label %21, label %28

21:                                               ; preds = %10
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.arm_2d_helper_film_t, ptr %22, i32 0, i32 2
  %24 = load i16, ptr %23, align 2, !tbaa !11
  %25 = zext i16 %24 to i32
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = add nsw i32 %26, %25
  store i32 %27, ptr %4, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %21, %10
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = trunc i32 %29 to i16
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.arm_2d_helper_film_t, ptr %31, i32 0, i32 4
  store i16 %30, ptr %32, align 2, !tbaa !14
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.arm_2d_helper_film_t, ptr %34, i32 0, i32 1
  %36 = load i16, ptr %35, align 8, !tbaa !15
  %37 = zext i16 %36 to i32
  %38 = srem i32 %33, %37
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %39, i32 0, i32 1
  %41 = getelementptr inbounds %struct.arm_2d_region_t, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds %struct.arm_2d_size_t, ptr %41, i32 0, i32 0
  %43 = load i16, ptr %42, align 4, !tbaa !16
  %44 = sext i16 %43 to i32
  %45 = mul nsw i32 %38, %44
  %46 = trunc i32 %45 to i16
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %47, i32 0, i32 1
  %49 = getelementptr inbounds %struct.arm_2d_region_t, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds %struct.arm_2d_location_t, ptr %49, i32 0, i32 0
  store i16 %46, ptr %50, align 4, !tbaa !16
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.arm_2d_helper_film_t, ptr %52, i32 0, i32 1
  %54 = load i16, ptr %53, align 8, !tbaa !15
  %55 = zext i16 %54 to i32
  %56 = sdiv i32 %51, %55
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %57, i32 0, i32 1
  %59 = getelementptr inbounds %struct.arm_2d_region_t, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds %struct.arm_2d_size_t, ptr %59, i32 0, i32 1
  %61 = load i16, ptr %60, align 2, !tbaa !16
  %62 = sext i16 %61 to i32
  %63 = mul nsw i32 %56, %62
  %64 = trunc i32 %63 to i16
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.arm_2d_tile_t, ptr %65, i32 0, i32 1
  %67 = getelementptr inbounds %struct.arm_2d_region_t, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds %struct.arm_2d_location_t, ptr %67, i32 0, i32 1
  store i16 %64, ptr %68, align 2, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 26}
!12 = !{!"arm_2d_helper_film_t", !7, i64 0, !13, i64 24, !13, i64 26, !13, i64 28, !13, i64 30}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 30}
!15 = !{!12, !13, i64 24}
!16 = !{!7, !7, i64 0}


; 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 void @arm_2d_helper_film_set_frame(ptr nocapture noundef nonnull %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 26
  %4 = load i16, ptr %3, align 2, !tbaa !5
  %5 = zext i16 %4 to i32
  %6 = srem i32 %1, %5
  %7 = icmp slt i32 %6, 0
  %8 = select i1 %7, i32 %5, i32 0
  %.0 = add nsw i32 %8, %6
  %9 = trunc i32 %.0 to i16
  %10 = getelementptr inbounds i8, ptr %0, i64 30
  store i16 %9, ptr %10, align 2, !tbaa !10
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load i16, ptr %11, align 8, !tbaa !11
  %13 = zext i16 %12 to i32
  %14 = srem i32 %.0, %13
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = sdiv i32 %.0, %13
  %18 = load <2 x i16>, ptr %16, align 4, !tbaa !12
  %19 = insertelement <2 x i32> poison, i32 %14, i64 0
  %20 = insertelement <2 x i32> %19, i32 %17, i64 1
  %21 = trunc <2 x i32> %20 to <2 x i16>
  %22 = mul <2 x i16> %18, %21
  store <2 x i16> %22, ptr %15, align 4, !tbaa !12
  ret void
}

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, !9, i64 26}
!6 = !{!"arm_2d_helper_film_t", !7, i64 0, !9, i64 24, !9, i64 26, !9, i64 28, !9, i64 30}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!6, !9, i64 30}
!11 = !{!6, !9, i64 24}
!12 = !{!7, !7, i64 0}


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