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

; 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_layout_t = type { ptr, %struct.arm_2d_region_t, %struct.arm_2d_region_t, i8, i8, %struct.__arm_2d_layout_align_tab_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 }
%struct.__arm_2d_layout_align_tab_t = type { %union.anon.24, %union.anon.26 }
%union.anon.24 = type { %struct.anon.25 }
%struct.anon.25 = type { i8 }
%union.anon.26 = type { %struct.anon.27 }
%struct.anon.27 = type { i8 }

@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [17 x i8], align 1
@__PRETTY_FUNCTION__.__arm_2d_layout_wrap_horizontal = external hidden unnamed_addr constant [67 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 void @__arm_2d_layout_wrap_horizontal(i16 noundef signext %0, ptr noundef nonnull %1) #1 {
  %3 = alloca i16, align 2
  %4 = alloca ptr, align 8
  store i16 %0, ptr %3, align 2, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %5 = load ptr, ptr %4, align 8, !tbaa !9
  %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.12, ptr noundef @.str.1, i32 noundef 1125, ptr noundef @__PRETTY_FUNCTION__.__arm_2d_layout_wrap_horizontal) #2
  unreachable

9:                                                ; preds = %7
  %10 = load ptr, ptr %4, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %10, i32 0, i32 5
  %12 = getelementptr inbounds %struct.__arm_2d_layout_align_tab_t, ptr %11, i32 0, i32 0
  %13 = load i8, ptr %12, align 2
  %14 = ashr i8 %13, 6
  %15 = sext i8 %14 to i32
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %17, label %36

17:                                               ; preds = %9
  %18 = load i16, ptr %3, align 2, !tbaa !5
  %19 = sext i16 %18 to i32
  %20 = load ptr, ptr %4, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %20, i32 0, i32 2
  %22 = getelementptr inbounds %struct.arm_2d_region_t, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds %struct.arm_2d_location_t, ptr %22, i32 0, i32 0
  %24 = load i16, ptr %23, align 8, !tbaa !11
  %25 = sext i16 %24 to i32
  %26 = load ptr, ptr %4, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %26, i32 0, i32 2
  %28 = getelementptr inbounds %struct.arm_2d_region_t, ptr %27, i32 0, i32 1
  %29 = getelementptr inbounds %struct.arm_2d_size_t, ptr %28, i32 0, i32 0
  %30 = load i16, ptr %29, align 4, !tbaa !11
  %31 = sext i16 %30 to i32
  %32 = add nsw i32 %25, %31
  %33 = icmp sge i32 %19, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %17
  br label %100

35:                                               ; preds = %17
  br label %48

36:                                               ; preds = %9
  %37 = load i16, ptr %3, align 2, !tbaa !5
  %38 = sext i16 %37 to i32
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %39, i32 0, i32 2
  %41 = getelementptr inbounds %struct.arm_2d_region_t, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds %struct.arm_2d_location_t, ptr %41, i32 0, i32 0
  %43 = load i16, ptr %42, align 8, !tbaa !11
  %44 = sext i16 %43 to i32
  %45 = icmp sle i32 %38, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %36
  br label %100

47:                                               ; preds = %36
  br label %48

48:                                               ; preds = %47, %35
  %49 = load ptr, ptr %4, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %49, i32 0, i32 1
  %51 = getelementptr inbounds %struct.arm_2d_region_t, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds %struct.arm_2d_size_t, ptr %51, i32 0, i32 1
  %53 = load i16, ptr %52, align 2, !tbaa !11
  %54 = sext i16 %53 to i32
  %55 = load ptr, ptr %4, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %55, i32 0, i32 5
  %57 = getelementptr inbounds %struct.__arm_2d_layout_align_tab_t, ptr %56, i32 0, i32 1
  %58 = load i8, ptr %57, align 1
  %59 = ashr i8 %58, 6
  %60 = sext i8 %59 to i32
  %61 = mul nsw i32 %54, %60
  %62 = load ptr, ptr %4, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %62, i32 0, i32 1
  %64 = getelementptr inbounds %struct.arm_2d_region_t, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds %struct.arm_2d_location_t, ptr %64, i32 0, i32 1
  %66 = load i16, ptr %65, align 2, !tbaa !11
  %67 = sext i16 %66 to i32
  %68 = add nsw i32 %67, %61
  %69 = trunc i32 %68 to i16
  store i16 %69, ptr %65, align 2, !tbaa !11
  %70 = load ptr, ptr %4, align 8, !tbaa !9
  %71 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %70, i32 0, i32 1
  %72 = getelementptr inbounds %struct.arm_2d_region_t, ptr %71, i32 0, i32 1
  %73 = getelementptr inbounds %struct.arm_2d_size_t, ptr %72, i32 0, i32 1
  store i16 0, ptr %73, align 2, !tbaa !11
  %74 = load ptr, ptr %4, align 8, !tbaa !9
  %75 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %74, i32 0, i32 2
  %76 = getelementptr inbounds %struct.arm_2d_region_t, ptr %75, i32 0, i32 0
  %77 = getelementptr inbounds %struct.arm_2d_location_t, ptr %76, i32 0, i32 0
  %78 = load i16, ptr %77, align 8, !tbaa !11
  %79 = sext i16 %78 to i32
  %80 = load ptr, ptr %4, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %80, i32 0, i32 2
  %82 = getelementptr inbounds %struct.arm_2d_region_t, ptr %81, i32 0, i32 1
  %83 = getelementptr inbounds %struct.arm_2d_size_t, ptr %82, i32 0, i32 0
  %84 = load i16, ptr %83, align 4, !tbaa !11
  %85 = sext i16 %84 to i32
  %86 = load ptr, ptr %4, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %86, i32 0, i32 5
  %88 = getelementptr inbounds %struct.__arm_2d_layout_align_tab_t, ptr %87, i32 0, i32 0
  %89 = load i8, ptr %88, align 2
  %90 = shl i8 %89, 6
  %91 = ashr i8 %90, 6
  %92 = sext i8 %91 to i32
  %93 = mul nsw i32 %85, %92
  %94 = sub nsw i32 %79, %93
  %95 = trunc i32 %94 to i16
  %96 = load ptr, ptr %4, align 8, !tbaa !9
  %97 = getelementptr inbounds %struct.__arm_2d_layout_t, ptr %96, i32 0, i32 1
  %98 = getelementptr inbounds %struct.arm_2d_region_t, ptr %97, i32 0, i32 0
  %99 = getelementptr inbounds %struct.arm_2d_location_t, ptr %98, i32 0, i32 0
  store i16 %95, ptr %99, align 8, !tbaa !11
  br label %100

100:                                              ; preds = %48, %46, %34
  ret void
}

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 = { 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!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_layout_wrap_horizontal(i16 noundef signext %0, ptr nocapture noundef nonnull %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 26
  %4 = load i8, ptr %3, align 2
  %5 = icmp sgt i8 %4, 63
  br i1 %5, label %6, label %15

6:                                                ; preds = %2
  %7 = sext i16 %0 to i32
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load i16, ptr %8, align 8, !tbaa !5
  %10 = sext i16 %9 to i32
  %11 = getelementptr inbounds i8, ptr %1, i64 20
  %12 = load i16, ptr %11, align 4, !tbaa !5
  %13 = sext i16 %12 to i32
  %14 = add nsw i32 %13, %10
  %.not14 = icmp sgt i32 %14, %7
  br i1 %.not14, label %37, label %18

15:                                               ; preds = %2
  %16 = getelementptr inbounds i8, ptr %1, i64 16
  %17 = load i16, ptr %16, align 8, !tbaa !5
  %.not = icmp slt i16 %17, %0
  br i1 %.not, label %37, label %._crit_edge

._crit_edge:                                      ; preds = %15
  %.phi.trans.insert = getelementptr inbounds i8, ptr %1, i64 20
  %.pre = load i16, ptr %.phi.trans.insert, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %._crit_edge, %6
  %19 = phi i16 [ %.pre, %._crit_edge ], [ %12, %6 ]
  %20 = phi i16 [ %17, %._crit_edge ], [ %9, %6 ]
  %21 = getelementptr inbounds i8, ptr %1, i64 8
  %22 = getelementptr inbounds i8, ptr %1, i64 14
  %23 = load i16, ptr %22, align 2, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %1, i64 27
  %25 = load i8, ptr %24, align 1
  %26 = ashr i8 %25, 6
  %27 = sext i8 %26 to i16
  %28 = mul i16 %23, %27
  %29 = getelementptr inbounds i8, ptr %1, i64 10
  %30 = load i16, ptr %29, align 2, !tbaa !5
  %31 = add i16 %28, %30
  store i16 %31, ptr %29, align 2, !tbaa !5
  store i16 0, ptr %22, align 2, !tbaa !5
  %32 = shl i8 %4, 6
  %33 = ashr exact i8 %32, 6
  %34 = sext i8 %33 to i16
  %35 = mul i16 %19, %34
  %36 = sub i16 %20, %35
  store i16 %36, ptr %21, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %15, %6, %18
  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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass