; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseTexture.ll (ZN4Simd4Base16TextureBoostedUvEPKhmmmhPhm)

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

@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base16TextureBoostedUvEPKhmmmhPhm = external hidden unnamed_addr constant [103 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base16TextureBoostedUvEPKhmmmhPhm(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i8 noundef zeroext %4, ptr noundef %5, i64 noundef %6) #2 {
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i8, align 1
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i64 %1, ptr %9, align 8, !tbaa !9
  store i64 %2, ptr %10, align 8, !tbaa !9
  store i64 %3, ptr %11, align 8, !tbaa !9
  store i8 %4, ptr %12, align 1, !tbaa !11
  store ptr %5, ptr %13, align 8, !tbaa !5
  store i64 %6, ptr %14, align 8, !tbaa !9
  %20 = load i8, ptr %12, align 1, !tbaa !11
  %21 = zext i8 %20 to i32
  %22 = icmp slt i32 %21, 128
  br i1 %22, label %23, label %24

23:                                               ; preds = %7
  br label %26

24:                                               ; preds = %7
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 68, ptr noundef @__PRETTY_FUNCTION__._ZN4Simd4Base16TextureBoostedUvEPKhmmmhPhm) #4
  unreachable

25:                                               ; No predecessors!
  br label %26

26:                                               ; preds = %25, %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %27 = load i8, ptr %12, align 1, !tbaa !11
  %28 = zext i8 %27 to i32
  %29 = sdiv i32 128, %28
  %30 = sub nsw i32 128, %29
  store i32 %30, ptr %15, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  %31 = load i32, ptr %15, align 4, !tbaa !12
  %32 = sub nsw i32 255, %31
  store i32 %32, ptr %16, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %72, %26
  %34 = load i64, ptr %17, align 8, !tbaa !9
  %35 = load i64, ptr %11, align 8, !tbaa !9
  %36 = icmp ult i64 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 2, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  br label %75

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  store i64 0, ptr %19, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %62, %38
  %40 = load i64, ptr %19, align 8, !tbaa !9
  %41 = load i64, ptr %10, align 8, !tbaa !9
  %42 = icmp ult i64 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  store i32 5, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  br label %65

44:                                               ; preds = %39
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load i64, ptr %19, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = zext i8 %48 to i32
  %50 = load i32, ptr %15, align 4, !tbaa !12
  %51 = load i32, ptr %16, align 4, !tbaa !12
  %52 = call noundef i32 @_ZN4Simd4Base13RestrictRangeEiii(i32 noundef %49, i32 noundef %50, i32 noundef %51)
  %53 = load i32, ptr %15, align 4, !tbaa !12
  %54 = sub nsw i32 %52, %53
  %55 = load i8, ptr %12, align 1, !tbaa !11
  %56 = zext i8 %55 to i32
  %57 = mul nsw i32 %54, %56
  %58 = trunc i32 %57 to i8
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = load i64, ptr %19, align 8, !tbaa !9
  %61 = getelementptr inbounds i8, ptr %59, i64 %60
  store i8 %58, ptr %61, align 1, !tbaa !11
  br label %62

62:                                               ; preds = %44
  %63 = load i64, ptr %19, align 8, !tbaa !9
  %64 = add i64 %63, 1
  store i64 %64, ptr %19, align 8, !tbaa !9
  br label %39, !llvm.loop !14

65:                                               ; preds = %43
  %66 = load i64, ptr %9, align 8, !tbaa !9
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i64 %66
  store ptr %68, ptr %8, align 8, !tbaa !5
  %69 = load i64, ptr %14, align 8, !tbaa !9
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 %69
  store ptr %71, ptr %13, align 8, !tbaa !5
  br label %72

72:                                               ; preds = %65
  %73 = load i64, ptr %17, align 8, !tbaa !9
  %74 = add i64 %73, 1
  store i64 %74, ptr %17, align 8, !tbaa !9
  br label %33, !llvm.loop !16

75:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  ret void
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base13RestrictRangeEiii(i32 noundef, i32 noundef, i32 noundef) #3

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 = { alwaysinline mustprogress 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 #4 = { noreturn nounwind }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

@.str.1 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [12 x i8], align 1
@__PRETTY_FUNCTION__._ZN4Simd4Base16TextureBoostedUvEPKhmmmhPhm = external hidden unnamed_addr constant [103 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base16TextureBoostedUvEPKhmmmhPhm(ptr nocapture noundef readonly %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i8 noundef zeroext %4, ptr nocapture noundef writeonly %5, i64 noundef %6) local_unnamed_addr #1 {
  %8 = icmp sgt i8 %4, -1
  br i1 %8, label %10, label %9

9:                                                ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 68, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4Simd4Base16TextureBoostedUvEPKhmmmhPhm) #3
  unreachable

10:                                               ; preds = %7
  %11 = udiv i8 -128, %4
  %12 = zext i8 %11 to i32
  %13 = sub nuw nsw i32 128, %12
  %14 = add nuw nsw i32 %12, 127
  %.not = icmp eq i64 %3, 0
  %.not29 = icmp eq i64 %2, 0
  %or.cond = or i1 %.not, %.not29
  br i1 %or.cond, label %._crit_edge28, label %.preheader.us

.preheader.us:                                    ; preds = %10, %._crit_edge.us
  %.02027.us = phi i64 [ %27, %._crit_edge.us ], [ 0, %10 ]
  %.02126.us = phi ptr [ %25, %._crit_edge.us ], [ %0, %10 ]
  %.02225.us = phi ptr [ %26, %._crit_edge.us ], [ %5, %10 ]
  br label %15

15:                                               ; preds = %.preheader.us, %15
  %.024.us = phi i64 [ 0, %.preheader.us ], [ %24, %15 ]
  %16 = getelementptr inbounds i8, ptr %.02126.us, i64 %.024.us
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %18 = zext i8 %17 to i32
  %19 = tail call noundef i32 @_ZN4Simd4Base13RestrictRangeEiii(i32 noundef %18, i32 noundef %13, i32 noundef %14)
  %20 = sub nsw i32 %19, %13
  %21 = trunc i32 %20 to i8
  %22 = mul i8 %21, %4
  %23 = getelementptr inbounds i8, ptr %.02225.us, i64 %.024.us
  store i8 %22, ptr %23, align 1, !tbaa !5
  %24 = add nuw i64 %.024.us, 1
  %exitcond.not = icmp eq i64 %24, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %15, !llvm.loop !8

._crit_edge.us:                                   ; preds = %15
  %25 = getelementptr inbounds i8, ptr %.02126.us, i64 %1
  %26 = getelementptr inbounds i8, ptr %.02225.us, i64 %6
  %27 = add nuw i64 %.02027.us, 1
  %exitcond31.not = icmp eq i64 %27, %3
  br i1 %exitcond31.not, label %._crit_edge28, label %.preheader.us, !llvm.loop !10

._crit_edge28:                                    ; preds = %._crit_edge.us, %10
  ret void
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef i32 @_ZN4Simd4Base13RestrictRangeEiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #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 = { mustprogress 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 = { alwaysinline mustprogress 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 }

!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++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass